Spaces:
Runtime error
Runtime error
interupt
Browse filesFiles changed (2)
9 unmodified lines1011121314151649 unmodified lines666768697071727374757677787 unmodified lines868788899091929394959697989920 unmodified lines1201211221231241251269 unmodified lines1361371381221391401411421439 unmodified lines15315415515613815715815916016116216316416516616770 unmodified lines2382392402412422432449 unmodified lines import PlaygroundOptions from '$lib/components/Playground/PlaygroundOptions.svelte'; import PlaygroundTokenModal from './PlaygroundTokenModal.svelte'; import PlaygroundModelSelector from './PlaygroundModelSelector.svelte'; import { onDestroy } from 'svelte';
const compatibleModels: string[] = [ '01-ai/Yi-1.5-34B-Chat',49 unmodified lines let tokens = 0; let latency = 0; let messageContainer: HTMLDivElement | null = null; let abortController: AbortController | null = null;
onDestroy(() => { if (abortController) { abortController.abort(); } });
function addMessage() { currentConversation.messages = [7 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; }20 unmodified lines if (currentConversation.config.streaming) { streamingMessage = { role: 'assistant', content: '' }; currentConversation.messages = [...currentConversation.messages, streamingMessage]; abortController = new AbortController();
await handleStreamingResponse( hf,9 unmodified lines conversations = conversations; scrollToBottom(); } } }, abortController ); } else { const newMessage = await handleNonStreamingResponse(9 unmodified lines scrollToBottom(); } } catch (error) { if (error.name !== 'AbortError') { alert('error: ' + (error as Error).message); alert('error: ' + (error as Error).message); } } finally { const endTime = performance.now(); latency = Math.round(endTime - startTime); loading = false; streamingMessage = null; abortController = null; scrollToBottom(); } }70 unmodified lines <button class="flex px-6 py-6 hover:bg-gray-50 dark:hover:bg-gray-800/50" on:click={addMessage} disabled={loading} > <div class="flex items-center gap-2 !p-0 text-sm font-semibold"> <svg19 unmodified lines20212223232425262726272829303132333435282930313233343536373839404142434445464719 unmodified lines temperature: number, maxTokens: number, jsonMode: boolean, onChunk: (content: string) => void onChunk: (content: string) => void, abortController: AbortController): Promise<void> { let out = ''; try { for await (const chunk of hf.chatCompletionStream({ model: model, messages: messages, temperature: temperature, max_tokens: maxTokens, json_mode: jsonMode })) { if (chunk.choices && chunk.choices.length > 0 && chunk.choices[0]?.delta?.content) { out += chunk.choices[0].delta.content; onChunk(out); for await (const chunk of hf.chatCompletionStream({ model: model, messages: messages, temperature: temperature, max_tokens: maxTokens, json_mode: jsonMode }, { signal: abortController.signal })) { if (chunk.choices && chunk.choices.length > 0 && chunk.choices[0]?.delta?.content) { out += chunk.choices[0].delta.content; onChunk(out); } } } catch (error) { if (error.name === 'AbortError') { console.log('Stream aborted'); } else { throw error; } }}src/lib/components/Playground/Playground.svelte+24-2
src/lib/components/Playground/playgroundUtils.ts+20-11