From 110e3df0b75d78d7cd16d1ac01314f4480963984 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 12 Aug 2022 02:18:46 +0300 Subject: [PATCH] Set default config in the constant module. Use from there to configure app - Avoid having to pass the khoj_sample.yml data file into pip, native apps - Packaging data files into python packages is annoying. - There's `MANIFEST.in`, `data_files` and `package_data` in setup.py - Bdist, wheel, generated source tarball use different set of these fields and put the data files in different locations - Rather just code the default config into a constant. Avoid pointless file reads as well this way --- MANIFEST.in | 1 - src/interface/desktop/configure_screen.py | 4 +- src/utils/constants.py | 59 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 30a81879..595ab4e1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include Readme.md -include config/khoj_sample.yml graft src/interface/* prune src/interface/web/images* prune docs* diff --git a/src/interface/desktop/configure_screen.py b/src/interface/desktop/configure_screen.py index a6cc84f2..ff7b86b3 100644 --- a/src/interface/desktop/configure_screen.py +++ b/src/interface/desktop/configure_screen.py @@ -30,7 +30,7 @@ class ConfigureScreen(QtWidgets.QDialog): if resolve_absolute_path(self.config_file).exists(): self.current_config = yaml_utils.load_config_from_file(self.config_file) else: - self.current_config = yaml_utils.load_config_from_file(constants.app_root_directory / 'config/khoj_sample.yml') + self.current_config = constants.default_config self.new_config = self.current_config # Initialize Configure Window @@ -127,7 +127,7 @@ class ConfigureScreen(QtWidgets.QDialog): def get_default_config(self, search_type:SearchType=None, processor_type:ProcessorType=None): "Get default config" - config = yaml_utils.load_config_from_file(constants.app_root_directory / 'config/khoj_sample.yml') + config = constants.default_config if search_type: return config['content-type'][search_type] elif processor_type: diff --git a/src/utils/constants.py b/src/utils/constants.py index 8e45d03c..569c5bcb 100644 --- a/src/utils/constants.py +++ b/src/utils/constants.py @@ -3,3 +3,62 @@ from pathlib import Path app_root_directory = Path(__file__).parent.parent.parent web_directory = app_root_directory / 'src/interface/web/' empty_escape_sequences = r'\n|\r\t ' + +# default app config to use +default_config = { + 'content-type': { + 'org': { + 'input-files': None, + 'input-filter': None, + 'compressed-jsonl': '~/.khoj/content/org/org.jsonl.gz', + 'embeddings-file': '~/.khoj/content/org/org_embeddings.pt' + }, + 'markdown': { + 'input-files': None, + 'input-filter': None, + 'compressed-jsonl': '~/.khoj/content/markdown/markdown.jsonl.gz', + 'embeddings-file': '~/.khoj/content/markdown/markdown_embeddings.pt' + }, + 'ledger': { + 'input-files': None, + 'input-filter': None, + 'compressed-jsonl': '~/.khoj/content/ledger/ledger.jsonl.gz', + 'embeddings-file': '~/.khoj/content/ledger/ledger_embeddings.pt' + }, + 'image': { + 'input-directories': None, + 'input-filter': None, + 'embeddings-file': '~/.khoj/content/image/image_embeddings.pt', + 'batch-size': 50, + 'use-xmp-metadata': True + }, + 'music': { + 'input-files': None, + 'input-filter': None, + 'compressed-jsonl': '~/.khoj/content/music/music.jsonl.gz', + 'embeddings-file': '~/.khoj/content/music/music_embeddings.pt' + } + }, + 'search-type': { + 'symmetric': { + 'encoder': 'sentence-transformers/all-MiniLM-L6-v2', + 'cross-encoder': 'cross-encoder/ms-marco-MiniLM-L-6-v2', + 'model_directory': '~/.khoj/search/symmetric/' + }, + 'asymmetric': { + 'encoder': 'sentence-transformers/multi-qa-MiniLM-L6-cos-v1', + 'cross-encoder': 'cross-encoder/ms-marco-MiniLM-L-6-v2', + 'model_directory': '~/.khoj/search/asymmetric/' + }, + 'image': { + 'encoder': 'sentence-transformers/clip-ViT-B-32', + 'model_directory': '~/.khoj/search/image/' + } + }, + 'processor': { + 'conversation': { + 'openai-api-key': None, + 'conversation-logfile': '~/.khoj/processor/conversation/conversation_logs.json' + } + } +} \ No newline at end of file