Spaces:
Runtime error
Runtime error
Improve JS snippet (#18)
Browse files21 unmodified lines22232425262711 unmodified lines3940414243444546474849505152535455565758596061626364651 unmodified line67686970717273747576777879808152 unmodified lines13413513613713813914053 unmodified lines19419519619719819920020120220320420520620721 unmodified linesinterface Snippet {label: string;code: string;}const snippetsByLanguage: Record<Language, Snippet[]> = {11 unmodified linesfunction getJavascriptSnippets() {const snippets: Snippet[] = [];snippets.push({label: 'Install',code: `import { HfInference } from '@huggingface/inference'const hf = new HfInference('your access token')`});if (conversation.config.streaming) {snippets.push({label: 'Streaming API',code: `let out = "";for await (const chunk of hf.chatCompletionStream({model: "${conversation.model}",messages: [{ role: "user", content: "Complete the equation 1+1= ,just the answer" },],max_tokens: ${conversation.config.maxTokens},temperature: ${conversation.config.temperature},seed: 0,})) {if (chunk.choices && chunk.choices.length > 0) {out += chunk.choices[0].delta.content;}}`});1 unmodified line// non-streamingsnippets.push({label: 'Non-Streaming API',code: `await hf.chatCompletion({model: "${conversation.model}",messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }],max_tokens: ${conversation.config.maxTokens},temperature: ${conversation.config.temperature},seed: 0,});`});}52 unmodified lineslabel: 'Install',code: `import { HfInference } from '@huggingface/inference'const hf = new HfInference('your access token')`});if (conversation.config.streaming) {snippets.push({53 unmodified lines</ul></div>{#each snippetsByLanguage[selectedLanguage] as { label, code }}<div class="px-4 pb-4 pt-6"><h2 class="font-semibold">{label}</h2></div><preclass="overflow-x-auto rounded-lg border border-gray-200/80 bg-white px-4 py-6 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-800/50">{@html highlight(code,'javascript')}</pre>{/each}</div>21 unmodified lines2223242526272811 unmodified lines404142434445464748495051525354555657585960616263646566676869707172731 unmodified line75767778798081828384858687888990919293949552 unmodified lines14814915015115215315453 unmodified lines20820921021121221321421521621721821922022121 unmodified linesinterface Snippet {label: string;code: string;language?: Language;}const snippetsByLanguage: Record<Language, Snippet[]> = {11 unmodified linesfunction getJavascriptSnippets() {const snippets: Snippet[] = [];snippets.push({label: 'Install @huggingface/inference',language: 'bash',code: `npm install --save @huggingface/inference# oryarn add @huggingface/inference`});if (conversation.config.streaming) {snippets.push({label: 'Streaming API',code: `import { HfInference } from "@huggingface/inference"const inference = new HfInference("your HF token")let out = "";for await (const chunk of inference.chatCompletionStream({model: "${conversation.model}",messages: [{ role: "user", content: "Tell me a story" },],max_tokens: ${conversation.config.maxTokens},temperature: ${conversation.config.temperature},seed: 0,})) {if (chunk.choices && chunk.choices.length > 0) {const newContent = chunk.choices[0].delta.content;out += newContent;process.stdout.write(newContent);}}`});1 unmodified line// non-streamingsnippets.push({label: 'Non-Streaming API',code: `import { HfInference } from '@huggingface/inference'const inference = new HfInference("your access token")const out = await inference.chatCompletion({model: "${conversation.model}",messages: [{ role: "user", content: "Who are you?" }],max_tokens: ${conversation.config.maxTokens},temperature: ${conversation.config.temperature},seed: 0,});console.log(out.choices[0].message);`});}52 unmodified lineslabel: 'Install',code: `import { HfInference } from '@huggingface/inference'const hf = new HfInference("your access token")`});if (conversation.config.streaming) {snippets.push({53 unmodified lines</ul></div>{#each snippetsByLanguage[selectedLanguage] as { label, code, language }}<div class="px-4 pb-4 pt-6"><h2 class="font-semibold">{label}</h2></div><preclass="overflow-x-auto rounded-lg border border-gray-200/80 bg-white px-4 py-6 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-800/50">{@html highlight(code,language ?? selectedLanguage)}</pre>{/each}</div>
src/lib/components/CodeSnippets.svelte+34-20