forked from open-webui/open-webui
Merge pull request #203 from therohitdas/display-error
feat: Display error returned by ollama
This commit is contained in:
commit
763448bca9
3 changed files with 190 additions and 115 deletions
|
@ -655,7 +655,32 @@
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
{@html marked(message.content.replace('\\\\', '\\\\\\'))}
|
{#if message?.error === true}
|
||||||
|
<div
|
||||||
|
class="flex mt-2 mb-4 space-x-2 border px-4 py-3 border-red-800 bg-red-800/30 font-medium rounded-lg"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width="1.5"
|
||||||
|
stroke="currentColor"
|
||||||
|
class="w-5 h-5 self-center"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<div class=" self-center">
|
||||||
|
{message.content}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
{@html marked(message.content.replace('\\\\', '\\\\\\'))}
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if message.done}
|
{#if message.done}
|
||||||
<div class=" flex justify-start space-x-1 -mt-2">
|
<div class=" flex justify-start space-x-1 -mt-2">
|
||||||
|
|
|
@ -189,82 +189,107 @@
|
||||||
},
|
},
|
||||||
format: $settings.requestFormat ?? undefined
|
format: $settings.requestFormat ?? undefined
|
||||||
})
|
})
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
const reader = res.body
|
if (res && res.ok) {
|
||||||
.pipeThrough(new TextDecoderStream())
|
const reader = res.body
|
||||||
.pipeThrough(splitStream('\n'))
|
.pipeThrough(new TextDecoderStream())
|
||||||
.getReader();
|
.pipeThrough(splitStream('\n'))
|
||||||
|
.getReader();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const { value, done } = await reader.read();
|
const { value, done } = await reader.read();
|
||||||
if (done || stopResponseFlag || _chatId !== $chatId) {
|
if (done || stopResponseFlag || _chatId !== $chatId) {
|
||||||
responseMessage.done = true;
|
responseMessage.done = true;
|
||||||
messages = messages;
|
messages = messages;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let lines = value.split('\n');
|
let lines = value.split('\n');
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line !== '') {
|
if (line !== '') {
|
||||||
console.log(line);
|
console.log(line);
|
||||||
let data = JSON.parse(line);
|
let data = JSON.parse(line);
|
||||||
|
|
||||||
if ('detail' in data) {
|
if ('detail' in data) {
|
||||||
throw data;
|
throw data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.done == false) {
|
if (data.done == false) {
|
||||||
if (responseMessage.content == '' && data.message.content == '\n') {
|
if (responseMessage.content == '' && data.message.content == '\n') {
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
responseMessage.content += data.message.content;
|
||||||
|
messages = messages;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
responseMessage.content += data.message.content;
|
responseMessage.done = true;
|
||||||
|
responseMessage.context = data.context ?? null;
|
||||||
|
responseMessage.info = {
|
||||||
|
total_duration: data.total_duration,
|
||||||
|
prompt_eval_count: data.prompt_eval_count,
|
||||||
|
prompt_eval_duration: data.prompt_eval_duration,
|
||||||
|
eval_count: data.eval_count,
|
||||||
|
eval_duration: data.eval_duration
|
||||||
|
};
|
||||||
messages = messages;
|
messages = messages;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
responseMessage.done = true;
|
|
||||||
responseMessage.context = data.context ?? null;
|
|
||||||
responseMessage.info = {
|
|
||||||
total_duration: data.total_duration,
|
|
||||||
prompt_eval_count: data.prompt_eval_count,
|
|
||||||
prompt_eval_duration: data.prompt_eval_duration,
|
|
||||||
eval_count: data.eval_count,
|
|
||||||
eval_duration: data.eval_duration
|
|
||||||
};
|
|
||||||
messages = messages;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
if ('detail' in error) {
|
||||||
|
toast.error(error.detail);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
|
if (autoScroll) {
|
||||||
|
window.scrollTo({ top: document.body.scrollHeight });
|
||||||
|
}
|
||||||
|
|
||||||
|
await $db.updateChatById(_chatId, {
|
||||||
|
title: title === '' ? 'New Chat' : title,
|
||||||
|
models: selectedModels,
|
||||||
|
system: $settings.system ?? undefined,
|
||||||
|
options: {
|
||||||
|
seed: $settings.seed ?? undefined,
|
||||||
|
temperature: $settings.temperature ?? undefined,
|
||||||
|
repeat_penalty: $settings.repeat_penalty ?? undefined,
|
||||||
|
top_k: $settings.top_k ?? undefined,
|
||||||
|
top_p: $settings.top_p ?? undefined,
|
||||||
|
num_ctx: $settings.num_ctx ?? undefined,
|
||||||
|
...($settings.options ?? {})
|
||||||
|
},
|
||||||
|
messages: messages,
|
||||||
|
history: history
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (res !== null) {
|
||||||
|
const error = await res.json();
|
||||||
console.log(error);
|
console.log(error);
|
||||||
if ('detail' in error) {
|
if ('detail' in error) {
|
||||||
toast.error(error.detail);
|
toast.error(error.detail);
|
||||||
|
responseMessage.content = error.detail;
|
||||||
|
} else {
|
||||||
|
toast.error(error.error);
|
||||||
|
responseMessage.content = error.error;
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
|
toast.error(`Uh-oh! There was an issue connecting to Ollama.`);
|
||||||
|
responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoScroll) {
|
responseMessage.error = true;
|
||||||
window.scrollTo({ top: document.body.scrollHeight });
|
responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`;
|
||||||
}
|
responseMessage.done = true;
|
||||||
|
messages = messages;
|
||||||
await $db.updateChatById(_chatId, {
|
|
||||||
title: title === '' ? 'New Chat' : title,
|
|
||||||
models: selectedModels,
|
|
||||||
system: $settings.system ?? undefined,
|
|
||||||
options: {
|
|
||||||
seed: $settings.seed ?? undefined,
|
|
||||||
temperature: $settings.temperature ?? undefined,
|
|
||||||
repeat_penalty: $settings.repeat_penalty ?? undefined,
|
|
||||||
top_k: $settings.top_k ?? undefined,
|
|
||||||
top_p: $settings.top_p ?? undefined,
|
|
||||||
num_ctx: $settings.num_ctx ?? undefined,
|
|
||||||
...($settings.options ?? {})
|
|
||||||
},
|
|
||||||
messages: messages,
|
|
||||||
history: history
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stopResponseFlag = false;
|
stopResponseFlag = false;
|
||||||
|
|
|
@ -216,82 +216,107 @@
|
||||||
},
|
},
|
||||||
format: $settings.requestFormat ?? undefined
|
format: $settings.requestFormat ?? undefined
|
||||||
})
|
})
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
const reader = res.body
|
if (res && res.ok) {
|
||||||
.pipeThrough(new TextDecoderStream())
|
const reader = res.body
|
||||||
.pipeThrough(splitStream('\n'))
|
.pipeThrough(new TextDecoderStream())
|
||||||
.getReader();
|
.pipeThrough(splitStream('\n'))
|
||||||
|
.getReader();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const { value, done } = await reader.read();
|
const { value, done } = await reader.read();
|
||||||
if (done || stopResponseFlag || _chatId !== $chatId) {
|
if (done || stopResponseFlag || _chatId !== $chatId) {
|
||||||
responseMessage.done = true;
|
responseMessage.done = true;
|
||||||
messages = messages;
|
messages = messages;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let lines = value.split('\n');
|
let lines = value.split('\n');
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line !== '') {
|
if (line !== '') {
|
||||||
console.log(line);
|
console.log(line);
|
||||||
let data = JSON.parse(line);
|
let data = JSON.parse(line);
|
||||||
|
|
||||||
if ('detail' in data) {
|
if ('detail' in data) {
|
||||||
throw data;
|
throw data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.done == false) {
|
if (data.done == false) {
|
||||||
if (responseMessage.content == '' && data.message.content == '\n') {
|
if (responseMessage.content == '' && data.message.content == '\n') {
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
responseMessage.content += data.message.content;
|
||||||
|
messages = messages;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
responseMessage.content += data.message.content;
|
responseMessage.done = true;
|
||||||
|
responseMessage.context = data.context ?? null;
|
||||||
|
responseMessage.info = {
|
||||||
|
total_duration: data.total_duration,
|
||||||
|
prompt_eval_count: data.prompt_eval_count,
|
||||||
|
prompt_eval_duration: data.prompt_eval_duration,
|
||||||
|
eval_count: data.eval_count,
|
||||||
|
eval_duration: data.eval_duration
|
||||||
|
};
|
||||||
messages = messages;
|
messages = messages;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
responseMessage.done = true;
|
|
||||||
responseMessage.context = data.context ?? null;
|
|
||||||
responseMessage.info = {
|
|
||||||
total_duration: data.total_duration,
|
|
||||||
prompt_eval_count: data.prompt_eval_count,
|
|
||||||
prompt_eval_duration: data.prompt_eval_duration,
|
|
||||||
eval_count: data.eval_count,
|
|
||||||
eval_duration: data.eval_duration
|
|
||||||
};
|
|
||||||
messages = messages;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
if ('detail' in error) {
|
||||||
|
toast.error(error.detail);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
|
if (autoScroll) {
|
||||||
|
window.scrollTo({ top: document.body.scrollHeight });
|
||||||
|
}
|
||||||
|
|
||||||
|
await $db.updateChatById(_chatId, {
|
||||||
|
title: title === '' ? 'New Chat' : title,
|
||||||
|
models: selectedModels,
|
||||||
|
system: $settings.system ?? undefined,
|
||||||
|
options: {
|
||||||
|
seed: $settings.seed ?? undefined,
|
||||||
|
temperature: $settings.temperature ?? undefined,
|
||||||
|
repeat_penalty: $settings.repeat_penalty ?? undefined,
|
||||||
|
top_k: $settings.top_k ?? undefined,
|
||||||
|
top_p: $settings.top_p ?? undefined,
|
||||||
|
num_ctx: $settings.num_ctx ?? undefined,
|
||||||
|
...($settings.options ?? {})
|
||||||
|
},
|
||||||
|
messages: messages,
|
||||||
|
history: history
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (res !== null) {
|
||||||
|
const error = await res.json();
|
||||||
console.log(error);
|
console.log(error);
|
||||||
if ('detail' in error) {
|
if ('detail' in error) {
|
||||||
toast.error(error.detail);
|
toast.error(error.detail);
|
||||||
|
responseMessage.content = error.detail;
|
||||||
|
} else {
|
||||||
|
toast.error(error.error);
|
||||||
|
responseMessage.content = error.error;
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
|
toast.error(`Uh-oh! There was an issue connecting to Ollama.`);
|
||||||
|
responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoScroll) {
|
responseMessage.error = true;
|
||||||
window.scrollTo({ top: document.body.scrollHeight });
|
responseMessage.content = `Uh-oh! There was an issue connecting to Ollama.`;
|
||||||
}
|
responseMessage.done = true;
|
||||||
|
messages = messages;
|
||||||
await $db.updateChatById(_chatId, {
|
|
||||||
title: title === '' ? 'New Chat' : title,
|
|
||||||
models: selectedModels,
|
|
||||||
system: $settings.system ?? undefined,
|
|
||||||
options: {
|
|
||||||
seed: $settings.seed ?? undefined,
|
|
||||||
temperature: $settings.temperature ?? undefined,
|
|
||||||
repeat_penalty: $settings.repeat_penalty ?? undefined,
|
|
||||||
top_k: $settings.top_k ?? undefined,
|
|
||||||
top_p: $settings.top_p ?? undefined,
|
|
||||||
num_ctx: $settings.num_ctx ?? undefined,
|
|
||||||
...($settings.options ?? {})
|
|
||||||
},
|
|
||||||
messages: messages,
|
|
||||||
history: history
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stopResponseFlag = false;
|
stopResponseFlag = false;
|
||||||
|
|
Loading…
Reference in a new issue