mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Update desktop shortcut, web app factchecker to use new POST chat API
This commit is contained in:
@@ -366,7 +366,7 @@
|
|||||||
let conversationID = chat_body.dataset.conversationId;
|
let conversationID = chat_body.dataset.conversationId;
|
||||||
let hostURL = await window.hostURLAPI.getURL();
|
let hostURL = await window.hostURLAPI.getURL();
|
||||||
const khojToken = await window.tokenAPI.getToken();
|
const khojToken = await window.tokenAPI.getToken();
|
||||||
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
const headers = { 'Authorization': `Bearer ${khojToken}`, 'Content-Type': 'application/json' };
|
||||||
|
|
||||||
if (!conversationID) {
|
if (!conversationID) {
|
||||||
let response = await fetch(`${hostURL}/api/chat/sessions`, { method: "POST", headers });
|
let response = await fetch(`${hostURL}/api/chat/sessions`, { method: "POST", headers });
|
||||||
@@ -402,12 +402,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Construct API URL to execute chat query
|
// Construct API URL to execute chat query
|
||||||
let chatApi = `${hostURL}/api/chat?q=${encodeURIComponent(query)}&conversation_id=${conversationID}&stream=true&client=desktop`;
|
const chatApi = `${hostURL}/api/chat?client=desktop`;
|
||||||
chatApi += (!!region && !!city && !!countryName && !!timezone)
|
const chatApiBody = {
|
||||||
? `®ion=${region}&city=${city}&country=${countryName}&timezone=${timezone}`
|
q: query,
|
||||||
: '';
|
conversation_id: parseInt(conversationID),
|
||||||
|
stream: true,
|
||||||
|
...(!!city && { city: city }),
|
||||||
|
...(!!region && { region: region }),
|
||||||
|
...(!!countryName && { country: countryName }),
|
||||||
|
...(!!timezone && { timezone: timezone }),
|
||||||
|
};
|
||||||
|
|
||||||
const response = await fetch(chatApi, { method: 'POST', headers });
|
const response = await fetch(chatApi, {
|
||||||
|
method: "POST",
|
||||||
|
headers: headers,
|
||||||
|
body: JSON.stringify(chatApiBody),
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!response.ok) throw new Error(response.statusText);
|
if (!response.ok) throw new Error(response.statusText);
|
||||||
|
|||||||
@@ -75,11 +75,24 @@ async function verifyStatement(
|
|||||||
setInitialReferences: (references: ResponseWithReferences) => void,
|
setInitialReferences: (references: ResponseWithReferences) => void,
|
||||||
) {
|
) {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
// Send a message to the chat server to verify the fact
|
// Construct the verification payload
|
||||||
let verificationMessage = `${verificationPrecursor} ${message}`;
|
let verificationMessage = `${verificationPrecursor} ${message}`;
|
||||||
const apiURL = `${chatURL}?q=${encodeURIComponent(verificationMessage)}&client=web&stream=true&conversation_id=${conversationId}`;
|
const apiURL = `${chatURL}?client=web`;
|
||||||
|
const requestBody = {
|
||||||
|
q: verificationMessage,
|
||||||
|
conversation_id: conversationId,
|
||||||
|
stream: true,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(apiURL, { method: "POST" });
|
// Send a message to the chat server to verify the fact
|
||||||
|
const response = await fetch(apiURL, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(requestBody),
|
||||||
|
});
|
||||||
if (!response.body) throw new Error("No response body found");
|
if (!response.body) throw new Error("No response body found");
|
||||||
|
|
||||||
const reader = response.body?.getReader();
|
const reader = response.body?.getReader();
|
||||||
|
|||||||
Reference in New Issue
Block a user