Remove unused imports. Fix typing and indentation

- Typing issues discovered using `mypy'. Fixed manually
- Unused imports discovered and fixed using `autoflake'
- Fix indentation in `org_to_jsonl' manually
This commit is contained in:
Debanjum Singh Solanky
2022-09-14 02:58:49 +03:00
parent be57c711fd
commit 8f57a62675
14 changed files with 34 additions and 42 deletions

View File

@@ -2,7 +2,6 @@
from enum import Enum
from dataclasses import dataclass
from pathlib import Path
from typing import List
# Internal Packages
from src.utils.rawconfig import ConversationProcessorConfig
@@ -22,7 +21,7 @@ class ProcessorType(str, Enum):
class TextSearchModel():
def __init__(self, entries, corpus_embeddings, bi_encoder, cross_encoder, filters: List[BaseFilter], top_k):
def __init__(self, entries, corpus_embeddings, bi_encoder, cross_encoder, filters: list[BaseFilter], top_k):
self.entries = entries
self.corpus_embeddings = corpus_embeddings
self.bi_encoder = bi_encoder
@@ -54,7 +53,7 @@ class ConversationProcessorConfigModel():
self.openai_api_key = processor_config.openai_api_key
self.conversation_logfile = Path(processor_config.conversation_logfile)
self.chat_session = ''
self.meta_log = []
self.meta_log: dict = {}
@dataclass

View File

@@ -1,10 +1,11 @@
# Standard Packages
import pathlib
from pathlib import Path
import sys
import time
import hashlib
from os.path import join
from collections import OrderedDict
from typing import Optional, Union
def is_none_or_empty(item):
@@ -15,12 +16,12 @@ def to_snake_case_from_dash(item: str):
return item.replace('_', '-')
def get_absolute_path(filepath):
return str(pathlib.Path(filepath).expanduser().absolute())
def get_absolute_path(filepath: Union[str, Path]) -> str:
return str(Path(filepath).expanduser().absolute())
def resolve_absolute_path(filepath, strict=False):
return pathlib.Path(filepath).expanduser().absolute().resolve(strict=strict)
def resolve_absolute_path(filepath: Union[str, Optional[Path]], strict=False) -> Path:
return Path(filepath).expanduser().absolute().resolve(strict=strict)
def get_from_dict(dictionary, *args):

View File

@@ -1,5 +1,6 @@
# Standard Packages
from packaging import version
# External Packages
import torch
from pathlib import Path
@@ -13,11 +14,11 @@ from src.utils.rawconfig import FullConfig
config = FullConfig()
model = SearchModels()
processor_config = ProcessorConfigModel()
config_file: Path = ""
config_file: Path = None
verbose: int = 0
host: str = None
port: int = None
cli_args = None
cli_args: list[str] = None
query_cache = LRU()
if torch.cuda.is_available():

View File

@@ -5,12 +5,13 @@ from pathlib import Path
import yaml
# Internal Packages
from src.utils.helpers import get_absolute_path, resolve_absolute_path
from src.utils.rawconfig import FullConfig
# Do not emit tags when dumping to YAML
yaml.emitter.Emitter.process_tag = lambda self, *args, **kwargs: None
def save_config_to_file(yaml_config: dict, yaml_config_file: Path):
"Write config to YML file"
# Create output directory, if it doesn't exist