Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
loading state
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
|
@@ -15,12 +15,13 @@
|
|
| 15 |
'mistralai/Mistral-7B-Instruct-v0.3'
|
| 16 |
];
|
| 17 |
|
| 18 |
-
let hfToken: string | null;
|
| 19 |
-
|
| 20 |
let currentModel = compatibleModels[0];
|
| 21 |
let systemMessage: Message = { role: 'system', content: '' };
|
| 22 |
let messages: Message[] = startMessages;
|
| 23 |
|
|
|
|
|
|
|
| 24 |
function addMessage() {
|
| 25 |
messages = [
|
| 26 |
...messages,
|
|
@@ -52,17 +53,23 @@
|
|
| 52 |
hfToken = token;
|
| 53 |
}
|
| 54 |
(document.activeElement as HTMLElement).blur();
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
$: console.log(messages);
|
|
@@ -71,11 +78,12 @@
|
|
| 71 |
<svelte:window on:keydown={onKeydown} />
|
| 72 |
|
| 73 |
<div
|
| 74 |
-
class="grid h-dvh divide-gray-200 overflow-hidden max-md:grid-cols-1 max-md:divide-y md:grid-cols-[260px,1fr,260px] md:divide-x"
|
| 75 |
>
|
| 76 |
<div class="relative flex flex-col overflow-y-auto p-5 pb-24">
|
| 77 |
<div class="pb-2 text-sm font-semibold">SYSTEM</div>
|
| 78 |
<textarea
|
|
|
|
| 79 |
name=""
|
| 80 |
id=""
|
| 81 |
placeholder="Enter a custom prompt"
|
|
@@ -118,9 +126,27 @@
|
|
| 118 |
<button
|
| 119 |
on:click={submit}
|
| 120 |
type="button"
|
| 121 |
-
class="rounded-lg bg-black px-5 py-2.5 text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700"
|
| 122 |
-
>Submit</button
|
| 123 |
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
</div>
|
| 125 |
</div>
|
| 126 |
<div class="flex flex-col gap-6 p-5">
|
|
|
|
| 15 |
'mistralai/Mistral-7B-Instruct-v0.3'
|
| 16 |
];
|
| 17 |
|
| 18 |
+
let hfToken: string | null = '';
|
|
|
|
| 19 |
let currentModel = compatibleModels[0];
|
| 20 |
let systemMessage: Message = { role: 'system', content: '' };
|
| 21 |
let messages: Message[] = startMessages;
|
| 22 |
|
| 23 |
+
let loading = false;
|
| 24 |
+
|
| 25 |
function addMessage() {
|
| 26 |
messages = [
|
| 27 |
...messages,
|
|
|
|
| 53 |
hfToken = token;
|
| 54 |
}
|
| 55 |
(document.activeElement as HTMLElement).blur();
|
| 56 |
+
loading = true;
|
| 57 |
+
try {
|
| 58 |
+
const hf = new HfInference(hfToken);
|
| 59 |
+
|
| 60 |
+
const out = await hf.chatCompletion({
|
| 61 |
+
model: currentModel,
|
| 62 |
+
messages: systemMessage.content ? [systemMessage, ...messages] : messages,
|
| 63 |
+
max_tokens: 500,
|
| 64 |
+
temperature: 0.1,
|
| 65 |
+
seed: 0
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
messages = [...messages, ...out.choices.map((o) => o.message)];
|
| 69 |
+
} catch (error) {
|
| 70 |
+
alert('error: ' + error.message);
|
| 71 |
+
}
|
| 72 |
+
loading = false;
|
| 73 |
}
|
| 74 |
|
| 75 |
$: console.log(messages);
|
|
|
|
| 78 |
<svelte:window on:keydown={onKeydown} />
|
| 79 |
|
| 80 |
<div
|
| 81 |
+
class="grid h-dvh max-h-dvh divide-gray-200 overflow-hidden max-md:grid-cols-1 max-md:divide-y md:grid-cols-[260px,1fr,260px] md:divide-x"
|
| 82 |
>
|
| 83 |
<div class="relative flex flex-col overflow-y-auto p-5 pb-24">
|
| 84 |
<div class="pb-2 text-sm font-semibold">SYSTEM</div>
|
| 85 |
<textarea
|
| 86 |
+
disabled
|
| 87 |
name=""
|
| 88 |
id=""
|
| 89 |
placeholder="Enter a custom prompt"
|
|
|
|
| 126 |
<button
|
| 127 |
on:click={submit}
|
| 128 |
type="button"
|
| 129 |
+
class="flex h-[42px] w-24 items-center justify-center rounded-lg bg-black px-5 py-2.5 text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700"
|
|
|
|
| 130 |
>
|
| 131 |
+
{#if loading}
|
| 132 |
+
<div class="flex flex-none items-center gap-[3px]">
|
| 133 |
+
<div
|
| 134 |
+
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
|
| 135 |
+
style="animation-delay: 0.25s;"
|
| 136 |
+
/>
|
| 137 |
+
<div
|
| 138 |
+
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
|
| 139 |
+
style="animation-delay: 0.5s;"
|
| 140 |
+
/>
|
| 141 |
+
<div
|
| 142 |
+
class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
|
| 143 |
+
style="animation-delay: 0.75s;"
|
| 144 |
+
/>
|
| 145 |
+
</div>
|
| 146 |
+
{:else}
|
| 147 |
+
Submit
|
| 148 |
+
{/if}
|
| 149 |
+
</button>
|
| 150 |
</div>
|
| 151 |
</div>
|
| 152 |
<div class="flex flex-col gap-6 p-5">
|