mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Show temp status message in Khoj Obsidian chat while Khoj is thinking
- Scroll to bottom after adding temporary status message and references too
This commit is contained in:
@@ -156,6 +156,10 @@ export class KhojChatModal extends Modal {
|
|||||||
// Get chat response from Khoj backend
|
// Get chat response from Khoj backend
|
||||||
let encodedQuery = encodeURIComponent(query);
|
let encodedQuery = encodeURIComponent(query);
|
||||||
let chatUrl = `${this.setting.khojUrl}/api/chat?q=${encodedQuery}&client=obsidian`;
|
let chatUrl = `${this.setting.khojUrl}/api/chat?q=${encodedQuery}&client=obsidian`;
|
||||||
|
let responseElement = this.createKhojResponseDiv();
|
||||||
|
|
||||||
|
// Temporary status message to indicate that Khoj is thinking
|
||||||
|
this.renderIncrementalMessage(responseElement, "🤔");
|
||||||
|
|
||||||
let response = await fetch(chatUrl, {
|
let response = await fetch(chatUrl, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -164,22 +168,25 @@ export class KhojChatModal extends Modal {
|
|||||||
"Content-Type": "text/event-stream"
|
"Content-Type": "text/event-stream"
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
let responseElemeent = this.createKhojResponseDiv();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (response.body == null) {
|
if (response.body == null) {
|
||||||
throw new Error("Response body is null");
|
throw new Error("Response body is null");
|
||||||
}
|
}
|
||||||
|
// Clear thinking status message
|
||||||
|
if (responseElement.innerHTML === "🤔") {
|
||||||
|
responseElement.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
for await (const chunk of response.body) {
|
for await (const chunk of response.body) {
|
||||||
const responseText = chunk.toString();
|
const responseText = chunk.toString();
|
||||||
if (responseText.startsWith("### compiled references:")) {
|
if (responseText.startsWith("### compiled references:")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.renderIncrementalMessage(responseElemeent, responseText);
|
this.renderIncrementalMessage(responseElement, responseText);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.renderIncrementalMessage(responseElemeent, "Sorry, unable to get response from Khoj backend ❤️🩹. Contact developer for help at team@khoj.dev or <a href='https://discord.gg/BDgyabRM6e'>in Discord</a>")
|
this.renderIncrementalMessage(responseElement, "Sorry, unable to get response from Khoj backend ❤️🩹. Contact developer for help at team@khoj.dev or <a href='https://discord.gg/BDgyabRM6e'>in Discord</a>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user