Spaces:
Sleeping
Sleeping
handle error
Browse files
src/lib/chat/triggerAiCall.ts
CHANGED
|
@@ -57,7 +57,7 @@ export async function triggerAiCall(ctx: TriggerAiCallContext): Promise<void> {
|
|
| 57 |
const errorMessages: string[] = [];
|
| 58 |
|
| 59 |
const results = await Promise.all(
|
| 60 |
-
newNodes.map(async (node
|
| 61 |
const model = node?.data?.selectedModel as string;
|
| 62 |
if (!model) return null;
|
| 63 |
try {
|
|
@@ -136,8 +136,8 @@ export async function triggerAiCall(ctx: TriggerAiCallContext): Promise<void> {
|
|
| 136 |
} catch (error) {
|
| 137 |
const msg = error instanceof Error ? error.message : 'An unknown error occurred';
|
| 138 |
failedNodeIds.add(node.id);
|
| 139 |
-
failedModelIds.add(model);
|
| 140 |
-
errorMessages.push(
|
| 141 |
return null;
|
| 142 |
} finally {
|
| 143 |
onLoadingChange(false);
|
|
@@ -155,12 +155,12 @@ export async function triggerAiCall(ctx: TriggerAiCallContext): Promise<void> {
|
|
| 155 |
{
|
| 156 |
...nodeData,
|
| 157 |
messages: newNodes.length === failedNodeIds.size ? messages.slice(0, -1) : messages,
|
| 158 |
-
prompt: newNodes.length === failedNodeIds.size ? prompt : ''
|
| 159 |
-
selectedModels: selectedModels.filter((m) => !failedModelIds.has(m))
|
| 160 |
} as Record<string, unknown>,
|
| 161 |
{ replace: true }
|
| 162 |
);
|
| 163 |
-
|
| 164 |
}
|
| 165 |
|
| 166 |
const validResults = results.filter(
|
|
|
|
| 57 |
const errorMessages: string[] = [];
|
| 58 |
|
| 59 |
const results = await Promise.all(
|
| 60 |
+
newNodes.map(async (node) => {
|
| 61 |
const model = node?.data?.selectedModel as string;
|
| 62 |
if (!model) return null;
|
| 63 |
try {
|
|
|
|
| 136 |
} catch (error) {
|
| 137 |
const msg = error instanceof Error ? error.message : 'An unknown error occurred';
|
| 138 |
failedNodeIds.add(node.id);
|
| 139 |
+
// failedModelIds.add(model);
|
| 140 |
+
errorMessages.push(msg);
|
| 141 |
return null;
|
| 142 |
} finally {
|
| 143 |
onLoadingChange(false);
|
|
|
|
| 155 |
{
|
| 156 |
...nodeData,
|
| 157 |
messages: newNodes.length === failedNodeIds.size ? messages.slice(0, -1) : messages,
|
| 158 |
+
prompt: newNodes.length === failedNodeIds.size ? prompt : ''
|
| 159 |
+
// selectedModels: selectedModels.filter((m) => !failedModelIds.has(m))
|
| 160 |
} as Record<string, unknown>,
|
| 161 |
{ replace: true }
|
| 162 |
);
|
| 163 |
+
errorMessages.forEach((msg) => onError(msg));
|
| 164 |
}
|
| 165 |
|
| 166 |
const validResults = results.filter(
|
src/lib/components/chat/User.svelte
CHANGED
|
@@ -45,7 +45,7 @@
|
|
| 45 |
|
| 46 |
let prompt = $state.raw<string>((nodeData.current?.data.prompt as string) ?? '');
|
| 47 |
let loading = $state.raw<boolean>(false);
|
| 48 |
-
let errorMessage = $state.raw<string>(
|
| 49 |
|
| 50 |
const randomSuggestions = SUGGESTIONS_PROMPT.sort(() => Math.random() - 0.5).slice(
|
| 51 |
0,
|
|
@@ -70,7 +70,7 @@
|
|
| 70 |
signinModalState.open = true;
|
| 71 |
return;
|
| 72 |
}
|
| 73 |
-
errorMessage
|
| 74 |
const newNodes: Node[] = [];
|
| 75 |
const newEdges: Edge[] = [];
|
| 76 |
const newMessages = [...messages, { role: 'user', content: prompt }] as ChatMessage[];
|
|
@@ -125,7 +125,9 @@
|
|
| 125 |
updateNodes,
|
| 126 |
updateEdges,
|
| 127 |
onLoadingChange: (v) => (loading = v),
|
| 128 |
-
onError: (msg) =>
|
|
|
|
|
|
|
| 129 |
});
|
| 130 |
}
|
| 131 |
|
|
|
|
| 45 |
|
| 46 |
let prompt = $state.raw<string>((nodeData.current?.data.prompt as string) ?? '');
|
| 47 |
let loading = $state.raw<boolean>(false);
|
| 48 |
+
let errorMessage = $state.raw<Set<string>>(new Set());
|
| 49 |
|
| 50 |
const randomSuggestions = SUGGESTIONS_PROMPT.sort(() => Math.random() - 0.5).slice(
|
| 51 |
0,
|
|
|
|
| 70 |
signinModalState.open = true;
|
| 71 |
return;
|
| 72 |
}
|
| 73 |
+
errorMessage.clear();
|
| 74 |
const newNodes: Node[] = [];
|
| 75 |
const newEdges: Edge[] = [];
|
| 76 |
const newMessages = [...messages, { role: 'user', content: prompt }] as ChatMessage[];
|
|
|
|
| 125 |
updateNodes,
|
| 126 |
updateEdges,
|
| 127 |
onLoadingChange: (v) => (loading = v),
|
| 128 |
+
onError: (msg) => {
|
| 129 |
+
errorMessage = new Set([...errorMessage, msg]);
|
| 130 |
+
}
|
| 131 |
});
|
| 132 |
}
|
| 133 |
|
src/lib/components/error/Error.svelte
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
let showAlert = $state(false);
|
| 11 |
|
| 12 |
$effect(() => {
|
| 13 |
-
if (error) {
|
| 14 |
showAlert = true;
|
| 15 |
// const timer = setTimeout(() => (showAlert = false), 6_000);
|
| 16 |
// return () => clearTimeout(timer);
|
|
@@ -24,14 +24,14 @@
|
|
| 24 |
<div
|
| 25 |
class="mb-2.5"
|
| 26 |
transition:scale={{ duration: 250, easing: backOut, start: 1.02 }}
|
| 27 |
-
onoutroend={() => (error =
|
| 28 |
>
|
| 29 |
<div
|
| 30 |
class="relative inline-flex w-fit items-center gap-1.5 rounded-t-2xl bg-rose-500/10 pt-3 pr-5 pl-4 text-[11px] font-semibold text-rose-600 uppercase"
|
| 31 |
>
|
| 32 |
<button
|
| 33 |
class="flex size-3 -translate-y-[0.5px] cursor-pointer items-center justify-center rounded-full bg-rose-600 text-white hover:bg-rose-600/80"
|
| 34 |
-
onclick={() => (error =
|
| 35 |
>
|
| 36 |
<X class="size-2.5" />
|
| 37 |
</button>
|
|
@@ -44,34 +44,36 @@
|
|
| 44 |
<div
|
| 45 |
class="-translate-y-[3px] rounded-r-2xl rounded-b-xl bg-rose-500/10 px-4 py-3 text-xs whitespace-pre-line text-rose-500"
|
| 46 |
>
|
| 47 |
-
{error}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
{:else if error.includes('exceeded your monthly included credits') || error.includes('reached the free monthly usage limit') || error.includes('Credit balance is depleted')}
|
| 57 |
-
<div class="mt-2 flex items-center gap-1">
|
| 58 |
-
<a target="_blank" href="https://huggingface.co/settings/billing">
|
| 59 |
-
<Button variant="outline" size="3xs">Upgrade your plan</Button>
|
| 60 |
</a>
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
</div>
|
| 76 |
</div>
|
| 77 |
{/if}
|
|
|
|
| 10 |
let showAlert = $state(false);
|
| 11 |
|
| 12 |
$effect(() => {
|
| 13 |
+
if (error.size > 0) {
|
| 14 |
showAlert = true;
|
| 15 |
// const timer = setTimeout(() => (showAlert = false), 6_000);
|
| 16 |
// return () => clearTimeout(timer);
|
|
|
|
| 24 |
<div
|
| 25 |
class="mb-2.5"
|
| 26 |
transition:scale={{ duration: 250, easing: backOut, start: 1.02 }}
|
| 27 |
+
onoutroend={() => (error = new Set())}
|
| 28 |
>
|
| 29 |
<div
|
| 30 |
class="relative inline-flex w-fit items-center gap-1.5 rounded-t-2xl bg-rose-500/10 pt-3 pr-5 pl-4 text-[11px] font-semibold text-rose-600 uppercase"
|
| 31 |
>
|
| 32 |
<button
|
| 33 |
class="flex size-3 -translate-y-[0.5px] cursor-pointer items-center justify-center rounded-full bg-rose-600 text-white hover:bg-rose-600/80"
|
| 34 |
+
onclick={() => (error = new Set())}
|
| 35 |
>
|
| 36 |
<X class="size-2.5" />
|
| 37 |
</button>
|
|
|
|
| 44 |
<div
|
| 45 |
class="-translate-y-[3px] rounded-r-2xl rounded-b-xl bg-rose-500/10 px-4 py-3 text-xs whitespace-pre-line text-rose-500"
|
| 46 |
>
|
| 47 |
+
{#each error as err (err)}
|
| 48 |
+
{err}
|
| 49 |
+
{#if err.includes('is not supported by any provider')}
|
| 50 |
+
<a
|
| 51 |
+
target="_blank"
|
| 52 |
+
href="https://huggingface.co/settings/inference-providers/settings"
|
| 53 |
+
class="mt-2 block"
|
| 54 |
+
>
|
| 55 |
+
<Button variant="outline" size="3xs">View supported providers</Button>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
</a>
|
| 57 |
+
{:else if err.includes('exceeded your monthly included credits') || err.includes('reached the free monthly usage limit') || err.includes('Credit balance is depleted')}
|
| 58 |
+
<div class="mt-2 flex items-center gap-1">
|
| 59 |
+
<a target="_blank" href="https://huggingface.co/settings/billing">
|
| 60 |
+
<Button variant="outline" size="3xs">Upgrade your plan</Button>
|
| 61 |
+
</a>
|
| 62 |
+
{#if (authState.user?.orgs?.length ?? 0) > 0}
|
| 63 |
+
<Button variant="outline" size="3xs" onclick={() => (billingModalState.open = true)}
|
| 64 |
+
>Update your billing information</Button
|
| 65 |
+
>
|
| 66 |
+
{/if}
|
| 67 |
+
</div>
|
| 68 |
+
{:else if err.includes('to call Inference Providers on behalf of org')}
|
| 69 |
+
<Button
|
| 70 |
+
variant="outline"
|
| 71 |
+
size="3xs"
|
| 72 |
+
onclick={() => (billingModalState.open = true)}
|
| 73 |
+
class="mt-2 block">Change billing option</Button
|
| 74 |
+
>
|
| 75 |
+
{/if}
|
| 76 |
+
{/each}
|
| 77 |
</div>
|
| 78 |
</div>
|
| 79 |
{/if}
|