nsarrazin HF staff commited on
Commit
0f7a55d
1 Parent(s): 7a3c71d

Improve error handling when posting new messages (#892)

Browse files

* send an error or if no text was written

* fix loading indicator

* fix lastIsError code

src/lib/components/chat/ChatMessage.svelte CHANGED
@@ -106,7 +106,7 @@
106
  clearTimeout(pendingTimeout);
107
 
108
  // Add loading animation to the last message if update takes more than 600ms
109
- if ((loading && isLast) || emptyLoad) {
110
  pendingTimeout = setTimeout(() => {
111
  if (contentEl) {
112
  loadingEl = new IconLoading({
 
106
  clearTimeout(pendingTimeout);
107
 
108
  // Add loading animation to the last message if update takes more than 600ms
109
+ if (isLast && loading && emptyLoad) {
110
  pendingTimeout = setTimeout(() => {
111
  if (contentEl) {
112
  loadingEl = new IconLoading({
src/lib/components/chat/ChatWindow.svelte CHANGED
@@ -86,7 +86,10 @@
86
  const convTreeStore = useConvTreeStore();
87
 
88
  $: lastMessage = browser && (messages.find((m) => m.id == $convTreeStore.leaf) as Message);
89
- $: lastIsError = lastMessage && lastMessage.from === "user" && !loading;
 
 
 
90
 
91
  $: sources = files.map((file) => file2base64(file));
92
 
@@ -242,7 +245,7 @@
242
  on:click={() => {
243
  if (lastMessage && lastMessage.ancestors) {
244
  dispatch("retry", {
245
- id: lastMessage.ancestors[lastMessage.ancestors.length - 1],
246
  });
247
  }
248
  }}
 
86
  const convTreeStore = useConvTreeStore();
87
 
88
  $: lastMessage = browser && (messages.find((m) => m.id == $convTreeStore.leaf) as Message);
89
+ $: lastIsError =
90
+ lastMessage &&
91
+ ((lastMessage.from === "user" && !loading) ||
92
+ lastMessage.updates?.findIndex((u) => u.type === "status" && u.status === "error") !== -1);
93
 
94
  $: sources = files.map((file) => file2base64(file));
95
 
 
245
  on:click={() => {
246
  if (lastMessage && lastMessage.ancestors) {
247
  dispatch("retry", {
248
+ id: lastMessage.id,
249
  });
250
  }
251
  }}
src/routes/conversation/[id]/+server.ts CHANGED
@@ -377,6 +377,15 @@ export async function POST({ request, locals, params, getClientAddress }) {
377
  }
378
  } catch (e) {
379
  update({ type: "status", status: "error", message: (e as Error).message });
 
 
 
 
 
 
 
 
 
380
  }
381
 
382
  await collections.conversations.updateOne(
 
377
  }
378
  } catch (e) {
379
  update({ type: "status", status: "error", message: (e as Error).message });
380
+ } finally {
381
+ // check if no output was generated
382
+ if (messageToWriteTo.content === previousText) {
383
+ update({
384
+ type: "status",
385
+ status: "error",
386
+ message: "No output was generated. Something went wrong.",
387
+ });
388
+ }
389
  }
390
 
391
  await collections.conversations.updateOne(