save hf token for later
Browse files
src/lib/components/InferencePlayground/InferencePlayground.svelte
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
FEATUED_MODELS_IDS,
|
12 |
} from "./inferencePlaygroundUtils";
|
13 |
|
14 |
-
import { onDestroy } from "svelte";
|
15 |
import GenerationConfig from "./InferencePlaygroundGenerationConfig.svelte";
|
16 |
import HFTokenModal from "./InferencePlaygroundHFTokenModal.svelte";
|
17 |
import ModelSelector from "./InferencePlaygroundModelSelector.svelte";
|
@@ -41,6 +41,9 @@
|
|
41 |
let generatedTokensCount = 0;
|
42 |
let abortController: AbortController | undefined = undefined;
|
43 |
let waitForNonStreaming = true;
|
|
|
|
|
|
|
44 |
|
45 |
$: systemPromptSupported = isSystemPromptSupported(conversation.model);
|
46 |
|
@@ -124,6 +127,7 @@
|
|
124 |
if (error instanceof Error) {
|
125 |
if (error.message.includes("token seems invalid")) {
|
126 |
hfToken = "";
|
|
|
127 |
}
|
128 |
if (error.name !== "AbortError") {
|
129 |
alert("error: " + error.message);
|
@@ -150,6 +154,9 @@
|
|
150 |
const RE_HF_TOKEN = /\bhf_[a-zA-Z0-9]{34}\b/;
|
151 |
if (RE_HF_TOKEN.test(submittedHfToken)) {
|
152 |
hfToken = submittedHfToken;
|
|
|
|
|
|
|
153 |
submit();
|
154 |
showTokenModal = false;
|
155 |
} else {
|
@@ -157,13 +164,20 @@
|
|
157 |
}
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
onDestroy(() => {
|
161 |
abortController?.abort();
|
162 |
});
|
163 |
</script>
|
164 |
|
165 |
{#if showTokenModal}
|
166 |
-
<HFTokenModal on:close={() => (showTokenModal = false)} on:submit={handleTokenSubmit} />
|
167 |
{/if}
|
168 |
|
169 |
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
|
11 |
FEATUED_MODELS_IDS,
|
12 |
} from "./inferencePlaygroundUtils";
|
13 |
|
14 |
+
import { onDestroy, onMount } from "svelte";
|
15 |
import GenerationConfig from "./InferencePlaygroundGenerationConfig.svelte";
|
16 |
import HFTokenModal from "./InferencePlaygroundHFTokenModal.svelte";
|
17 |
import ModelSelector from "./InferencePlaygroundModelSelector.svelte";
|
|
|
41 |
let generatedTokensCount = 0;
|
42 |
let abortController: AbortController | undefined = undefined;
|
43 |
let waitForNonStreaming = true;
|
44 |
+
let storeLocallyHfToken = false;
|
45 |
+
|
46 |
+
const hfTokenLocalStorageKey = "hf-inference-token";
|
47 |
|
48 |
$: systemPromptSupported = isSystemPromptSupported(conversation.model);
|
49 |
|
|
|
127 |
if (error instanceof Error) {
|
128 |
if (error.message.includes("token seems invalid")) {
|
129 |
hfToken = "";
|
130 |
+
localStorage.removeItem(hfTokenLocalStorageKey);
|
131 |
}
|
132 |
if (error.name !== "AbortError") {
|
133 |
alert("error: " + error.message);
|
|
|
154 |
const RE_HF_TOKEN = /\bhf_[a-zA-Z0-9]{34}\b/;
|
155 |
if (RE_HF_TOKEN.test(submittedHfToken)) {
|
156 |
hfToken = submittedHfToken;
|
157 |
+
if(storeLocallyHfToken){
|
158 |
+
localStorage.setItem(hfTokenLocalStorageKey, JSON.stringify(hfToken));
|
159 |
+
}
|
160 |
submit();
|
161 |
showTokenModal = false;
|
162 |
} else {
|
|
|
164 |
}
|
165 |
}
|
166 |
|
167 |
+
onMount(() => {
|
168 |
+
const storedHfToken = localStorage.getItem(hfTokenLocalStorageKey);
|
169 |
+
if (storedHfToken !== null) {
|
170 |
+
hfToken = JSON.parse(storedHfToken);
|
171 |
+
}
|
172 |
+
});
|
173 |
+
|
174 |
onDestroy(() => {
|
175 |
abortController?.abort();
|
176 |
});
|
177 |
</script>
|
178 |
|
179 |
{#if showTokenModal}
|
180 |
+
<HFTokenModal bind:storeLocallyHfToken on:close={() => (showTokenModal = false)} on:submit={handleTokenSubmit} />
|
181 |
{/if}
|
182 |
|
183 |
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
src/lib/components/InferencePlayground/InferencePlaygroundHFTokenModal.svelte
CHANGED
@@ -5,6 +5,8 @@
|
|
5 |
|
6 |
import IconCross from "../Icons/IconCross.svelte";
|
7 |
|
|
|
|
|
8 |
let backdropEl: HTMLDivElement;
|
9 |
let modalEl: HTMLDivElement;
|
10 |
|
@@ -94,6 +96,16 @@
|
|
94 |
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
95 |
/>
|
96 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
</div>
|
98 |
|
99 |
<!-- Modal footer -->
|
|
|
5 |
|
6 |
import IconCross from "../Icons/IconCross.svelte";
|
7 |
|
8 |
+
export let storeLocallyHfToken = false;
|
9 |
+
|
10 |
let backdropEl: HTMLDivElement;
|
11 |
let modalEl: HTMLDivElement;
|
12 |
|
|
|
96 |
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
97 |
/>
|
98 |
</div>
|
99 |
+
<label class="flex items-center gap-x-1 text-gray-900 dark:text-gray-200">
|
100 |
+
<input type="checkbox" bind:checked={storeLocallyHfToken}>
|
101 |
+
<p class="leading-none">store locally <span class="text-gray-800 dark:text-gray-300">(using <a
|
102 |
+
href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage"
|
103 |
+
target="_blank"
|
104 |
+
class="underline"
|
105 |
+
>
|
106 |
+
localStorage
|
107 |
+
</a> for the next use)</span></p>
|
108 |
+
</label>
|
109 |
</div>
|
110 |
|
111 |
<!-- Modal footer -->
|