From ac96f43b1bb04455f2b40b2a242b02618a51df66 Mon Sep 17 00:00:00 2001 From: Saba Date: Fri, 16 Jun 2023 23:46:25 -0700 Subject: [PATCH] Remove try-catch specific to Github plugin; consolidate GUI logic --- src/khoj/configure.py | 18 ++++++-------- src/khoj/interface/desktop/main_window.py | 30 ++++++++--------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/khoj/configure.py b/src/khoj/configure.py index 6bb844cc..38a29efb 100644 --- a/src/khoj/configure.py +++ b/src/khoj/configure.py @@ -49,7 +49,6 @@ def configure_server(args, required=False): # Initialize the search type and model from Config state.search_index_lock.acquire() state.SearchType = configure_search_types(state.config) - state.model = SearchModels() state.model = configure_search(state.model, state.config, args.regenerate) state.search_index_lock.release() @@ -158,16 +157,13 @@ def configure_search(model: SearchModels, config: FullConfig, regenerate: bool, if (t == state.SearchType.Github or t == None) and config.content_type.github: logger.info("🐙 Setting up search for github") # Extract Entries, Generate Github Embeddings - try: - model.github_search = text_search.setup( - GithubToJsonl, - config.content_type.github, - search_config=config.search_type.asymmetric, - regenerate=regenerate, - filters=[DateFilter(), WordFilter(), FileFilter()], - ) - except Exception as e: - logger.error(f"Failed to setup github search: {e}") + model.github_search = text_search.setup( + GithubToJsonl, + config.content_type.github, + search_config=config.search_type.asymmetric, + regenerate=regenerate, + filters=[DateFilter(), WordFilter(), FileFilter()], + ) # Initialize External Plugin Search if (t == None or t in state.SearchType) and config.content_type.plugins: diff --git a/src/khoj/interface/desktop/main_window.py b/src/khoj/interface/desktop/main_window.py index 5a3df3ec..24239772 100644 --- a/src/khoj/interface/desktop/main_window.py +++ b/src/khoj/interface/desktop/main_window.py @@ -119,28 +119,18 @@ class MainWindow(QtWidgets.QMainWindow): # Add labelled text input field input_fields = [] - pat_token = current_content_config.get("pat-token", None) - input_field = LabelledTextField("pat-token", search_type=search_type, default_value=pat_token) - search_type_layout.addWidget(input_field) - input_fields += [input_field] - - repo_name = current_content_config.get("repo-name", None) - input_field = LabelledTextField("repo-name", search_type=search_type, default_value=repo_name) - search_type_layout.addWidget(input_field) - input_fields += [input_field] - - repo_owner = current_content_config.get("repo-owner", None) - input_field = LabelledTextField("repo-owner", search_type=search_type, default_value=repo_owner) - search_type_layout.addWidget(input_field) - input_fields += [input_field] - - repo_branch = current_content_config.get("repo-branch", None) - input_field = LabelledTextField("repo-branch", search_type=search_type, default_value=repo_branch) - search_type_layout.addWidget(input_field) - input_fields += [input_field] + fields = ["pat-token", "repo-name", "repo-owner", "repo-branch"] + active = False + for field in fields: + field_value = current_content_config.get(field, None) + input_field = LabelledTextField(field, search_type=search_type, default_value=field_value) + search_type_layout.addWidget(input_field) + input_fields += [input_field] + if field_value: + active = True # Set enabled/disabled based on checkbox state - enable_search_type.setChecked(bool(repo_name or repo_owner or repo_branch or pat_token)) + enable_search_type.setChecked(active) for input_field in input_fields: input_field.setEnabled(enable_search_type.isChecked()) enable_search_type.stateChanged.connect(lambda _: [input_field.setEnabled(enable_search_type.isChecked()) for input_field in input_fields]) # type: ignore[attr-defined]