mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Reduce promise based nesting in chat JS func used in desktop, web client
Use async/await to reduce .then() based nesting to improve code readability
This commit is contained in:
@@ -346,8 +346,7 @@
|
|||||||
chatInput.classList.remove("option-enabled");
|
chatInput.classList.remove("option-enabled");
|
||||||
|
|
||||||
// Call specified Khoj API which returns a streamed response of type text/plain
|
// Call specified Khoj API which returns a streamed response of type text/plain
|
||||||
fetch(url, { headers })
|
let response = await fetch(url, { headers });
|
||||||
.then(response => {
|
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
let rawResponse = "";
|
let rawResponse = "";
|
||||||
@@ -454,7 +453,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
readStream();
|
readStream();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function incrementalChat(event) {
|
function incrementalChat(event) {
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
function chat() {
|
async 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 resultsCount = localStorage.getItem("khojResultsCount") || 5;
|
let resultsCount = localStorage.getItem("khojResultsCount") || 5;
|
||||||
@@ -351,8 +351,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
chatInput.classList.remove("option-enabled");
|
chatInput.classList.remove("option-enabled");
|
||||||
|
|
||||||
// Call specified Khoj API which returns a streamed response of type text/plain
|
// Call specified Khoj API which returns a streamed response of type text/plain
|
||||||
fetch(url)
|
let response = await fetch(url);
|
||||||
.then(response => {
|
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
let rawResponse = "";
|
let rawResponse = "";
|
||||||
@@ -458,8 +457,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
readStream();
|
readStream();
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function incrementalChat(event) {
|
function incrementalChat(event) {
|
||||||
if (!event.shiftKey && event.key === 'Enter') {
|
if (!event.shiftKey && event.key === 'Enter') {
|
||||||
|
|||||||
Reference in New Issue
Block a user