Only show 3 starter questions even when consecutive chat sessions created

Reset starter question suggestions before appending in web, desktop app

Otherwise previously it'd keep adding to existing starter question
suggestions on each new session creation if multiple consecutive new
chat sessions created.

This would result in more than the 3 expected starter questions being
displayed at a time
This commit is contained in:
Debanjum Singh Solanky 2024-02-22 20:11:03 +05:30
parent 102f5c3f53
commit 50617594fd
2 changed files with 11 additions and 7 deletions

View file

@ -541,6 +541,7 @@
chatInput.value = chatInput.value.trimStart();
let questionStarterSuggestions = document.getElementById("question-starters");
questionStarterSuggestions.innerHTML = "";
questionStarterSuggestions.style.display = "none";
if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) {
@ -592,6 +593,7 @@
const headers = { 'Authorization': `Bearer ${khojToken}` };
let chatBody = document.getElementById("chat-body");
chatBody.innerHTML = "";
let conversationId = chatBody.dataset.conversationId;
let chatHistoryUrl = `/api/chat/history?client=desktop`;
if (conversationId) {
@ -672,11 +674,11 @@
fetch(`${hostURL}/api/chat/starters?client=desktop`, { headers })
.then(response => response.json())
.then(data => {
// Render chat options, if any
// Render conversation starters, if any
if (data.length > 0) {
let questionStarterSuggestions = document.getElementById("question-starters");
for (let index in data) {
let questionStarter = data[index];
questionStarterSuggestions.innerHTML = "";
data.forEach((questionStarter) => {
let questionStarterButton = document.createElement('button');
questionStarterButton.innerHTML = questionStarter;
questionStarterButton.classList.add("question-starter");
@ -686,7 +688,7 @@
chat();
});
questionStarterSuggestions.appendChild(questionStarterButton);
}
});
questionStarterSuggestions.style.display = "grid";
}
})

View file

@ -523,6 +523,7 @@ To get started, just start typing below. You can also type / to see a list of co
chatInput.value = chatInput.value.trimStart();
let questionStarterSuggestions = document.getElementById("question-starters");
questionStarterSuggestions.innerHTML = "";
questionStarterSuggestions.style.display = "none";
if (chatInput.value.startsWith("/") && chatInput.value.split(" ").length === 1) {
@ -568,6 +569,7 @@ To get started, just start typing below. You can also type / to see a list of co
function loadChat() {
let chatBody = document.getElementById("chat-body");
chatBody.innerHTML = "";
let conversationId = chatBody.dataset.conversationId;
let chatHistoryUrl = `/api/chat/history?client=web`;
if (conversationId) {
@ -650,8 +652,8 @@ To get started, just start typing below. You can also type / to see a list of co
// Render chat options, if any
if (data.length > 0) {
let questionStarterSuggestions = document.getElementById("question-starters");
for (let index in data) {
let questionStarter = data[index];
questionStarterSuggestions.innerHTML = "";
data.forEach((questionStarter) => {
let questionStarterButton = document.createElement('button');
questionStarterButton.innerHTML = questionStarter;
questionStarterButton.classList.add("question-starter");
@ -661,7 +663,7 @@ To get started, just start typing below. You can also type / to see a list of co
chat();
});
questionStarterSuggestions.appendChild(questionStarterButton);
}
});
questionStarterSuggestions.style.display = "grid";
}
})