mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Fix bug in chat feedback flow - user message not included during live chat
This commit is contained in:
@@ -436,7 +436,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
thumbsUpButton.onclick = function() {
|
thumbsUpButton.onclick = function() {
|
||||||
khojQuery = newHTML;
|
khojQuery = newHTML;
|
||||||
thumbsUpIcon.src = "/static/assets/icons/confirm-icon.svg";
|
thumbsUpIcon.src = "/static/assets/icons/confirm-icon.svg";
|
||||||
sendFeedback(userQuery,khojQuery,"Good Response");
|
sendFeedback(userQuery ,khojQuery, "Good Response");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create thumbs-down button
|
// Create thumbs-down button
|
||||||
@@ -449,7 +449,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
thumbsDownButton.onclick = function() {
|
thumbsDownButton.onclick = function() {
|
||||||
khojQuery = newHTML;
|
khojQuery = newHTML;
|
||||||
thumbsDownIcon.src = "/static/assets/icons/confirm-icon.svg";
|
thumbsDownIcon.src = "/static/assets/icons/confirm-icon.svg";
|
||||||
sendFeedback(userQuery,khojQuery,"Bad Response");
|
sendFeedback(userQuery, khojQuery, "Bad Response");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Append buttons to parent element
|
// Append buttons to parent element
|
||||||
@@ -651,7 +651,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
} else {
|
} else {
|
||||||
// If the chunk is not a JSON object, just display it as is
|
// If the chunk is not a JSON object, just display it as is
|
||||||
rawResponse += chunk;
|
rawResponse += chunk;
|
||||||
handleStreamResponse(newResponseText, rawResponse, loadingEllipsis);
|
handleStreamResponse(newResponseText, rawResponse, query, loadingEllipsis);
|
||||||
readStream();
|
readStream();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -687,14 +687,14 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
return loadingEllipsis;
|
return loadingEllipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleStreamResponse(newResponseElement, rawResponse, loadingEllipsis, replace=true) {
|
function handleStreamResponse(newResponseElement, rawResponse, rawQuery, loadingEllipsis, replace=true) {
|
||||||
if (newResponseElement.getElementsByClassName("lds-ellipsis").length > 0 && loadingEllipsis) {
|
if (newResponseElement.getElementsByClassName("lds-ellipsis").length > 0 && loadingEllipsis) {
|
||||||
newResponseElement.removeChild(loadingEllipsis);
|
newResponseElement.removeChild(loadingEllipsis);
|
||||||
}
|
}
|
||||||
if (replace) {
|
if (replace) {
|
||||||
newResponseElement.innerHTML = "";
|
newResponseElement.innerHTML = "";
|
||||||
}
|
}
|
||||||
newResponseElement.appendChild(formatHTMLMessage(rawResponse, false, replace));
|
newResponseElement.appendChild(formatHTMLMessage(rawResponse, false, replace, rawQuery));
|
||||||
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
|
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -994,6 +994,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
loadingEllipsis: null,
|
loadingEllipsis: null,
|
||||||
references: {},
|
references: {},
|
||||||
rawResponse: "",
|
rawResponse: "",
|
||||||
|
rawQuery: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatBody.dataset.conversationId) {
|
if (chatBody.dataset.conversationId) {
|
||||||
@@ -1012,6 +1013,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
// Append any references after all the data has been streamed
|
// Append any references after all the data has been streamed
|
||||||
finalizeChatBodyResponse(websocketState.references, websocketState.newResponseTextEl);
|
finalizeChatBodyResponse(websocketState.references, websocketState.newResponseTextEl);
|
||||||
|
|
||||||
|
const liveQuery = websocketState.rawQuery;
|
||||||
// Reset variables
|
// Reset variables
|
||||||
websocketState = {
|
websocketState = {
|
||||||
newResponseTextEl: null,
|
newResponseTextEl: null,
|
||||||
@@ -1019,6 +1021,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
loadingEllipsis: null,
|
loadingEllipsis: null,
|
||||||
references: {},
|
references: {},
|
||||||
rawResponse: "",
|
rawResponse: "",
|
||||||
|
rawQuery: liveQuery,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -1040,9 +1043,9 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
websocketState.rawResponse = rawResponse;
|
websocketState.rawResponse = rawResponse;
|
||||||
websocketState.references = references;
|
websocketState.references = references;
|
||||||
} else if (chunk.type == "status") {
|
} else if (chunk.type == "status") {
|
||||||
handleStreamResponse(websocketState.newResponseTextEl, chunk.message, null, false);
|
handleStreamResponse(websocketState.newResponseTextEl, chunk.message, websocketState.rawQuery, null, false);
|
||||||
} else if (chunk.type == "rate_limit") {
|
} else if (chunk.type == "rate_limit") {
|
||||||
handleStreamResponse(websocketState.newResponseTextEl, chunk.message, websocketState.loadingEllipsis, true);
|
handleStreamResponse(websocketState.newResponseTextEl, chunk.message, websocketState.rawQuery, websocketState.loadingEllipsis, true);
|
||||||
} else {
|
} else {
|
||||||
rawResponse = chunk.response;
|
rawResponse = chunk.response;
|
||||||
}
|
}
|
||||||
@@ -1065,7 +1068,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
// If the chunk is not a JSON object, just display it as is
|
// If the chunk is not a JSON object, just display it as is
|
||||||
websocketState.rawResponse += chunk;
|
websocketState.rawResponse += chunk;
|
||||||
if (websocketState.newResponseTextEl) {
|
if (websocketState.newResponseTextEl) {
|
||||||
handleStreamResponse(websocketState.newResponseTextEl, websocketState.rawResponse, websocketState.loadingEllipsis);
|
handleStreamResponse(websocketState.newResponseTextEl, websocketState.rawResponse, websocketState.rawQuery, websocketState.loadingEllipsis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,6 +1149,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
loadingEllipsis,
|
loadingEllipsis,
|
||||||
references,
|
references,
|
||||||
rawResponse,
|
rawResponse,
|
||||||
|
rawQuery: query,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user