Skip to content

Commit

Permalink
Improve error handling when posting new messages (#892)
Browse files Browse the repository at this point in the history
* send an error or if no text was written

* fix loading indicator

* fix lastIsError code
  • Loading branch information
nsarrazin committed Mar 1, 2024
1 parent 7a3c71d commit 0f7a55d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/chat/ChatMessage.svelte
Expand Up @@ -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({
Expand Down
7 changes: 5 additions & 2 deletions src/lib/components/chat/ChatWindow.svelte
Expand Up @@ -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));
Expand Down Expand Up @@ -242,7 +245,7 @@
on:click={() => {
if (lastMessage && lastMessage.ancestors) {
dispatch("retry", {
id: lastMessage.ancestors[lastMessage.ancestors.length - 1],
id: lastMessage.id,
});
}
}}
Expand Down
9 changes: 9 additions & 0 deletions src/routes/conversation/[id]/+server.ts
Expand Up @@ -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(
Expand Down

0 comments on commit 0f7a55d

Please sign in to comment.