From 71ebf31a545d237e1c43b956007eb277238cd4e9 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 17 Jul 2024 12:41:01 +0530 Subject: [PATCH] Make config API detailed response fields more intuitive, consistent - Use name, id for every [search|chat|voice|pain]_model_option - Rename current_model_state field to more intuitive enabled_content_source - Update references to the update fields in config.html --- src/khoj/interface/web/config.html | 24 ++++++++++++------------ src/khoj/routers/helpers.py | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/khoj/interface/web/config.html b/src/khoj/interface/web/config.html index 58e62a10..6049a029 100644 --- a/src/khoj/interface/web/config.html +++ b/src/khoj/interface/web/config.html @@ -34,7 +34,7 @@

Files Configured @@ -45,7 +45,7 @@
- {% if current_model_state.computer %} + {% if enabled_content_source.computer %} Update {% else %} Setup @@ -53,7 +53,7 @@
+ style="display: {% if not enabled_content_source.computer %}none{% endif %}"> @@ -69,7 +69,7 @@ class="configured-icon" src="/static/assets/icons/confirm-icon.svg" alt="Configured" - style="display: {% if not current_model_state.github %}none{% endif %}"> + style="display: {% if not enabled_content_source.github %}none{% endif %}">

@@ -77,7 +77,7 @@
- {% if current_model_state.github %} + {% if enabled_content_source.github %} Update {% else %} Setup @@ -86,7 +86,7 @@
+ style="display: {% if not enabled_content_source.github %}none{% endif %}"> @@ -102,14 +102,14 @@ class="configured-icon" src="/static/assets/icons/confirm-icon.svg" alt="Configured" - style="display: {% if not current_model_state.notion %}none{% endif %}"> + style="display: {% if not enabled_content_source.notion %}none{% endif %}">

Sync your Notion pages

- {% if current_model_state.notion %} + {% if enabled_content_source.notion %} Update @@ -128,7 +128,7 @@
+ style="display: {% if not enabled_content_source.notion %}none{% endif %}"> @@ -181,8 +181,8 @@
@@ -208,7 +208,7 @@
diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index 59a5ce49..0df618df 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1230,18 +1230,18 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False) ) given_name = get_user_name(user) - enabled_content_source = set(EntryAdapters.get_unique_file_sources(user)) - successfully_configured = { - "computer": ("computer" in enabled_content_source), - "github": ("github" in enabled_content_source), - "notion": ("notion" in enabled_content_source), + enabled_content_sources_set = set(EntryAdapters.get_unique_file_sources(user)) + enabled_content_sources = { + "computer": ("computer" in enabled_content_sources_set), + "github": ("github" in enabled_content_sources_set), + "notion": ("notion" in enabled_content_sources_set), } - selected_conversation_config = ConversationAdapters.get_conversation_config(user) - conversation_options = ConversationAdapters.get_conversation_processor_options().all() - all_conversation_options = list() - for conversation_option in conversation_options: - all_conversation_options.append({"chat_model": conversation_option.chat_model, "id": conversation_option.id}) + selected_chat_model_config = ConversationAdapters.get_conversation_config(user) + chat_models = ConversationAdapters.get_conversation_processor_options().all() + chat_model_options = list() + for chat_model in chat_models: + chat_model_options.append({"name": chat_model.chat_model, "id": chat_model.id}) search_model_options = adapters.get_or_create_search_models().all() all_search_model_options = list() @@ -1254,7 +1254,7 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False) paint_model_options = ConversationAdapters.get_text_to_image_model_options().all() all_paint_model_options = list() for paint_model in paint_model_options: - all_paint_model_options.append({"model_name": paint_model.model_name, "id": paint_model.id}) + all_paint_model_options.append({"name": paint_model.model_name, "id": paint_model.id}) notion_oauth_url = get_notion_auth_url(user) @@ -1277,13 +1277,13 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False) "is_active": is_active, "has_documents": has_documents, "khoj_version": state.khoj_version, - "current_model_state": successfully_configured, + "enabled_content_source": enabled_content_sources, "anonymous_mode": state.anonymous_mode, "given_name": given_name, "search_model_options": all_search_model_options, "selected_search_model_config": current_search_model_option.id, - "conversation_options": all_conversation_options, - "selected_conversation_config": selected_conversation_config.id if selected_conversation_config else None, + "chat_model_options": chat_model_options, + "selected_chat_model_config": selected_chat_model_config.id if selected_chat_model_config else None, "paint_model_options": all_paint_model_options, "selected_paint_model_config": selected_paint_model_config.id if selected_paint_model_config else None, "user_photo": user_picture,