From e590d75b202502fa64209d5cce43e04b16b4b65c Mon Sep 17 00:00:00 2001
From: sabaimran <65192171+sabaimran@users.noreply.github.com>
Date: Sat, 15 Jul 2023 14:11:54 -0700
Subject: [PATCH] Start Khoj even when config is not valid (#320)
* Add icon to indicate bad config, start Khoj even if there was an issue setting up the index
---
src/khoj/configure.py | 2 +-
.../web/assets/icons/question-mark-icon.svg | 1 +
src/khoj/interface/web/config.html | 61 +++++++++++++++----
src/khoj/routers/web_client.py | 18 +++++-
4 files changed, 69 insertions(+), 13 deletions(-)
create mode 100644 src/khoj/interface/web/assets/icons/question-mark-icon.svg
diff --git a/src/khoj/configure.py b/src/khoj/configure.py
index 18c5ac8a..84b87ff3 100644
--- a/src/khoj/configure.py
+++ b/src/khoj/configure.py
@@ -233,7 +233,7 @@ def configure_content(
)
except Exception as e:
- logger.error("🚨 Failed to setup search")
+ logger.error(f"🚨 Failed to setup search: {e}", exc_info=True)
raise e
# Invalidate Query Cache
diff --git a/src/khoj/interface/web/assets/icons/question-mark-icon.svg b/src/khoj/interface/web/assets/icons/question-mark-icon.svg
new file mode 100644
index 00000000..fde2e972
--- /dev/null
+++ b/src/khoj/interface/web/assets/icons/question-mark-icon.svg
@@ -0,0 +1 @@
+
diff --git a/src/khoj/interface/web/config.html b/src/khoj/interface/web/config.html
index 07ad8189..81968d94 100644
--- a/src/khoj/interface/web/config.html
+++ b/src/khoj/interface/web/config.html
@@ -11,7 +11,11 @@
Github
{% if current_config.content_type.github %}
-
+ {% if current_model_state.github == False %}
+
+ {% else %}
+
+ {% endif %}
{% endif %}
@@ -42,7 +46,11 @@
Notion
{% if current_config.content_type.notion %}
-
+ {% if current_model_state.notion == False %}
+
+ {% else %}
+
+ {% endif %}
{% endif %}
@@ -73,7 +81,11 @@
Markdown
{% if current_config.content_type.markdown %}
-
+ {% if current_model_state.markdown == False%}
+
+ {% else %}
+
+ {% endif %}
{% endif %}
@@ -104,7 +116,11 @@
Org
{% if current_config.content_type.org %}
-
+ {% if current_model_state.org == False %}
+
+ {% else %}
+
+ {% endif %}
{% endif %}
@@ -135,7 +151,11 @@
PDF
{% if current_config.content_type.pdf %}
-
+ {% if current_model_state.pdf == False %}
+
+ {% else %}
+
+ {% endif %}
{% endif %}
@@ -171,8 +191,12 @@
Chat
{% if current_config.processor and current_config.processor.conversation %}
-
- {% endif %}
+ {% if current_model_state.conversation == False %}
+
+ {% else %}
+
+ {% endif %}
+ {% endif %}
@@ -227,7 +251,14 @@
contentTypeClearButton.style.display = "none";
var configuredIcon = document.getElementById("configured-icon-" + content_type);
- configuredIcon.style.display = "none";
+ if (configuredIcon) {
+ configuredIcon.style.display = "none";
+ }
+
+ var misconfiguredIcon = document.getElementById("misconfigured-icon-" + content_type);
+ if (misconfiguredIcon) {
+ misconfiguredIcon.style.display = "none";
+ }
}
})
};
@@ -248,7 +279,15 @@
conversationClearButton.style.display = "none";
var configuredIcon = document.getElementById("configured-icon-conversation-processor");
- configuredIcon.style.display = "none";
+ if (configuredIcon) {
+ configuredIcon.style.display = "none";
+ }
+
+ var misconfiguredIcon = document.getElementById("misconfigured-icon-conversation-processor");
+
+ if (misconfiguredIcon) {
+ misconfiguredIcon.style.display = "none";
+ }
}
})
};
@@ -294,14 +333,14 @@
if (data.detail != null) {
throw new Error(data.detail);
}
- document.getElementById("status").innerHTML = emoji + successText;
+ document.getElementById("status").innerHTML = emoji + " " + successText;
document.getElementById("status").style.display = "block";
button.disabled = false;
button.innerHTML = '✅ Done!';
})
.catch((error) => {
console.error('Error:', error);
- document.getElementById("status").innerHTML = emoji + errorText
+ document.getElementById("status").innerHTML = emoji + " " + errorText
document.getElementById("status").style.display = "block";
button.disabled = false;
button.innerHTML = '⚠️ Unsuccessful';
diff --git a/src/khoj/routers/web_client.py b/src/khoj/routers/web_client.py
index e3bb7dde..43ffb357 100644
--- a/src/khoj/routers/web_client.py
+++ b/src/khoj/routers/web_client.py
@@ -39,7 +39,23 @@ if not state.demo:
processor=None,
)
current_config = state.config or json.loads(default_full_config.json())
- return templates.TemplateResponse("config.html", context={"request": request, "current_config": current_config})
+ successfully_configured = {
+ "pdf": state.content_index.pdf is not None,
+ "markdown": state.content_index.markdown is not None,
+ "org": state.content_index.org is not None,
+ "image": state.content_index.image is not None,
+ "github": state.content_index.github is not None,
+ "notion": state.content_index.notion is not None,
+ "conversation": state.processor_config.conversation is not None,
+ }
+ return templates.TemplateResponse(
+ "config.html",
+ context={
+ "request": request,
+ "current_config": current_config,
+ "current_model_state": successfully_configured,
+ },
+ )
@web_client.get("/config/content_type/github", response_class=HTMLResponse)
def github_config_page(request: Request):