Spaces:
Running
Running
update error handling
Browse files
src/lib/components/chat/User.svelte
CHANGED
|
@@ -115,7 +115,7 @@
|
|
| 115 |
}
|
| 116 |
|
| 117 |
async function handleTriggerAiCall(newNodes: Node[]) {
|
| 118 |
-
|
| 119 |
newNodes.map(async (node) => {
|
| 120 |
const model = node?.data?.selectedModel as ChatModel;
|
| 121 |
if (!model) return;
|
|
@@ -216,7 +216,13 @@
|
|
| 216 |
id,
|
| 217 |
{
|
| 218 |
...nodeData.current?.data,
|
| 219 |
-
messages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
},
|
| 221 |
{ replace: true }
|
| 222 |
);
|
|
@@ -228,12 +234,19 @@
|
|
| 228 |
);
|
| 229 |
}
|
| 230 |
errorMessage += `\n${msg}`;
|
|
|
|
| 231 |
} finally {
|
| 232 |
loading = false;
|
| 233 |
}
|
| 234 |
})
|
| 235 |
);
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
const assistantMessage = results.reduce<ChatMessage>(
|
| 238 |
(acc, result) => (result ? { ...acc, ...result } : acc),
|
| 239 |
{ role: 'assistant' }
|
|
@@ -249,7 +262,7 @@
|
|
| 249 |
},
|
| 250 |
data: {
|
| 251 |
role: 'user',
|
| 252 |
-
selectedModels,
|
| 253 |
messages: [...messages, assistantMessage]
|
| 254 |
}
|
| 255 |
};
|
|
|
|
| 115 |
}
|
| 116 |
|
| 117 |
async function handleTriggerAiCall(newNodes: Node[]) {
|
| 118 |
+
let results = await Promise.all(
|
| 119 |
newNodes.map(async (node) => {
|
| 120 |
const model = node?.data?.selectedModel as ChatModel;
|
| 121 |
if (!model) return;
|
|
|
|
| 216 |
id,
|
| 217 |
{
|
| 218 |
...nodeData.current?.data,
|
| 219 |
+
messages,
|
| 220 |
+
selectedModels: selectedModels.map((m) => {
|
| 221 |
+
if (m.id === model.id) {
|
| 222 |
+
return { ...m, isError: true };
|
| 223 |
+
}
|
| 224 |
+
return m;
|
| 225 |
+
})
|
| 226 |
},
|
| 227 |
{ replace: true }
|
| 228 |
);
|
|
|
|
| 234 |
);
|
| 235 |
}
|
| 236 |
errorMessage += `\n${msg}`;
|
| 237 |
+
return null;
|
| 238 |
} finally {
|
| 239 |
loading = false;
|
| 240 |
}
|
| 241 |
})
|
| 242 |
);
|
| 243 |
|
| 244 |
+
results = results.filter((result) => result !== null);
|
| 245 |
+
|
| 246 |
+
if (results.length === 0) {
|
| 247 |
+
return;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
const assistantMessage = results.reduce<ChatMessage>(
|
| 251 |
(acc, result) => (result ? { ...acc, ...result } : acc),
|
| 252 |
{ role: 'assistant' }
|
|
|
|
| 262 |
},
|
| 263 |
data: {
|
| 264 |
role: 'user',
|
| 265 |
+
selectedModels: selectedModels.filter((m) => !m.isError),
|
| 266 |
messages: [...messages, assistantMessage]
|
| 267 |
}
|
| 268 |
};
|
src/lib/components/error/Error.svelte
CHANGED
|
@@ -7,13 +7,12 @@
|
|
| 7 |
|
| 8 |
let { error = $bindable() } = $props();
|
| 9 |
let showAlert = $state(false);
|
| 10 |
-
// be able to close the alert!
|
| 11 |
|
| 12 |
$effect(() => {
|
| 13 |
if (error) {
|
| 14 |
showAlert = true;
|
| 15 |
-
const timer = setTimeout(() => (showAlert = false), 6_000);
|
| 16 |
-
return () => clearTimeout(timer);
|
| 17 |
} else {
|
| 18 |
showAlert = false;
|
| 19 |
}
|
|
|
|
| 7 |
|
| 8 |
let { error = $bindable() } = $props();
|
| 9 |
let showAlert = $state(false);
|
|
|
|
| 10 |
|
| 11 |
$effect(() => {
|
| 12 |
if (error) {
|
| 13 |
showAlert = true;
|
| 14 |
+
// const timer = setTimeout(() => (showAlert = false), 6_000);
|
| 15 |
+
// return () => clearTimeout(timer);
|
| 16 |
} else {
|
| 17 |
showAlert = false;
|
| 18 |
}
|
src/routes/+page.svelte
CHANGED
|
@@ -38,7 +38,7 @@
|
|
| 38 |
data: {
|
| 39 |
isFirstNode: true,
|
| 40 |
showWelcome: true,
|
| 41 |
-
selectedModels: modelsState.models.slice(
|
| 42 |
}
|
| 43 |
}
|
| 44 |
];
|
|
|
|
| 38 |
data: {
|
| 39 |
isFirstNode: true,
|
| 40 |
showWelcome: true,
|
| 41 |
+
selectedModels: modelsState.models.slice(2, 2 + MAX_DEFAULT_MODELS) as ChatModel[]
|
| 42 |
}
|
| 43 |
}
|
| 44 |
];
|