Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
code
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
|
@@ -11,6 +11,13 @@
|
|
| 11 |
content: string;
|
| 12 |
};
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
const startMessages: Message[] = [{ role: 'user', content: '' }];
|
| 15 |
|
| 16 |
const messagesParam = queryParam('messages', {
|
|
@@ -22,12 +29,6 @@
|
|
| 22 |
encode: (value: string) => value,
|
| 23 |
decode: (value: string | null) => value || ''
|
| 24 |
});
|
| 25 |
-
const compatibleModels: string[] = [
|
| 26 |
-
'google/gemma-2-27b-it',
|
| 27 |
-
'meta-llama/Meta-Llama-3-8B-Instruct',
|
| 28 |
-
'meta-llama/Meta-Llama-3-70B-Instruct',
|
| 29 |
-
'mistralai/Mistral-7B-Instruct-v0.3'
|
| 30 |
-
];
|
| 31 |
|
| 32 |
const currentModel = queryParam('model', ssp.string(compatibleModels[0]));
|
| 33 |
const temperature = queryParam('temperature', ssp.number(0.5));
|
|
@@ -51,8 +52,6 @@
|
|
| 51 |
];
|
| 52 |
}
|
| 53 |
|
| 54 |
-
$: console.log($currentModel);
|
| 55 |
-
|
| 56 |
function deleteMessage(i: number) {
|
| 57 |
$messagesParam = $messagesParam.filter((_, j) => j !== i);
|
| 58 |
}
|
|
@@ -176,7 +175,7 @@
|
|
| 176 |
<div class="!p-0 text-sm font-semibold">Add message</div>
|
| 177 |
</button>
|
| 178 |
{:else}
|
| 179 |
-
<PlaygroundCode />
|
| 180 |
{/if}
|
| 181 |
</div>
|
| 182 |
|
|
@@ -201,8 +200,20 @@
|
|
| 201 |
<button
|
| 202 |
type="button"
|
| 203 |
on:click={() => (viewCode = !viewCode)}
|
| 204 |
-
class="rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
>
|
| 207 |
<button
|
| 208 |
on:click={submit}
|
|
|
|
| 11 |
content: string;
|
| 12 |
};
|
| 13 |
|
| 14 |
+
const compatibleModels: string[] = [
|
| 15 |
+
'google/gemma-2-27b-it',
|
| 16 |
+
'meta-llama/Meta-Llama-3-8B-Instruct',
|
| 17 |
+
'meta-llama/Meta-Llama-3-70B-Instruct',
|
| 18 |
+
'mistralai/Mistral-7B-Instruct-v0.3'
|
| 19 |
+
];
|
| 20 |
+
$: console.log($currentModel);
|
| 21 |
const startMessages: Message[] = [{ role: 'user', content: '' }];
|
| 22 |
|
| 23 |
const messagesParam = queryParam('messages', {
|
|
|
|
| 29 |
encode: (value: string) => value,
|
| 30 |
decode: (value: string | null) => value || ''
|
| 31 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
const currentModel = queryParam('model', ssp.string(compatibleModels[0]));
|
| 34 |
const temperature = queryParam('temperature', ssp.number(0.5));
|
|
|
|
| 52 |
];
|
| 53 |
}
|
| 54 |
|
|
|
|
|
|
|
| 55 |
function deleteMessage(i: number) {
|
| 56 |
$messagesParam = $messagesParam.filter((_, j) => j !== i);
|
| 57 |
}
|
|
|
|
| 175 |
<div class="!p-0 text-sm font-semibold">Add message</div>
|
| 176 |
</button>
|
| 177 |
{:else}
|
| 178 |
+
<PlaygroundCode model={$currentModel} />
|
| 179 |
{/if}
|
| 180 |
</div>
|
| 181 |
|
|
|
|
| 200 |
<button
|
| 201 |
type="button"
|
| 202 |
on:click={() => (viewCode = !viewCode)}
|
| 203 |
+
class="flex items-center gap-2 rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
|
| 204 |
+
>
|
| 205 |
+
<svg
|
| 206 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 207 |
+
width="1em"
|
| 208 |
+
height="1em"
|
| 209 |
+
class="text-base"
|
| 210 |
+
viewBox="0 0 32 32"
|
| 211 |
+
><path
|
| 212 |
+
fill="currentColor"
|
| 213 |
+
d="m31 16l-7 7l-1.41-1.41L28.17 16l-5.58-5.59L24 9l7 7zM1 16l7-7l1.41 1.41L3.83 16l5.58 5.59L8 23l-7-7zm11.42 9.484L17.64 6l1.932.517L14.352 26z"
|
| 214 |
+
/></svg
|
| 215 |
+
>
|
| 216 |
+
{!viewCode ? 'View Code' : 'Hide Code'}</button
|
| 217 |
>
|
| 218 |
<button
|
| 219 |
on:click={submit}
|
src/lib/components/Playground/PlaygroundCode.svelte
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
<script>
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
max_tokens: 500,
|
| 6 |
temperature: 0.1,
|
| 7 |
seed: 0,
|
| 8 |
});`;
|
| 9 |
|
| 10 |
-
|
| 11 |
|
| 12 |
for await (const chunk of hf.chatCompletionStream({
|
| 13 |
model: "mistrali/Mistral-7B-Instruct-v0.2",
|
|
@@ -24,11 +32,41 @@ for await (const chunk of hf.chatCompletionStream({
|
|
| 24 |
}`;
|
| 25 |
</script>
|
| 26 |
|
| 27 |
-
<div class="
|
| 28 |
-
<
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
<
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
</div>
|
|
|
|
| 1 |
<script>
|
| 2 |
+
export let model = '';
|
| 3 |
+
|
| 4 |
+
const npmSnippet = `import { HfInference } from '@huggingface/inference'
|
| 5 |
+
|
| 6 |
+
const hf = new HfInference('your access token')`;
|
| 7 |
+
|
| 8 |
+
$: nonStreaming = `await hf.chatCompletion({
|
| 9 |
+
model: "${model}",
|
| 10 |
+
messages: [
|
| 11 |
+
{ role: "user", content: "Complete the this sentence with words one plus one is equal " }
|
| 12 |
+
],
|
| 13 |
max_tokens: 500,
|
| 14 |
temperature: 0.1,
|
| 15 |
seed: 0,
|
| 16 |
});`;
|
| 17 |
|
| 18 |
+
$: streaming = `let out = "";
|
| 19 |
|
| 20 |
for await (const chunk of hf.chatCompletionStream({
|
| 21 |
model: "mistrali/Mistral-7B-Instruct-v0.2",
|
|
|
|
| 32 |
}`;
|
| 33 |
</script>
|
| 34 |
|
| 35 |
+
<div class="pt-2">
|
| 36 |
+
<div
|
| 37 |
+
class="border-b border-gray-200 text-center text-sm font-medium text-gray-500 dark:border-gray-700 dark:text-gray-400"
|
| 38 |
+
>
|
| 39 |
+
<ul class="-mb-px flex flex-wrap">
|
| 40 |
+
<li>
|
| 41 |
+
<a
|
| 42 |
+
href="#"
|
| 43 |
+
class="active inline-block rounded-t-lg border-b-2 border-black p-4 text-black dark:border-blue-500 dark:text-blue-500"
|
| 44 |
+
aria-current="page">Huggingface.js</a
|
| 45 |
+
>
|
| 46 |
+
</li>
|
| 47 |
+
<li>
|
| 48 |
+
<a
|
| 49 |
+
href="#"
|
| 50 |
+
class="inline-block rounded-t-lg border-b-2 border-transparent p-4 hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300"
|
| 51 |
+
>Curl</a
|
| 52 |
+
>
|
| 53 |
+
</li>
|
| 54 |
+
</ul>
|
| 55 |
+
</div>
|
| 56 |
|
| 57 |
+
<div class="px-4 pb-4 pt-6">
|
| 58 |
+
<h2 class="font-semibold">Install and instantiate</h2>
|
| 59 |
+
</div>
|
| 60 |
+
<pre
|
| 61 |
+
class="overflow-x-auto border-y border-y-gray-100 bg-gray-50 px-4 py-6 text-sm">{npmSnippet}</pre>
|
| 62 |
+
<div class="px-4 pb-4 pt-6">
|
| 63 |
+
<h2 class="font-semibold">Non-Streaming API</h2>
|
| 64 |
+
</div>
|
| 65 |
+
<pre
|
| 66 |
+
class="overflow-x-auto border-y border-y-gray-100 bg-gray-50 px-4 py-6 text-sm">{nonStreaming}</pre>
|
| 67 |
+
<div class="px-4 pb-4 pt-6">
|
| 68 |
+
<h2 class="font-semibold">Streaming API</h2>
|
| 69 |
+
</div>
|
| 70 |
+
<pre
|
| 71 |
+
class="overflow-x-auto border-y border-gray-100 bg-gray-50 px-4 py-6 text-sm">{streaming}</pre>
|
| 72 |
</div>
|