Spaces:
Runtime error
Runtime error
[curl snippets] Improve UI (#38)
Browse files1 unmodified line2345567891011121213141516161718192021212223245 unmodified lines303132333334353630 unmodified lines676869707071727359 unmodified lines13313413513613613713813935 unmodified lines17517617717817817918018113 unmodified lines1951961971981992001981992002012022035 unmodified lines2092102112122132142122132142152162171 unmodified line import 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 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('bash', bash); hljs.registerLanguage('http', http);
export let conversation: Conversation;
const lanuages = ['javascript', 'python', 'bash']; const lanuages = ['javascript', 'python', 'http']; type Language = (typeof lanuages)[number]; const labelsByLanguage: Record<Language, string> = { javascript: 'JavaScript', python: 'Python', bash: 'Curl' http: 'Curl' };
interface Snippet {5 unmodified lines $: snippetsByLanguage = { javascript: getJavascriptSnippets(conversation), python: getPythonSnippets(conversation), bash: getBashSnippets(conversation) http: getHttpSnippets(conversation) };
let selectedLanguage: Language = 'javascript';30 unmodified lines const snippets: Snippet[] = []; snippets.push({ label: 'Install @huggingface/inference', language: 'bash', language: 'http', code: `npm install --save @huggingface/inference` }); if (conversation.streaming) {59 unmodified lines const snippets: Snippet[] = []; snippets.push({ label: 'Install huggingface_hub', language: 'bash', language: 'http', code: `pip install huggingface_hub` }); if (conversation.streaming) {35 unmodified lines return snippets; }
function getBashSnippets(conversation: Conversation) { function getHttpSnippets(conversation: Conversation) { const formattedMessages = ({ sep, start, end }) => start + getMessages()13 unmodified lines if (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' \ 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-streaming snippets.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' \ 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