Spaces:
Runtime error
Runtime error
[curl snippets] Improve UI (#38)
Browse files1 unmodified line234567891011121314151617181920212223245 unmodified lines3031323334353630 unmodified lines6768697071727359 unmodified lines13313413513613713813935 unmodified lines17517617717817918018113 unmodified lines1951961971981992002012022035 unmodified lines2092102112122132142152162171 unmodified lineimport hljs from 'highlight.js/lib/core';import javascript from 'highlight.js/lib/languages/javascript';import python from 'highlight.js/lib/languages/python';import bash from 'highlight.js/lib/languages/bash';import type { Conversation } from '$lib/types';import IconCopyCode from '../Icons/IconCopyCode.svelte';import { onDestroy } from 'svelte';hljs.registerLanguage('javascript', javascript);hljs.registerLanguage('python', python);hljs.registerLanguage('bash', bash);export let conversation: Conversation;const lanuages = ['javascript', 'python', 'bash'];type Language = (typeof lanuages)[number];const labelsByLanguage: Record<Language, string> = {javascript: 'JavaScript',python: 'Python',bash: 'Curl'};interface Snippet {5 unmodified lines$: snippetsByLanguage = {javascript: getJavascriptSnippets(conversation),python: getPythonSnippets(conversation),bash: getBashSnippets(conversation)};let selectedLanguage: Language = 'javascript';30 unmodified linesconst snippets: Snippet[] = [];snippets.push({label: 'Install @huggingface/inference',language: 'bash',code: `npm install --save @huggingface/inference`});if (conversation.streaming) {59 unmodified linesconst snippets: Snippet[] = [];snippets.push({label: 'Install huggingface_hub',language: 'bash',code: `pip install huggingface_hub`});if (conversation.streaming) {35 unmodified linesreturn snippets;}function getBashSnippets(conversation: Conversation) {const formattedMessages = ({ sep, start, end }) =>start +getMessages()13 unmodified linesif (conversation.streaming) {snippets.push({label: 'Streaming API',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 '{"model": "meta-llama/Meta-Llama-3-8B-Instruct","messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},5 unmodified lines// non-streamingsnippets.push({label: 'Non-Streaming API',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 '{"model": "meta-llama/Meta-Llama-3-8B-Instruct","messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},1 unmodified line234567891011121314151617181920212223245 unmodified lines3031323334353630 unmodified lines6768697071727359 unmodified lines13313413513613713813935 unmodified lines17517617717817918018113 unmodified lines1951961971981992002012022035 unmodified lines2092102112122132142152162171 unmodified lineimport hljs from 'highlight.js/lib/core';import javascript from 'highlight.js/lib/languages/javascript';import python from 'highlight.js/lib/languages/python';import http from 'highlight.js/lib/languages/http';import type { Conversation } from '$lib/types';import IconCopyCode from '../Icons/IconCopyCode.svelte';import { onDestroy } from 'svelte';hljs.registerLanguage('javascript', javascript);hljs.registerLanguage('python', python);hljs.registerLanguage('http', http);export let conversation: Conversation;const lanuages = ['javascript', 'python', 'http'];type Language = (typeof lanuages)[number];const labelsByLanguage: Record<Language, string> = {javascript: 'JavaScript',python: 'Python',http: 'Curl'};interface Snippet {5 unmodified lines$: snippetsByLanguage = {javascript: getJavascriptSnippets(conversation),python: getPythonSnippets(conversation),http: getHttpSnippets(conversation)};let selectedLanguage: Language = 'javascript';30 unmodified linesconst snippets: Snippet[] = [];snippets.push({label: 'Install @huggingface/inference',language: 'http',code: `npm install --save @huggingface/inference`});if (conversation.streaming) {59 unmodified linesconst snippets: Snippet[] = [];snippets.push({label: 'Install huggingface_hub',language: 'http',code: `pip install huggingface_hub`});if (conversation.streaming) {35 unmodified linesreturn snippets;}function getHttpSnippets(conversation: Conversation) {const formattedMessages = ({ sep, start, end }) =>start +getMessages()13 unmodified linesif (conversation.streaming) {snippets.push({label: 'Streaming API',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 '{"model": "meta-llama/Meta-Llama-3-8B-Instruct","messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},5 unmodified lines// non-streamingsnippets.push({label: 'Non-Streaming API',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 '{"model": "meta-llama/Meta-Llama-3-8B-Instruct","messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte+14-14