Spaces:
Sleeping
Sleeping
Improve the run button and behaviour (#4)
Browse files44 unmodified lines4546474849505122 unmodified lines74757676777879808182837778794 unmodified lines8485868788899091929394959697989930 unmodified lines1301311321331341351361372 unmodified lines14014114214314413813914014514614714814915015110 unmodified lines16216316415716516616716852 unmodified lines221222223224225226227228124 unmodified lines35335435534635635735834935035936036136236336436536610 unmodified lines37737837937038038138238344 unmodified lines let latency = 0; let messageContainer: HTMLDivElement | null = null; let abortController: AbortController | null = null; let waitForNonStreaming = true;
onMount(() => { (async () => {22 unmodified lines }
function deleteMessage(i: number) { if (i === currentConversation.messages.length - 1 && streamingMessage) { if (abortController) { abortController.abort(); abortController = null; } loading = false; streamingMessage = null; } currentConversation.messages = currentConversation.messages.filter((_, j) => j !== i); conversations = conversations; }4 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 { streamingMessage = null; 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') {10 unmodified lines }
function onKeydown(event: KeyboardEvent) { if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { if (!event.shiftKey && event.key === 'Enter') { submit(); } }52 unmodified lines {#each conversations as conversation, index} <div class="flex max-h-[calc(100dvh-5.8rem)] flex-col overflow-y-auto overflow-x-hidden @container" class:pointer-events-none={loading} class:animate-pulse={loading && !streamingMessage} bind:this={messageContainer} > {#if conversations.length > 1}124 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" class="flex h-[39px] w-24 items-center justify-center gap-2 rounded-lg px-5 py-2.5 text-sm font-medium text-white focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:focus:ring-gray-700 {loading ? 'bg-red-900 hover:bg-red-800 dark:bg-red-600 dark:hover:bg-red-700' : 'bg-black hover:bg-gray-900 dark:bg-blue-600 dark:hover:bg-blue-700'}" > {#if loading} <div class="flex flex-none items-center gap-[3px]"> <span class="mr-2">Cancel</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;"10 unmodified lines {:else} Run <span class="inline-flex gap-0.5 rounded border border-white/20 bg-white/10 px-0.5 text-xs text-white/70" >⌘<span class="translate-y-px">↵</span></span >↵</span > {/if} </button>src/lib/components/Playground/Playground.svelte+26-16