2021-11-28 17:57:13 +01:00
|
|
|
# System Packages
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
# External Packages
|
2022-08-04 22:26:31 +02:00
|
|
|
from pydantic import BaseModel, validator
|
2021-11-28 17:57:13 +01:00
|
|
|
|
|
|
|
# Internal Packages
|
|
|
|
from src.utils.helpers import to_snake_case_from_dash
|
|
|
|
|
2021-12-09 14:50:38 +01:00
|
|
|
class ConfigBase(BaseModel):
|
2021-11-28 17:57:13 +01:00
|
|
|
class Config:
|
|
|
|
alias_generator = to_snake_case_from_dash
|
|
|
|
allow_population_by_field_name = True
|
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
class TextContentConfig(ConfigBase):
|
2022-08-04 22:26:31 +02:00
|
|
|
input_files: Optional[List[Path]]
|
2021-11-28 17:57:13 +01:00
|
|
|
input_filter: Optional[str]
|
2022-08-04 22:26:31 +02:00
|
|
|
compressed_jsonl: Path
|
|
|
|
embeddings_file: Path
|
|
|
|
|
|
|
|
@validator('input_filter')
|
|
|
|
def input_filter_or_files_required(cls, input_filter, values, **kwargs):
|
|
|
|
if input_filter is None and ('input_files' not in values or values["input_files"] is None):
|
|
|
|
raise ValueError("Either input_filter or input_files required in all content-type.<text_search> section of Khoj config file")
|
|
|
|
return input_filter
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
class ImageContentConfig(ConfigBase):
|
2022-07-20 00:54:03 +02:00
|
|
|
input_directories: Optional[List[Path]]
|
2021-11-28 17:57:13 +01:00
|
|
|
input_filter: Optional[str]
|
2022-08-04 22:26:31 +02:00
|
|
|
embeddings_file: Path
|
|
|
|
use_xmp_metadata: bool
|
|
|
|
batch_size: int
|
|
|
|
|
|
|
|
@validator('input_filter')
|
|
|
|
def input_filter_or_directories_required(cls, input_filter, values, **kwargs):
|
|
|
|
if input_filter is None and ('input_directories' not in values or values["input_directories"] is None):
|
|
|
|
raise ValueError("Either input_filter or input_directories required in all content-type.image section of Khoj config file")
|
|
|
|
return input_filter
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
class ContentConfig(ConfigBase):
|
|
|
|
org: Optional[TextContentConfig]
|
|
|
|
ledger: Optional[TextContentConfig]
|
|
|
|
image: Optional[ImageContentConfig]
|
|
|
|
music: Optional[TextContentConfig]
|
2022-07-21 18:22:24 +02:00
|
|
|
markdown: Optional[TextContentConfig]
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2022-07-21 16:05:43 +02:00
|
|
|
class TextSearchConfig(ConfigBase):
|
2022-08-04 22:26:31 +02:00
|
|
|
encoder: str
|
|
|
|
cross_encoder: str
|
2022-01-14 22:31:55 +01:00
|
|
|
model_directory: Optional[Path]
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
class ImageSearchConfig(ConfigBase):
|
2022-08-04 22:26:31 +02:00
|
|
|
encoder: str
|
2022-01-14 23:09:18 +01:00
|
|
|
model_directory: Optional[Path]
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
class SearchConfig(ConfigBase):
|
2022-07-21 16:05:43 +02:00
|
|
|
asymmetric: Optional[TextSearchConfig]
|
|
|
|
symmetric: Optional[TextSearchConfig]
|
2022-01-15 02:54:38 +01:00
|
|
|
image: Optional[ImageSearchConfig]
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2021-12-09 14:50:38 +01:00
|
|
|
class ConversationProcessorConfig(ConfigBase):
|
2022-08-04 22:26:31 +02:00
|
|
|
openai_api_key: str
|
|
|
|
conversation_logfile: Path
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
class ProcessorConfig(ConfigBase):
|
2021-12-09 14:50:38 +01:00
|
|
|
conversation: Optional[ConversationProcessorConfig]
|
2021-11-28 17:57:13 +01:00
|
|
|
|
2021-12-09 14:50:38 +01:00
|
|
|
class FullConfig(ConfigBase):
|
2022-01-15 02:54:38 +01:00
|
|
|
content_type: Optional[ContentConfig]
|
|
|
|
search_type: Optional[SearchConfig]
|
|
|
|
processor: Optional[ProcessorConfig]
|