Improve error handling
Browse files
src/lib/components/InferencePlayground/InferencePlayground.svelte
CHANGED
@@ -76,6 +76,7 @@
|
|
76 |
}
|
77 |
(document.activeElement as HTMLElement).blur();
|
78 |
loading = true;
|
|
|
79 |
|
80 |
try {
|
81 |
const startTime = performance.now();
|
@@ -84,6 +85,7 @@
|
|
84 |
if (conversation.streaming) {
|
85 |
const streamingMessage = { role: "assistant", content: "" };
|
86 |
conversation.messages = [...conversation.messages, streamingMessage];
|
|
|
87 |
abortController = new AbortController();
|
88 |
|
89 |
await handleStreamingResponse(
|
@@ -109,6 +111,10 @@
|
|
109 |
const endTime = performance.now();
|
110 |
latency = Math.round(endTime - startTime);
|
111 |
} catch (error) {
|
|
|
|
|
|
|
|
|
112 |
if (error.name !== "AbortError") {
|
113 |
alert("error: " + (error as Error).message);
|
114 |
}
|
@@ -127,7 +133,7 @@
|
|
127 |
function handleTokenSubmit(e: Event) {
|
128 |
const form = e.target as HTMLFormElement;
|
129 |
const formData = new FormData(form);
|
130 |
-
hfToken = (formData.get("hf-token") as string) ?? "";
|
131 |
submit();
|
132 |
showTokenModal = false;
|
133 |
}
|
|
|
76 |
}
|
77 |
(document.activeElement as HTMLElement).blur();
|
78 |
loading = true;
|
79 |
+
let streamingMsgAdded = false;
|
80 |
|
81 |
try {
|
82 |
const startTime = performance.now();
|
|
|
85 |
if (conversation.streaming) {
|
86 |
const streamingMessage = { role: "assistant", content: "" };
|
87 |
conversation.messages = [...conversation.messages, streamingMessage];
|
88 |
+
streamingMsgAdded = true;
|
89 |
abortController = new AbortController();
|
90 |
|
91 |
await handleStreamingResponse(
|
|
|
111 |
const endTime = performance.now();
|
112 |
latency = Math.round(endTime - startTime);
|
113 |
} catch (error) {
|
114 |
+
if (streamingMsgAdded) {
|
115 |
+
conversation.messages = conversation.messages.slice(0, -1);
|
116 |
+
}
|
117 |
+
hfToken = "";
|
118 |
if (error.name !== "AbortError") {
|
119 |
alert("error: " + (error as Error).message);
|
120 |
}
|
|
|
133 |
function handleTokenSubmit(e: Event) {
|
134 |
const form = e.target as HTMLFormElement;
|
135 |
const formData = new FormData(form);
|
136 |
+
hfToken = (formData.get("hf-token") as string).trim() ?? "";
|
137 |
submit();
|
138 |
showTokenModal = false;
|
139 |
}
|