Spaces:
Runtime error
Runtime error
code
Browse filesFiles changed (3)
1 unmodified line23456720 unmodified lines282930313233341 unmodified line363738394041424344454698 unmodified lines1451461471481491501517 unmodified lines15916016116216316416516616716816917017117217317417517617716 unmodified lines1941951961971981992002011 unmodified lineimport { HfInference } from '@huggingface/inference';import { queryParam, ssp } from 'sveltekit-search-params';import PlaygroundMessage from '$lib/components/Playground/PlaygroundMessage.svelte';import PlaygroundOptions from '$lib/components/Playground/PlaygroundOptions.svelte';20 unmodified lines'mistralai/Mistral-7B-Instruct-v0.3'];let hfToken: string | null = '';const currentModel = queryParam('model', ssp.string(compatibleModels[0]));const temperature = queryParam('temperature', ssp.number(0.5));const maxTokens = queryParam('max_tokens', ssp.number(2048));1 unmodified lineconst jsonMode = queryParam('json_mode', ssp.boolean(false));$: systemMessage = { role: 'system', content: $systemMessageParam };$: messages = $messagesParam;let messageContainer: HTMLDivElement | null = null;let loading = false;let streamingMessage: Message | null = null;let latency = 0;function addMessage() {$messagesParam = [98 unmodified lines<svelte:window on:keydown={onKeydown} /><divclass="grid h-dvh max-h-dvh divide-gray-200 overflow-hidden max-md:grid-cols-1 max-md:divide-y md:grid-cols-[260px,1fr,260px] md:divide-x dark:divide-gray-800 dark:bg-gray-900 dark:text-gray-300"><div class="relative flex flex-col overflow-y-auto px-5 pb-24 pt-7"><div class="pb-2 text-sm font-semibold">SYSTEM</div>7 unmodified lines</div><div class="relative divide-y divide-gray-200 dark:divide-gray-800"><divclass="flex max-h-[calc(100dvh-5rem)] flex-col divide-y divide-gray-200 overflow-y-auto dark:divide-gray-800"bind:this={messageContainer}>{#each messages as message, i}<PlaygroundMessage {message} on:delete={() => deleteMessage(i)} />{/each}<buttonclass="flex px-6 py-6 hover:bg-gray-50 dark:hover:bg-gray-800/50"on:click={addMessage}><div class="!p-0 text-sm font-semibold">Add message</div></button></div><div16 unmodified lines</div><buttontype="button"class="rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm 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 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">View Code</button><buttonon:click={submit}1 unmodified line234567820 unmodified lines2930313233341 unmodified line3637383940414243444546474898 unmodified lines1471481491501511521537 unmodified lines16116216316416516616716816917017117217317417517617717817918018118218316 unmodified lines2002012022032042052062072081 unmodified lineimport { HfInference } from '@huggingface/inference';import { queryParam, ssp } from 'sveltekit-search-params';import PlaygroundCode from './PlaygroundCode.svelte';import PlaygroundMessage from '$lib/components/Playground/PlaygroundMessage.svelte';import PlaygroundOptions from '$lib/components/Playground/PlaygroundOptions.svelte';20 unmodified lines'mistralai/Mistral-7B-Instruct-v0.3'];const currentModel = queryParam('model', ssp.string(compatibleModels[0]));const temperature = queryParam('temperature', ssp.number(0.5));const maxTokens = queryParam('max_tokens', ssp.number(2048));1 unmodified lineconst jsonMode = queryParam('json_mode', ssp.boolean(false));$: systemMessage = { role: 'system', content: $systemMessageParam };$: messages = $messagesParam;let hfToken: string | null = '';let viewCode = false;let loading = false;let streamingMessage: Message | null = null;let latency = 0;let messageContainer: HTMLDivElement | null = null;function addMessage() {$messagesParam = [98 unmodified lines<svelte:window on:keydown={onKeydown} /><divclass="w-dvh maxdivide-gray-200 grid h-dvh overflow-hidden max-md:grid-cols-1 max-md:divide-y md:grid-cols-[260px,minmax(0,1fr),260px] md:divide-x dark:divide-gray-800 dark:bg-gray-900 dark:text-gray-300"><div class="relative flex flex-col overflow-y-auto px-5 pb-24 pt-7"><div class="pb-2 text-sm font-semibold">SYSTEM</div>7 unmodified lines</div><div class="relative divide-y divide-gray-200 dark:divide-gray-800"><divclass="flex max-h-[calc(100dvh-5rem)] flex-col divide-y divide-gray-200 overflow-y-auto overflow-x-hidden dark:divide-gray-800"bind:this={messageContainer}>{#if !viewCode}{#each messages as message, i}<PlaygroundMessage {message} on:delete={() => deleteMessage(i)} />{/each}<buttonclass="flex px-6 py-6 hover:bg-gray-50 dark:hover:bg-gray-800/50"on:click={addMessage}><div class="!p-0 text-sm font-semibold">Add message</div></button>{:else}<PlaygroundCode />{/if}</div><div16 unmodified lines</div><buttontype="button"on:click={() => (viewCode = !viewCode)}class="rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm 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 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">{!viewCode ? 'View Code' : 'Hide Code'}</button><buttonon:click={submit}
12345678910111213141516171819202122232425262728293031323334<script> const nonStreaming = `await hf.chatCompletion({ model: "mistrali/Mistral-7B-Instruct-v0.2", messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }], max_tokens: 500, temperature: 0.1, seed: 0,});`;
const streaming = `let out = "";
for await (const chunk of hf.chatCompletionStream({ model: "mistrali/Mistral-7B-Instruct-v0.2", messages: [ { role: "user", content: "Complete the equation 1+1= ,just the answer" }, ], max_tokens: 500, temperature: 0.1, seed: 0,})) { if (chunk.choices && chunk.choices.length > 0) { out += chunk.choices[0].delta.content; } }`;</script>
<div class="overflow-hidden p-8"> <h2 class="mb-4 font-bold">Non-streaming API</h2> <pre class="overflow-x-auto rounded-md bg-gray-800 p-4 text-sm text-white">{@html nonStreaming}</pre>
<h2 class="my-4 font-bold">Streaming API</h2> <pre class="overflow-x-auto rounded-md bg-gray-800 p-4 text-sm text-white">{streaming}</pre></div>6 unmodified lines789101112135 unmodified lines192021222324256 unmodified lines</script><div><form class="mx-auto max-w-sm"><label for="countries" class="mb-2 block text-sm font-medium text-gray-900 dark:text-white">Model</label>5 unmodified lines<option value={model}>{model}</option>{/each}</select></form></div><div><div class="flex items-center justify-between">6 unmodified lines789101112135 unmodified lines192021222324256 unmodified lines</script><div><div><label for="countries" class="mb-2 block text-sm font-medium text-gray-900 dark:text-white">Model</label>5 unmodified lines<option value={model}>{model}</option>{/each}</select></div></div><div><div class="flex items-center justify-between">
src/lib/components/Playground/Playground.svelte+22-15
src/lib/components/Playground/PlaygroundCode.svelteAdded+34
src/lib/components/Playground/PlaygroundOptions.svelte+2-2