Include timeout function in GUI
This commit is contained in:
parent
437831aea5
commit
445eda821d
|
@ -38,6 +38,11 @@ class KuzcoCore {
|
|||
|
||||
async sendPrompt(prompt, model) {
|
||||
console.log("Model received in sendPrompt:", model)
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
||||
const timeoutId = setTimeout(() => controller.abort(), 15000);
|
||||
|
||||
try {
|
||||
const response = await fetch('https://relay.kuzco.xyz/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
|
@ -50,16 +55,25 @@ class KuzcoCore {
|
|||
model: model,
|
||||
stream: false,
|
||||
}),
|
||||
signal: signal,
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`An error occurred: ${error.message}`);
|
||||
return { error: error.message };
|
||||
clearTimeout(timeoutId);
|
||||
if (error.name === 'AbortError') {
|
||||
console.error('Request was aborted due to timeout.');
|
||||
return { error: 'Request timed out. Please try again.' };
|
||||
} else {
|
||||
console.error(`An error occurred: ${error.message}`);
|
||||
return { error: error.message };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "kuzco-gui",
|
||||
"version": "1.0.0",
|
||||
"version": "0.0.1",
|
||||
"description": "Simple gui for kuzco api",
|
||||
"author": "Wizzard <Wizzard@deadzone.lol>",
|
||||
"main": "kuzco-gui.js",
|
||||
|
|
|
@ -39,6 +39,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
try {
|
||||
const response = await window.electronAPI.sendPrompt(userInput, selectedModel);
|
||||
if (response.error) {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
const assistantMessage = response.choices[0].message.content.trim();
|
||||
displayMessage(assistantMessage, 'assistant');
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue