Spaces:
Runtime error
Runtime error
ability to abort non-streaming messages too
Browse files44 unmodified lines4546474849505140 unmodified lines929394959697989910010110210310410510610730 unmodified lines1381391401411421431442 unmodified lines147148149150151138139140152153154155156157158199 unmodified lines35835936034636136236334936436536636736836937037144 unmodified lines let latency = 0; let messageContainer: HTMLDivElement | null = null; let abortController: AbortController | null = null; let waitForNonStreaming = true;
onMount(() => { (async () => {40 unmodified lines conversations = conversations; }
function abort(){ if (streamingMessage && abortController) { abortController.abort(); abortController = null; } loading = false; streamingMessage = null; waitForNonStreaming = false; }
async function submit() { if (!hfToken) { showTokenModal = true;30 unmodified lines abortController ); } else { waitForNonStreaming = true; const newMessage = await handleNonStreamingResponse( hf, currentConversation.model,2 unmodified lines currentConversation.config.maxTokens, currentConversation.config.jsonMode ); // check if the user did not abort the request if(waitForNonStreaming){ currentConversation.messages = [...currentConversation.messages, newMessage]; conversations = conversations; scrollToBottom(); currentConversation.messages = [...currentConversation.messages, newMessage]; conversations = conversations; scrollToBottom(); } } } catch (error) { if (error.name !== 'AbortError') {199 unmodified lines <button on:click={() => { viewCode = false; submit(); loading ? abort() : submit(); }} type="button" disabled={loading} 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" > {#if loading} <div class="flex flex-none items-center gap-[3px]"> <span class="mr-2">Abort</span> <div class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-100" style="animation-delay: 0.25s;"src/lib/components/Playground/Playground.svelte+20-5