Spaces:
Runtime error
Runtime error
[curl snippets] Improve UI
Browse files
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte
CHANGED
|
@@ -2,23 +2,23 @@
|
|
| 2 |
import hljs from 'highlight.js/lib/core';
|
| 3 |
import javascript from 'highlight.js/lib/languages/javascript';
|
| 4 |
import python from 'highlight.js/lib/languages/python';
|
| 5 |
-
import
|
| 6 |
import type { Conversation } from '$lib/types';
|
| 7 |
import IconCopyCode from '../Icons/IconCopyCode.svelte';
|
| 8 |
import { onDestroy } from 'svelte';
|
| 9 |
|
| 10 |
hljs.registerLanguage('javascript', javascript);
|
| 11 |
hljs.registerLanguage('python', python);
|
| 12 |
-
hljs.registerLanguage('
|
| 13 |
|
| 14 |
export let conversation: Conversation;
|
| 15 |
|
| 16 |
-
const lanuages = ['javascript', 'python', '
|
| 17 |
type Language = (typeof lanuages)[number];
|
| 18 |
const labelsByLanguage: Record<Language, string> = {
|
| 19 |
javascript: 'JavaScript',
|
| 20 |
python: 'Python',
|
| 21 |
-
|
| 22 |
};
|
| 23 |
|
| 24 |
interface Snippet {
|
|
@@ -30,7 +30,7 @@
|
|
| 30 |
$: snippetsByLanguage = {
|
| 31 |
javascript: getJavascriptSnippets(conversation),
|
| 32 |
python: getPythonSnippets(conversation),
|
| 33 |
-
|
| 34 |
};
|
| 35 |
|
| 36 |
let selectedLanguage: Language = 'javascript';
|
|
@@ -67,7 +67,7 @@
|
|
| 67 |
const snippets: Snippet[] = [];
|
| 68 |
snippets.push({
|
| 69 |
label: 'Install @huggingface/inference',
|
| 70 |
-
language: '
|
| 71 |
code: `npm install --save @huggingface/inference`
|
| 72 |
});
|
| 73 |
if (conversation.streaming) {
|
|
@@ -133,7 +133,7 @@ console.log(out.choices[0].message);`
|
|
| 133 |
const snippets: Snippet[] = [];
|
| 134 |
snippets.push({
|
| 135 |
label: 'Install huggingface_hub',
|
| 136 |
-
language: '
|
| 137 |
code: `pip install huggingface_hub`
|
| 138 |
});
|
| 139 |
if (conversation.streaming) {
|
|
@@ -175,7 +175,7 @@ print(output.choices[0].message)`
|
|
| 175 |
return snippets;
|
| 176 |
}
|
| 177 |
|
| 178 |
-
function
|
| 179 |
const formattedMessages = ({ sep, start, end }) =>
|
| 180 |
start +
|
| 181 |
getMessages()
|
|
@@ -195,9 +195,9 @@ print(output.choices[0].message)`
|
|
| 195 |
if (conversation.streaming) {
|
| 196 |
snippets.push({
|
| 197 |
label: 'Streaming API',
|
| 198 |
-
code: `curl 'https://api-inference.huggingface.co/models/${conversation.model.id}/v1/chat/completions'
|
| 199 |
-
--header "Authorization: Bearer {YOUR_HF_TOKEN}"
|
| 200 |
-
--header 'Content-Type: application/json'
|
| 201 |
--data '{
|
| 202 |
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 203 |
"messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},
|
|
@@ -209,9 +209,9 @@ print(output.choices[0].message)`
|
|
| 209 |
// non-streaming
|
| 210 |
snippets.push({
|
| 211 |
label: 'Non-Streaming API',
|
| 212 |
-
code: `curl 'https://api-inference.huggingface.co/models/${conversation.model.id}/v1/chat/completions'
|
| 213 |
-
--header "Authorization: Bearer {YOUR_HF_TOKEN}"
|
| 214 |
-
--header 'Content-Type: application/json'
|
| 215 |
--data '{
|
| 216 |
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 217 |
"messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},
|
|
|
|
| 2 |
import hljs from 'highlight.js/lib/core';
|
| 3 |
import javascript from 'highlight.js/lib/languages/javascript';
|
| 4 |
import python from 'highlight.js/lib/languages/python';
|
| 5 |
+
import http from 'highlight.js/lib/languages/http';
|
| 6 |
import type { Conversation } from '$lib/types';
|
| 7 |
import IconCopyCode from '../Icons/IconCopyCode.svelte';
|
| 8 |
import { onDestroy } from 'svelte';
|
| 9 |
|
| 10 |
hljs.registerLanguage('javascript', javascript);
|
| 11 |
hljs.registerLanguage('python', python);
|
| 12 |
+
hljs.registerLanguage('http', http);
|
| 13 |
|
| 14 |
export let conversation: Conversation;
|
| 15 |
|
| 16 |
+
const lanuages = ['javascript', 'python', 'http'];
|
| 17 |
type Language = (typeof lanuages)[number];
|
| 18 |
const labelsByLanguage: Record<Language, string> = {
|
| 19 |
javascript: 'JavaScript',
|
| 20 |
python: 'Python',
|
| 21 |
+
http: 'Curl'
|
| 22 |
};
|
| 23 |
|
| 24 |
interface Snippet {
|
|
|
|
| 30 |
$: snippetsByLanguage = {
|
| 31 |
javascript: getJavascriptSnippets(conversation),
|
| 32 |
python: getPythonSnippets(conversation),
|
| 33 |
+
http: getHttpSnippets(conversation)
|
| 34 |
};
|
| 35 |
|
| 36 |
let selectedLanguage: Language = 'javascript';
|
|
|
|
| 67 |
const snippets: Snippet[] = [];
|
| 68 |
snippets.push({
|
| 69 |
label: 'Install @huggingface/inference',
|
| 70 |
+
language: 'http',
|
| 71 |
code: `npm install --save @huggingface/inference`
|
| 72 |
});
|
| 73 |
if (conversation.streaming) {
|
|
|
|
| 133 |
const snippets: Snippet[] = [];
|
| 134 |
snippets.push({
|
| 135 |
label: 'Install huggingface_hub',
|
| 136 |
+
language: 'http',
|
| 137 |
code: `pip install huggingface_hub`
|
| 138 |
});
|
| 139 |
if (conversation.streaming) {
|
|
|
|
| 175 |
return snippets;
|
| 176 |
}
|
| 177 |
|
| 178 |
+
function getHttpSnippets(conversation: Conversation) {
|
| 179 |
const formattedMessages = ({ sep, start, end }) =>
|
| 180 |
start +
|
| 181 |
getMessages()
|
|
|
|
| 195 |
if (conversation.streaming) {
|
| 196 |
snippets.push({
|
| 197 |
label: 'Streaming API',
|
| 198 |
+
code: `curl 'https://api-inference.huggingface.co/models/${conversation.model.id}/v1/chat/completions' \\
|
| 199 |
+
--header "Authorization: Bearer {YOUR_HF_TOKEN}" \\
|
| 200 |
+
--header 'Content-Type: application/json' \\
|
| 201 |
--data '{
|
| 202 |
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 203 |
"messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},
|
|
|
|
| 209 |
// non-streaming
|
| 210 |
snippets.push({
|
| 211 |
label: 'Non-Streaming API',
|
| 212 |
+
code: `curl 'https://api-inference.huggingface.co/models/${conversation.model.id}/v1/chat/completions' \\
|
| 213 |
+
--header "Authorization: Bearer {YOUR_HF_TOKEN}" \\
|
| 214 |
+
--header 'Content-Type: application/json' \\
|
| 215 |
--data '{
|
| 216 |
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 217 |
"messages": ${formattedMessages({ sep: ',\n ', start: `[\n `, end: `\n]` })},
|