Spaces:
Runtime error
Runtime error
Settings dynamically change (#27)
Browse filesFiles changed (3)
193 unmodified lines194195196197198199200201202203164 unmodified lines368369370367371372373374193 unmodified lines submit(); } }
function changeSelectedModel(modelIdx: number) { conversations[0] = { ...conversations[0], model: models[modelIdx] }; }</script>
<svelte:window on:keydown={onKeydown} />164 unmodified lines > <PlaygroundModelSelector compatibleModels={models} bind:currentModel={conversations[0].model} on:modelIdxChange={(e) => changeSelectedModel(e.detail)} /> <div class="group relative -mt-4 flex h-[26px] w-full items-center justify-center gap-2 rounded-lg bg-black px-5 text-sm 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"24 unmodified lines252627282930312829303132333411 unmodified lines464748494950515213 unmodified lines666768696970717216 unmodified lines89909192929394957 unmodified lines1031041051061061071081096 unmodified lines11611711811911912012112212 unmodified lines1351361371381381391401418 unmodified lines1501511521531531541551561571581591601601611621638 unmodified lines17217317417517517617717824 unmodified lines language?: Language; }
const snippetsByLanguage: Record<Language, Snippet[]> = { javascript: getJavascriptSnippets(), python: getPythonSnippets(), bash: getBashSnippets() $: snippetsByLanguage = { javascript: getJavascriptSnippets(conversation), python: getPythonSnippets(conversation), bash: getBashSnippets(conversation) };
let selectedLanguage: Language = 'javascript';11 unmodified lines return hljs.highlight(code, { language }).value; }
function getJavascriptSnippets() { function getJavascriptSnippets(conversation: Conversation) { const messagesStr = getMessages().replace(/"([^"]+)":/g, '$1:'); const snippets: Snippet[] = []; snippets.push({13 unmodified lineslet out = "";
for await (const chunk of inference.chatCompletionStream({ model: "${conversation.model}", model: "${conversation.model.id}", messages: ${messagesStr}, temperature: ${conversation.config.temperature}, max_tokens: ${conversation.config.maxTokens},16 unmodified linesconst inference = new HfInference("your access token")
const out = await inference.chatCompletion({ model: "${conversation.model}", model: "${conversation.model.id}", messages: ${messagesStr}, temperature: ${conversation.config.temperature}, max_tokens: ${conversation.config.maxTokens},7 unmodified lines return snippets; }
function getPythonSnippets() { function getPythonSnippets(conversation: Conversation) { const messagesStr = getMessages(); const snippets: Snippet[] = []; snippets.push({6 unmodified lines label: 'Streaming API', code: `from huggingface_hub import InferenceClient
model_id="${conversation.model}"model_id="${conversation.model.id}"hf_token = "your HF token"inference_client = InferenceClient(model_id, token=hf_token)
12 unmodified lines label: 'Non-Streaming API', code: `from huggingface_hub import InferenceClient
model_id="${conversation.model}"model_id="${conversation.model.id}"hf_token = "your HF token"inference_client = InferenceClient(model_id, token=hf_token)
8 unmodified lines return snippets; }
function getBashSnippets() { function getBashSnippets(conversation: Conversation) { const messagesStr = getMessages(); const snippets: Snippet[] = [];
if (conversation.config.streaming) { snippets.push({ label: 'Streaming API', code: `curl 'https://api-inference.huggingface.co/models/${conversation.model}/v1/chat/completions' \ code: `curl 'https://api-inference.huggingface.co/models/${conversation.model.id}/v1/chat/completions' \--header "Authorization: Bearer {YOUR_HF_TOKEN}" \--header 'Content-Type: application/json' \--data '{8 unmodified lines // non-streaming snippets.push({ label: 'Non-Streaming API', code: `curl 'https://api-inference.huggingface.co/models/${conversation.model}/v1/chat/completions' \ code: `curl 'https://api-inference.huggingface.co/models/${conversation.model.id}/v1/chat/completions' \--header "Authorization: Bearer {YOUR_HF_TOKEN}" \--header 'Content-Type: application/json' \--data '{123455678910114 unmodified lines161718171920212223<script lang="ts"> import { type ModelEntry } from '@huggingface/hub'; import { createEventDispatcher } from 'svelte';
export let compatibleModels: ModelEntry[] = []; export let currentModel = compatibleModels[0]; export let disabled = false;
const dispatch = createEventDispatcher<{ modelIdxChange: number }>();</script>
<div>4 unmodified lines </label> <select {disabled} bind:value={currentModel} class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500" on:change={(e) => dispatch('modelIdxChange', e.currentTarget.selectedIndex)} > {#each compatibleModels as model} <option value={model.id}>{model.id}</option>src/lib/components/InferencePlayground/InferencePlayground.svelte+5-1
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte+13-13
src/lib/components/InferencePlayground/InferencePlaygroundModelSelector.svelte+4-2