Skip to content

Commit 8598193

Browse files
authored
Merge pull request #70 from yfguo/improve-error-handling
allow error message to be cleared
2 parents e4e30be + a79120b commit 8598193

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

backend/open_webui/routers/openai.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,11 @@ async def generate_chat_completion(
10151015
)
10161016
else:
10171017
try:
1018+
log.debug(f"response: {r}")
10181019
response = await r.json()
10191020
except Exception as e:
10201021
log.debug(f"response: {r}")
1021-
r.raise_for_status()
1022+
r.raise_for_status()
10221023
return response
10231024
except Exception as e:
10241025
log.exception(e)

src/lib/components/chat/MessageInput.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@
107107
let inputVariables = {};
108108
let inputVariableValues = {};
109109
110+
let currentMessage = null;
111+
let showStopButton = false;
112+
$: currentMessage = history?.messages?.[history?.currentId ?? ''] ?? null;
113+
$: showStopButton =
114+
(Array.isArray(taskIds) && taskIds.length > 0) ||
115+
(currentMessage?.role === 'assistant' && currentMessage?.done !== true);
116+
110117
$: onChange({
111118
prompt,
112119
files: files
@@ -1819,7 +1826,7 @@
18191826
</Tooltip>
18201827
{/if}
18211828

1822-
{#if (taskIds && taskIds.length > 0) || (history.currentId && history.messages[history.currentId]?.done != true)}
1829+
{#if showStopButton}
18231830
<div class=" flex items-center">
18241831
<Tooltip content={$i18n.t('Stop')}>
18251832
<button
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
<script lang="ts">
2+
import { createEventDispatcher, getContext } from 'svelte';
3+
import type { Writable } from 'svelte/store';
4+
import type { i18n as i18nType } from 'i18next';
5+
26
import Info from '$lib/components/icons/Info.svelte';
37
8+
const i18n = getContext<Writable<i18nType>>('i18n');
9+
const dispatch = createEventDispatcher();
10+
411
export let content = '';
12+
13+
const handleClear = () => {
14+
dispatch('clear');
15+
};
516
</script>
617

718
<div class="flex my-2 gap-2.5 border px-4 py-3 border-red-600/10 bg-red-600/10 rounded-lg">
8-
<div class=" self-start mt-0.5">
19+
<div class="self-start mt-0.5">
920
<Info className="size-5 text-red-700 dark:text-red-400" />
1021
</div>
1122

12-
<div class=" self-center text-sm">
13-
{typeof content === 'string' ? content : JSON.stringify(content)}
23+
<div class="flex flex-col gap-2 text-sm text-left">
24+
<div>{typeof content === 'string' ? content : JSON.stringify(content)}</div>
25+
<button
26+
type="button"
27+
class="self-start rounded-md border border-red-500/40 bg-transparent px-3 py-1 text-xs font-medium text-red-700 transition hover:bg-red-500/10 dark:text-red-300"
28+
on:click={handleClear}
29+
>
30+
{$i18n.t('Clear')}
31+
</button>
1432
</div>
1533
</div>

src/lib/components/chat/Messages/ResponseMessage.svelte

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
151151
let messageIndexEdit = false;
152152
153+
let hideMessage = false;
154+
$: hideMessage = message?.hidden ?? false;
155+
153156
let audioParts: Record<number, HTMLAudioElement | null> = {};
154157
let speaking = false;
155158
let speakingIdx: number | undefined;
@@ -194,6 +197,30 @@
194197
});
195198
};
196199
200+
const clearResponseError = () => {
201+
const target = history?.messages?.[message.id];
202+
if (!target) {
203+
return;
204+
}
205+
206+
const updatedMessage = {
207+
...target,
208+
done: true,
209+
content: '',
210+
hidden: true
211+
};
212+
delete updatedMessage.error;
213+
214+
history.messages = {
215+
...history.messages,
216+
[message.id]: updatedMessage
217+
};
218+
message = JSON.parse(JSON.stringify(updatedMessage));
219+
history.currentId = message.id;
220+
221+
updateChat?.();
222+
};
223+
197224
const toggleSpeakMessage = async () => {
198225
if (speaking) {
199226
try {
@@ -599,7 +626,7 @@
599626

600627
{#key message.id}
601628
<div
602-
class=" flex w-full message-{message.id}"
629+
class={`flex w-full message-${message.id} ${hideMessage ? 'hidden' : ''}`}
603630
id="message-{message.id}"
604631
dir={$settings.chatDirection}
605632
>
@@ -853,7 +880,7 @@
853880
{/if}
854881

855882
{#if message?.error}
856-
<Error content={message?.error?.content ?? message.content} />
883+
<Error content={message?.error?.content ?? message.content} on:clear={clearResponseError} />
857884
{/if}
858885

859886
{#if (message?.sources || message?.citations) && (model?.info?.meta?.capabilities?.citations ?? true)}

0 commit comments

Comments
 (0)