Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Thomas G. Lopes
commited on
Commit
·
c971df7
1
Parent(s):
fd5a535
add link to copy token
Browse files
src/lib/components/inference-playground/code-snippets.svelte
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import { type ConversationClass } from "$lib/state/conversations.svelte";
|
| 3 |
-
import { token } from "$lib/state/token.svelte.js";
|
| 4 |
import { billing } from "$lib/state/billing.svelte";
|
|
|
|
| 5 |
import { isCustomModel } from "$lib/types.js";
|
| 6 |
import {
|
| 7 |
getInferenceSnippet,
|
|
@@ -17,6 +16,7 @@
|
|
| 17 |
import IconExternal from "~icons/carbon/arrow-up-right";
|
| 18 |
import IconCopy from "~icons/carbon/copy";
|
| 19 |
import LocalToasts from "../local-toasts.svelte";
|
|
|
|
| 20 |
|
| 21 |
hljs.registerLanguage("javascript", javascript);
|
| 22 |
hljs.registerLanguage("python", python);
|
|
@@ -37,8 +37,6 @@
|
|
| 37 |
type Language = keyof typeof labelsByLanguage;
|
| 38 |
|
| 39 |
let lang: Language = $state("javascript");
|
| 40 |
-
let showToken = $state(false);
|
| 41 |
-
|
| 42 |
type GetSnippetArgs = {
|
| 43 |
tokenStr?: string;
|
| 44 |
conversation: ConversationClass;
|
|
@@ -98,20 +96,10 @@
|
|
| 98 |
return hljs.highlight(code, { language: language === "sh" ? "http" : language }).value;
|
| 99 |
}
|
| 100 |
|
| 101 |
-
const tokenStr = $derived.by(() => {
|
| 102 |
-
if (isCustomModel(conversation.model)) {
|
| 103 |
-
const t = conversation.model.accessToken;
|
| 104 |
-
|
| 105 |
-
return t && showToken ? t : undefined;
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
return token.value && showToken ? token.value : undefined;
|
| 109 |
-
});
|
| 110 |
-
|
| 111 |
const snippetsByLang = $derived({
|
| 112 |
-
javascript: getSnippet({ lang: "js",
|
| 113 |
-
python: getSnippet({ lang: "python",
|
| 114 |
-
http: getSnippet({ lang: "sh",
|
| 115 |
} as Record<Language, GetInferenceSnippetReturn>);
|
| 116 |
|
| 117 |
// Auto-switch to available language if current one has no snippets
|
|
@@ -245,10 +233,14 @@
|
|
| 245 |
<h2 class="font-semibold">Non-Streaming API</h2>
|
| 246 |
{/if}
|
| 247 |
<div class="flex items-center gap-x-4">
|
| 248 |
-
<
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
<LocalToasts>
|
| 253 |
{#snippet children({ addToast, trigger })}
|
| 254 |
<button
|
|
|
|
| 1 |
<script lang="ts">
|
|
|
|
|
|
|
| 2 |
import { billing } from "$lib/state/billing.svelte";
|
| 3 |
+
import { type ConversationClass } from "$lib/state/conversations.svelte";
|
| 4 |
import { isCustomModel } from "$lib/types.js";
|
| 5 |
import {
|
| 6 |
getInferenceSnippet,
|
|
|
|
| 16 |
import IconExternal from "~icons/carbon/arrow-up-right";
|
| 17 |
import IconCopy from "~icons/carbon/copy";
|
| 18 |
import LocalToasts from "../local-toasts.svelte";
|
| 19 |
+
import IconLaunch from "~icons/carbon/launch";
|
| 20 |
|
| 21 |
hljs.registerLanguage("javascript", javascript);
|
| 22 |
hljs.registerLanguage("python", python);
|
|
|
|
| 37 |
type Language = keyof typeof labelsByLanguage;
|
| 38 |
|
| 39 |
let lang: Language = $state("javascript");
|
|
|
|
|
|
|
| 40 |
type GetSnippetArgs = {
|
| 41 |
tokenStr?: string;
|
| 42 |
conversation: ConversationClass;
|
|
|
|
| 96 |
return hljs.highlight(code, { language: language === "sh" ? "http" : language }).value;
|
| 97 |
}
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
const snippetsByLang = $derived({
|
| 100 |
+
javascript: getSnippet({ lang: "js", conversation }),
|
| 101 |
+
python: getSnippet({ lang: "python", conversation }),
|
| 102 |
+
http: getSnippet({ lang: "sh", conversation }),
|
| 103 |
} as Record<Language, GetInferenceSnippetReturn>);
|
| 104 |
|
| 105 |
// Auto-switch to available language if current one has no snippets
|
|
|
|
| 233 |
<h2 class="font-semibold">Non-Streaming API</h2>
|
| 234 |
{/if}
|
| 235 |
<div class="flex items-center gap-x-4">
|
| 236 |
+
<a
|
| 237 |
+
href="https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained"
|
| 238 |
+
target="_blank"
|
| 239 |
+
class="flex items-center gap-x-1 text-xs text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"
|
| 240 |
+
>
|
| 241 |
+
Create token
|
| 242 |
+
<IconLaunch class="translate-y-[0.5px] text-xs" />
|
| 243 |
+
</a>
|
| 244 |
<LocalToasts>
|
| 245 |
{#snippet children({ addToast, trigger })}
|
| 246 |
<button
|