mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-30 19:03:01 +01:00
Use default values, delete content config on disable and update state
This commit is contained in:
parent
362063f5fe
commit
0a86220d42
5 changed files with 26 additions and 12 deletions
|
@ -138,7 +138,6 @@ export class KhojChatModal extends Modal {
|
||||||
return `${time_string}, ${date_string}`;
|
return `${time_string}, ${date_string}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getChatHistory(): Promise<void> {
|
async getChatHistory(): Promise<void> {
|
||||||
// Get chat history from Khoj backend
|
// Get chat history from Khoj backend
|
||||||
let chatUrl = `${this.setting.khojUrl}/api/chat/init?client=obsidian`;
|
let chatUrl = `${this.setting.khojUrl}/api/chat/init?client=obsidian`;
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
function chat() {
|
function chat() {
|
||||||
// Extract required fields for search from form
|
// Extract required fields for search from form
|
||||||
let query = document.getElementById("chat-input").value.trim();
|
let query = document.getElementById("chat-input").value.trim();
|
||||||
let results_count = localStorage.getItem("khojResultsCount");
|
let results_count = localStorage.getItem("khojResultsCount") || 5;
|
||||||
console.log(`Query: ${query}`);
|
console.log(`Query: ${query}`);
|
||||||
|
|
||||||
// Short circuit on empty query
|
// Short circuit on empty query
|
||||||
|
@ -93,14 +93,17 @@
|
||||||
|
|
||||||
// Decode message chunk from stream
|
// Decode message chunk from stream
|
||||||
const chunk = decoder.decode(value, { stream: true });
|
const chunk = decoder.decode(value, { stream: true });
|
||||||
if (chunk.startsWith("### compiled references:")) {
|
if (chunk.includes("### compiled references:")) {
|
||||||
// Display references used to generate response
|
const additionalResponse = chunk.split("### compiled references:")[0];
|
||||||
const rawReferences = chunk.split("### compiled references:")[1];
|
new_response_text.innerHTML += additionalResponse;
|
||||||
const rawReferencesAsJson = JSON.parse(rawReferences);
|
|
||||||
let polishedReferences = rawReferencesAsJson
|
const rawReference = chunk.split("### compiled references:")[1];
|
||||||
.map((reference, index) => generateReference(reference, index))
|
const rawReferenceAsJson = JSON.parse(rawReference);
|
||||||
|
let polishedReference = rawReferenceAsJson.map((reference, index) => generateReference(reference, index))
|
||||||
.join("<sup>,</sup>");
|
.join("<sup>,</sup>");
|
||||||
new_response_text.innerHTML += polishedReferences;
|
|
||||||
|
new_response_text.innerHTML += polishedReference;
|
||||||
|
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
|
||||||
} else {
|
} else {
|
||||||
// Display response from Khoj
|
// Display response from Khoj
|
||||||
if (new_response_text.innerHTML === "🤔") {
|
if (new_response_text.innerHTML === "🤔") {
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
query = document.getElementById("query").value.trim();
|
query = document.getElementById("query").value.trim();
|
||||||
type = document.getElementById("type").value;
|
type = document.getElementById("type").value;
|
||||||
searchHint = document.getElementById("info-hint");
|
searchHint = document.getElementById("info-hint");
|
||||||
results_count = localStorage.getItem("khojResultsCount");
|
results_count = localStorage.getItem("khojResultsCount") || 5;
|
||||||
console.log(`Query: ${query}, Type: ${type}, Results Count: ${results_count}`);
|
console.log(`Query: ${query}, Type: ${type}, Results Count: ${results_count}`);
|
||||||
|
|
||||||
// Short circuit on empty query
|
// Short circuit on empty query
|
||||||
|
|
|
@ -104,8 +104,8 @@ class PdfToJsonl(TextToJsonl):
|
||||||
entry_to_location_map += zip(pdf_entries_per_file, [pdf_file] * len(pdf_entries_per_file))
|
entry_to_location_map += zip(pdf_entries_per_file, [pdf_file] * len(pdf_entries_per_file))
|
||||||
entries.extend(pdf_entries_per_file)
|
entries.extend(pdf_entries_per_file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error processing file: {pdf_file}. This file will not be indexed.")
|
logger.warning(f"Unable to process file: {pdf_file}. This file will not be indexed.")
|
||||||
logger.error(e)
|
logger.warning(e)
|
||||||
|
|
||||||
return entries, dict(entry_to_location_map)
|
return entries, dict(entry_to_location_map)
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,17 @@ if not state.demo:
|
||||||
if state.config.content_type:
|
if state.config.content_type:
|
||||||
state.config.content_type[content_type] = None
|
state.config.content_type[content_type] = None
|
||||||
|
|
||||||
|
if content_type == "github":
|
||||||
|
state.model.github_search = None
|
||||||
|
elif content_type == "plugins":
|
||||||
|
state.model.plugin_search = None
|
||||||
|
elif content_type == "pdf":
|
||||||
|
state.model.pdf_search = None
|
||||||
|
elif content_type == "markdown":
|
||||||
|
state.model.markdown_search = None
|
||||||
|
elif content_type == "org":
|
||||||
|
state.model.org_search = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
save_config_to_file_updated_state()
|
save_config_to_file_updated_state()
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
@ -123,6 +134,7 @@ if not state.demo:
|
||||||
state.config = FullConfig()
|
state.config = FullConfig()
|
||||||
state.config.search_type = SearchConfig.parse_obj(constants.default_config["search-type"])
|
state.config.search_type = SearchConfig.parse_obj(constants.default_config["search-type"])
|
||||||
state.config.processor = ProcessorConfig(conversation=updated_config)
|
state.config.processor = ProcessorConfig(conversation=updated_config)
|
||||||
|
state.processor_config = configure_processor(state.config.processor)
|
||||||
try:
|
try:
|
||||||
save_config_to_file_updated_state()
|
save_config_to_file_updated_state()
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
Loading…
Reference in a new issue