Spaces:
Runtime error
Runtime error
interupt
Browse filesFiles changed (2)
9 unmodified lines10111213141549 unmodified lines6566676869707 unmodified lines78798081828320 unmodified lines1041051061071081099 unmodified lines1191201211221231241259 unmodified lines13513613713813914014114214314414514670 unmodified lines2172182192202212229 unmodified linesimport PlaygroundOptions from '$lib/components/Playground/PlaygroundOptions.svelte';import PlaygroundTokenModal from './PlaygroundTokenModal.svelte';import PlaygroundModelSelector from './PlaygroundModelSelector.svelte';const compatibleModels: string[] = ['01-ai/Yi-1.5-34B-Chat',49 unmodified lineslet tokens = 0;let latency = 0;let messageContainer: HTMLDivElement | null = null;function addMessage() {currentConversation.messages = [7 unmodified lines}function deleteMessage(i: number) {currentConversation.messages = currentConversation.messages.filter((_, j) => j !== i);conversations = conversations;}20 unmodified linesif (currentConversation.config.streaming) {streamingMessage = { role: 'assistant', content: '' };currentConversation.messages = [...currentConversation.messages, streamingMessage];await handleStreamingResponse(hf,9 unmodified linesconversations = conversations;scrollToBottom();}});} else {const newMessage = await handleNonStreamingResponse(9 unmodified linesscrollToBottom();}} catch (error) {alert('error: ' + (error as Error).message);} finally {const endTime = performance.now();latency = Math.round(endTime - startTime);loading = false;streamingMessage = null;scrollToBottom();}}70 unmodified lines<buttonclass="flex px-6 py-6 hover:bg-gray-50 dark:hover:bg-gray-800/50"on:click={addMessage}><div class="flex items-center gap-2 !p-0 text-sm font-semibold"><svg9 unmodified lines1011121314151649 unmodified lines666768697071727374757677787 unmodified lines868788899091929394959697989920 unmodified lines1201211221231241251269 unmodified lines1361371381391401411421439 unmodified lines15315415515615715815916016116216316416516616770 unmodified lines2382392402412422432449 unmodified linesimport 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 lineslet 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 linesif (currentConversation.config.streaming) {streamingMessage = { role: 'assistant', content: '' };currentConversation.messages = [...currentConversation.messages, streamingMessage];abortController = new AbortController();await handleStreamingResponse(hf,9 unmodified linesconversations = conversations;scrollToBottom();}},abortController);} else {const newMessage = await handleNonStreamingResponse(9 unmodified linesscrollToBottom();}} catch (error) {if (error.name !== 'AbortError') {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<buttonclass="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"><svg
19 unmodified lines2021222324252627282930313233343536373819 unmodified linestemperature: number,maxTokens: number,jsonMode: boolean,onChunk: (content: string) => void): Promise<void> {let out = '';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);}}}19 unmodified lines2021222324252627282930313233343536373839404142434445464719 unmodified linestemperature: number,maxTokens: number,jsonMode: boolean,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}, { 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