From 0f7a55d679e8aeb3dffe5bd3e6d9efa7ffd66a31 Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Fri, 1 Mar 2024 11:47:04 +0100 Subject: [PATCH] Improve error handling when posting new messages (#892) * send an error or if no text was written * fix loading indicator * fix lastIsError code --- src/lib/components/chat/ChatMessage.svelte | 2 +- src/lib/components/chat/ChatWindow.svelte | 7 +++++-- src/routes/conversation/[id]/+server.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/components/chat/ChatMessage.svelte b/src/lib/components/chat/ChatMessage.svelte index ff03bbf7a0..6bbffb8f14 100644 --- a/src/lib/components/chat/ChatMessage.svelte +++ b/src/lib/components/chat/ChatMessage.svelte @@ -106,7 +106,7 @@ clearTimeout(pendingTimeout); // Add loading animation to the last message if update takes more than 600ms - if ((loading && isLast) || emptyLoad) { + if (isLast && loading && emptyLoad) { pendingTimeout = setTimeout(() => { if (contentEl) { loadingEl = new IconLoading({ diff --git a/src/lib/components/chat/ChatWindow.svelte b/src/lib/components/chat/ChatWindow.svelte index 130d7c8da1..3f899187f9 100644 --- a/src/lib/components/chat/ChatWindow.svelte +++ b/src/lib/components/chat/ChatWindow.svelte @@ -86,7 +86,10 @@ const convTreeStore = useConvTreeStore(); $: lastMessage = browser && (messages.find((m) => m.id == $convTreeStore.leaf) as Message); - $: lastIsError = lastMessage && lastMessage.from === "user" && !loading; + $: lastIsError = + lastMessage && + ((lastMessage.from === "user" && !loading) || + lastMessage.updates?.findIndex((u) => u.type === "status" && u.status === "error") !== -1); $: sources = files.map((file) => file2base64(file)); @@ -242,7 +245,7 @@ on:click={() => { if (lastMessage && lastMessage.ancestors) { dispatch("retry", { - id: lastMessage.ancestors[lastMessage.ancestors.length - 1], + id: lastMessage.id, }); } }} diff --git a/src/routes/conversation/[id]/+server.ts b/src/routes/conversation/[id]/+server.ts index a13948f5bd..7aeda860c8 100644 --- a/src/routes/conversation/[id]/+server.ts +++ b/src/routes/conversation/[id]/+server.ts @@ -377,6 +377,15 @@ export async function POST({ request, locals, params, getClientAddress }) { } } catch (e) { update({ type: "status", status: "error", message: (e as Error).message }); + } finally { + // check if no output was generated + if (messageToWriteTo.content === previousText) { + update({ + type: "status", + status: "error", + message: "No output was generated. Something went wrong.", + }); + } } await collections.conversations.updateOne(