ability to abort non-streaming messages too
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
@@ -45,6 +45,7 @@
|
|
45 |
let latency = 0;
|
46 |
let messageContainer: HTMLDivElement | null = null;
|
47 |
let abortController: AbortController | null = null;
|
|
|
48 |
|
49 |
onMount(() => {
|
50 |
(async () => {
|
@@ -91,6 +92,16 @@
|
|
91 |
conversations = conversations;
|
92 |
}
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
async function submit() {
|
95 |
if (!hfToken) {
|
96 |
showTokenModal = true;
|
@@ -127,6 +138,7 @@
|
|
127 |
abortController
|
128 |
);
|
129 |
} else {
|
|
|
130 |
const newMessage = await handleNonStreamingResponse(
|
131 |
hf,
|
132 |
currentConversation.model,
|
@@ -135,9 +147,12 @@
|
|
135 |
currentConversation.config.maxTokens,
|
136 |
currentConversation.config.jsonMode
|
137 |
);
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
141 |
}
|
142 |
} catch (error) {
|
143 |
if (error.name !== 'AbortError') {
|
@@ -343,14 +358,14 @@
|
|
343 |
<button
|
344 |
on:click={() => {
|
345 |
viewCode = false;
|
346 |
-
submit();
|
347 |
}}
|
348 |
type="button"
|
349 |
-
disabled={loading}
|
350 |
class="flex h-[39px] w-24 items-center justify-center gap-2 rounded-lg bg-black px-5 py-2.5 text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-gray-700"
|
351 |
>
|
352 |
{#if loading}
|
353 |
<div class="flex flex-none items-center gap-[3px]">
|
|
|
354 |
<div
|
355 |
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-100"
|
356 |
style="animation-delay: 0.25s;"
|
|
|
45 |
let latency = 0;
|
46 |
let messageContainer: HTMLDivElement | null = null;
|
47 |
let abortController: AbortController | null = null;
|
48 |
+
let waitForNonStreaming = true;
|
49 |
|
50 |
onMount(() => {
|
51 |
(async () => {
|
|
|
92 |
conversations = conversations;
|
93 |
}
|
94 |
|
95 |
+
function abort(){
|
96 |
+
if (streamingMessage && abortController) {
|
97 |
+
abortController.abort();
|
98 |
+
abortController = null;
|
99 |
+
}
|
100 |
+
loading = false;
|
101 |
+
streamingMessage = null;
|
102 |
+
waitForNonStreaming = false;
|
103 |
+
}
|
104 |
+
|
105 |
async function submit() {
|
106 |
if (!hfToken) {
|
107 |
showTokenModal = true;
|
|
|
138 |
abortController
|
139 |
);
|
140 |
} else {
|
141 |
+
waitForNonStreaming = true;
|
142 |
const newMessage = await handleNonStreamingResponse(
|
143 |
hf,
|
144 |
currentConversation.model,
|
|
|
147 |
currentConversation.config.maxTokens,
|
148 |
currentConversation.config.jsonMode
|
149 |
);
|
150 |
+
// check if the user did not abort the request
|
151 |
+
if(waitForNonStreaming){
|
152 |
+
currentConversation.messages = [...currentConversation.messages, newMessage];
|
153 |
+
conversations = conversations;
|
154 |
+
scrollToBottom();
|
155 |
+
}
|
156 |
}
|
157 |
} catch (error) {
|
158 |
if (error.name !== 'AbortError') {
|
|
|
358 |
<button
|
359 |
on:click={() => {
|
360 |
viewCode = false;
|
361 |
+
loading ? abort() : submit();
|
362 |
}}
|
363 |
type="button"
|
|
|
364 |
class="flex h-[39px] w-24 items-center justify-center gap-2 rounded-lg bg-black px-5 py-2.5 text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-gray-700"
|
365 |
>
|
366 |
{#if loading}
|
367 |
<div class="flex flex-none items-center gap-[3px]">
|
368 |
+
<span class="mr-2">Abort</span>
|
369 |
<div
|
370 |
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-100"
|
371 |
style="animation-delay: 0.25s;"
|