Show temp status message in Khoj web chat while Khoj is thinking

- Scroll to bottom after adding temporary status message and
references too
This commit is contained in:
Debanjum Singh Solanky
2023-07-05 17:19:39 -07:00
parent 257a421e45
commit c12ec1fd03

View File

@@ -74,6 +74,10 @@
new_response_text.classList.add("chat-message-text", "khoj");
new_response.appendChild(new_response_text);
// Temporary status message to indicate that Khoj is thinking
new_response_text.innerHTML = "🤔";
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
// Call specified Khoj API which returns a streamed response of type text/plain
fetch(url)
.then(response => {
@@ -96,10 +100,17 @@
new_response_text.innerHTML += polishedReference;
} else {
// Clear temporary status message
if (new_response_text.innerHTML === "🤔") {
new_response_text.innerHTML = "";
}
new_response_text.innerHTML += chunk;
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
readStream();
}
// Scroll to bottom of chat window as chat response is streamed
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
});
}
readStream();