Skip to content

Commit 6bb767e

Browse files
committed
"stop" btn for streaming messages
1 parent 29443e4 commit 6bb767e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/lib/components/InferencePlayground/InferencePlayground.svelte

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
}
8686
(document.activeElement as HTMLElement).blur();
8787
loading = true;
88-
let streamingMsgAdded = false;
8988
9089
try {
9190
const startTime = performance.now();
@@ -94,7 +93,6 @@
9493
if (conversation.streaming) {
9594
const streamingMessage = { role: "assistant", content: "" };
9695
conversation.messages = [...conversation.messages, streamingMessage];
97-
streamingMsgAdded = true;
9896
abortController = new AbortController();
9997
10098
await handleStreamingResponse(
@@ -125,9 +123,6 @@
125123
const endTime = performance.now();
126124
latency = Math.round(endTime - startTime);
127125
} catch (error) {
128-
if (streamingMsgAdded) {
129-
conversation.messages = conversation.messages.slice(0, -1);
130-
}
131126
if (error instanceof Error) {
132127
if (error.message.includes("token seems invalid")) {
133128
hfToken = "";
@@ -209,7 +204,9 @@
209204
</div>
210205
</div>
211206
<div class="relative divide-y divide-gray-200 dark:divide-gray-800" on:keydown={onKeydown}>
212-
<div class="flex h-[calc(100dvh-5rem-120px)] md:h-[calc(100dvh-5rem)] divide-x divide-gray-200 *:w-full dark:divide-gray-800 pt-3">
207+
<div
208+
class="flex h-[calc(100dvh-5rem-120px)] divide-x divide-gray-200 pt-3 *:w-full md:h-[calc(100dvh-5rem)] dark:divide-gray-800"
209+
>
213210
<Conversation
214211
{loading}
215212
{conversation}
@@ -288,7 +285,13 @@
288285
>
289286
{#if loading}
290287
<div class="flex flex-none items-center gap-[3px]">
291-
<span class="mr-2">Cancel</span>
288+
<span class="mr-2">
289+
{#if conversation.streaming}
290+
Stop
291+
{:else}
292+
Cancel
293+
{/if}
294+
</span>
292295
<div
293296
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-100"
294297
style="animation-delay: 0.25s;"

src/lib/components/InferencePlayground/InferencePlaygroundMessage.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
dispatch("delete");
2828
}}
2929
type="button"
30-
class="mt-1.5 sm:hidden size-8 rounded-lg border border-gray-200 bg-white text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-100 group-hover/message:block dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
30+
class="mt-1.5 size-8 rounded-lg border border-gray-200 bg-white text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-100 group-hover/message:block sm:hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
3131
>✕</button
3232
>
3333
</div>

0 commit comments

Comments
 (0)