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
This commit is contained in:
Debanjum Singh Solanky 2024-07-17 12:41:01 +05:30
parent 7316e6b9d3
commit 71ebf31a54
2 changed files with 26 additions and 26 deletions

View file

@ -34,7 +34,7 @@
<h3 id="card-title-computer" class="card-title">
<span>Files</span>
<img id="configured-icon-computer"
style="display: {% if not current_model_state.computer %}none{% endif %}"
style="display: {% if not enabled_content_source.computer %}none{% endif %}"
class="configured-icon"
src="/static/assets/icons/confirm-icon.svg"
alt="Configured">
@ -45,7 +45,7 @@
</div>
<div class="card-action-row">
<a class="card-button" href="/configure/content/computer">
{% if current_model_state.computer %}
{% if enabled_content_source.computer %}
Update
{% else %}
Setup
@ -53,7 +53,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg>
</a>
<div id="clear-computer" class="card-action-row"
style="display: {% if not current_model_state.computer %}none{% endif %}">
style="display: {% if not enabled_content_source.computer %}none{% endif %}">
<button class="card-button" onclick="clearContentType('computer')">
Disable
</button>
@ -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 %}">
</h3>
</div>
<div class="card-description-row">
@ -77,7 +77,7 @@
</div>
<div class="card-action-row">
<a class="card-button" href="/configure/content/github">
{% if current_model_state.github %}
{% if enabled_content_source.github %}
Update
{% else %}
Setup
@ -86,7 +86,7 @@
</a>
<div id="clear-github"
class="card-action-row"
style="display: {% if not current_model_state.github %}none{% endif %}">
style="display: {% if not enabled_content_source.github %}none{% endif %}">
<button class="card-button" onclick="clearContentType('github')">
Disable
</button>
@ -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 %}">
</h3>
</div>
<div class="card-description-row">
<p class="card-description">Sync your Notion pages</p>
</div>
<div class="card-action-row">
{% if current_model_state.notion %}
{% if enabled_content_source.notion %}
<a class="card-button" href="/configure/content/notion">
Update
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg>
@ -128,7 +128,7 @@
<div id="clear-notion"
class="card-action-row"
style="display: {% if not current_model_state.notion %}none{% endif %}">
style="display: {% if not enabled_content_source.notion %}none{% endif %}">
<button class="card-button" onclick="clearContentType('notion')">
Disable
</button>
@ -181,8 +181,8 @@
</div>
<div class="card-description-row">
<select id="chat-models">
{% for option in conversation_options %}
<option value="{{ option.id }}" {% if option.id == selected_conversation_config %}selected{% endif %}>{{ option.chat_model }}</option>
{% for option in chat_model_options %}
<option value="{{ option.id }}" {% if option.id == selected_chat_model_config %}selected{% endif %}>{{ option.name }}</option>
{% endfor %}
</select>
</div>
@ -208,7 +208,7 @@
<div class="card-description-row">
<select id="paint-models">
{% for option in paint_model_options %}
<option value="{{ option.id }}" {% if option.id == selected_paint_model_config %}selected{% endif %}>{{ option.model_name }}</option>
<option value="{{ option.id }}" {% if option.id == selected_paint_model_config %}selected{% endif %}>{{ option.name }}</option>
{% endfor %}
</select>
</div>

View file

@ -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,