Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Thomas G. Lopes
commited on
Commit
·
812d95a
1
Parent(s):
b1426d3
migrate code snippets
Browse files
src/lib/components/{icons/icon-provider.svelte → icon-provider.svelte}
RENAMED
|
File without changes
|
src/lib/components/inference-playground/code-snippets.svelte
CHANGED
|
@@ -10,15 +10,19 @@
|
|
| 10 |
import { token } from "$lib/stores/token.js";
|
| 11 |
import { entries, fromEntries, keys } from "$lib/utils/object.js";
|
| 12 |
import type { InferenceProvider } from "@huggingface/inference";
|
| 13 |
-
import IconCopyCode from "~icons/carbon/copy";
|
| 14 |
import IconExternal from "~icons/carbon/arrow-up-right";
|
|
|
|
| 15 |
import { getInferenceSnippet, type GetInferenceSnippetReturn, type InferenceSnippetLanguage } from "./utils.js";
|
| 16 |
|
| 17 |
hljs.registerLanguage("javascript", javascript);
|
| 18 |
hljs.registerLanguage("python", python);
|
| 19 |
hljs.registerLanguage("http", http);
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
const dispatch = createEventDispatcher<{ closeCode: void }>();
|
| 24 |
|
|
@@ -29,10 +33,8 @@
|
|
| 29 |
} as const satisfies Record<string, string>;
|
| 30 |
type Language = keyof typeof labelsByLanguage;
|
| 31 |
|
| 32 |
-
let lang: Language = "javascript";
|
| 33 |
-
let showToken = false;
|
| 34 |
-
|
| 35 |
-
$: tokenStr = getTokenStr(showToken);
|
| 36 |
|
| 37 |
type GetSnippetArgs = {
|
| 38 |
tokenStr: string;
|
|
@@ -49,50 +51,20 @@
|
|
| 49 |
});
|
| 50 |
}
|
| 51 |
|
| 52 |
-
$: snippetsByLang = {
|
| 53 |
-
javascript: getSnippet({ lang: "js", tokenStr, conversation }),
|
| 54 |
-
python: getSnippet({ lang: "python", tokenStr, conversation }),
|
| 55 |
-
http: getSnippet({ lang: "curl", tokenStr, conversation }),
|
| 56 |
-
} as Record<Language, GetInferenceSnippetReturn>;
|
| 57 |
-
|
| 58 |
// { javascript: 0, python: 0, http: 0 } at first
|
| 59 |
-
const selectedSnippetIdxByLang: Record<Language, number> =
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
);
|
| 64 |
-
$: selectedSnippet = snippetsByLang[lang][selectedSnippetIdxByLang[lang]];
|
| 65 |
|
| 66 |
type InstallInstructions = {
|
| 67 |
title: string;
|
| 68 |
content: string;
|
| 69 |
docs: string;
|
| 70 |
};
|
| 71 |
-
$: installInstructions = (function getInstallInstructions(): InstallInstructions | undefined {
|
| 72 |
-
if (lang === "javascript") {
|
| 73 |
-
const isHugging = selectedSnippet?.client.includes("hugging");
|
| 74 |
-
const toInstall = isHugging ? "@huggingface/inference" : "openai";
|
| 75 |
-
const docs = isHugging
|
| 76 |
-
? "https://huggingface.co/docs/huggingface.js/inference/README"
|
| 77 |
-
: "https://platform.openai.com/docs/libraries";
|
| 78 |
-
return {
|
| 79 |
-
title: `Install ${toInstall}`,
|
| 80 |
-
content: `npm install --save ${toInstall}`,
|
| 81 |
-
docs,
|
| 82 |
-
};
|
| 83 |
-
} else if (lang === "python") {
|
| 84 |
-
const isHugging = selectedSnippet?.client.includes("hugging");
|
| 85 |
-
const toInstall = isHugging ? "huggingface_hub" : "openai";
|
| 86 |
-
const docs = isHugging
|
| 87 |
-
? "https://huggingface.co/docs/huggingface_hub/guides/inference"
|
| 88 |
-
: "https://platform.openai.com/docs/libraries";
|
| 89 |
-
return {
|
| 90 |
-
title: `Install the latest`,
|
| 91 |
-
content: `pip install --upgrade ${toInstall}`,
|
| 92 |
-
docs,
|
| 93 |
-
};
|
| 94 |
-
}
|
| 95 |
-
})();
|
| 96 |
|
| 97 |
function getTokenStr(showToken: boolean) {
|
| 98 |
if ($token.value && showToken) {
|
|
@@ -132,6 +104,40 @@
|
|
| 132 |
},
|
| 133 |
};
|
| 134 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
</script>
|
| 136 |
|
| 137 |
<div class="px-2 pt-2">
|
|
@@ -142,7 +148,7 @@
|
|
| 142 |
{#each entries(labelsByLanguage) as [language, label]}
|
| 143 |
<li>
|
| 144 |
<button
|
| 145 |
-
|
| 146 |
class="inline-block rounded-t-lg border-b-2 p-4 {lang === language
|
| 147 |
? 'border-black text-black dark:border-blue-500 dark:text-blue-500'
|
| 148 |
: 'border-transparent hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300'}"
|
|
@@ -152,7 +158,7 @@
|
|
| 152 |
{/each}
|
| 153 |
<li class="ml-auto self-center max-sm:hidden">
|
| 154 |
<button
|
| 155 |
-
|
| 156 |
dispatch("closeCode");
|
| 157 |
}}
|
| 158 |
class="flex size-7 items-center justify-center rounded-lg px-3 py-2.5 text-xs font-medium text-gray-900 focus:ring-4 focus:ring-gray-100 focus:outline-hidden 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"
|
|
@@ -172,7 +178,7 @@
|
|
| 172 |
{isActive
|
| 173 |
? 'bg-black text-gray-100 dark:border-gray-500 dark:bg-gray-700 dark:text-white'
|
| 174 |
: 'text-gray-500 hover:text-gray-600 dark:border-gray-600 dark:hover:text-gray-400'}"
|
| 175 |
-
|
| 176 |
>
|
| 177 |
{/each}
|
| 178 |
</div>
|
|
|
|
| 10 |
import { token } from "$lib/stores/token.js";
|
| 11 |
import { entries, fromEntries, keys } from "$lib/utils/object.js";
|
| 12 |
import type { InferenceProvider } from "@huggingface/inference";
|
|
|
|
| 13 |
import IconExternal from "~icons/carbon/arrow-up-right";
|
| 14 |
+
import IconCopyCode from "~icons/carbon/copy";
|
| 15 |
import { getInferenceSnippet, type GetInferenceSnippetReturn, type InferenceSnippetLanguage } from "./utils.js";
|
| 16 |
|
| 17 |
hljs.registerLanguage("javascript", javascript);
|
| 18 |
hljs.registerLanguage("python", python);
|
| 19 |
hljs.registerLanguage("http", http);
|
| 20 |
|
| 21 |
+
interface Props {
|
| 22 |
+
conversation: Conversation;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
let { conversation }: Props = $props();
|
| 26 |
|
| 27 |
const dispatch = createEventDispatcher<{ closeCode: void }>();
|
| 28 |
|
|
|
|
| 33 |
} as const satisfies Record<string, string>;
|
| 34 |
type Language = keyof typeof labelsByLanguage;
|
| 35 |
|
| 36 |
+
let lang: Language = $state("javascript");
|
| 37 |
+
let showToken = $state(false);
|
|
|
|
|
|
|
| 38 |
|
| 39 |
type GetSnippetArgs = {
|
| 40 |
tokenStr: string;
|
|
|
|
| 51 |
});
|
| 52 |
}
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
// { javascript: 0, python: 0, http: 0 } at first
|
| 55 |
+
const selectedSnippetIdxByLang: Record<Language, number> = $state(
|
| 56 |
+
fromEntries(
|
| 57 |
+
keys(labelsByLanguage).map(lang => {
|
| 58 |
+
return [lang, 0];
|
| 59 |
+
})
|
| 60 |
+
)
|
| 61 |
);
|
|
|
|
| 62 |
|
| 63 |
type InstallInstructions = {
|
| 64 |
title: string;
|
| 65 |
content: string;
|
| 66 |
docs: string;
|
| 67 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
function getTokenStr(showToken: boolean) {
|
| 70 |
if ($token.value && showToken) {
|
|
|
|
| 104 |
},
|
| 105 |
};
|
| 106 |
}
|
| 107 |
+
let tokenStr = $derived(getTokenStr(showToken));
|
| 108 |
+
let snippetsByLang = $derived({
|
| 109 |
+
javascript: getSnippet({ lang: "js", tokenStr, conversation }),
|
| 110 |
+
python: getSnippet({ lang: "python", tokenStr, conversation }),
|
| 111 |
+
http: getSnippet({ lang: "curl", tokenStr, conversation }),
|
| 112 |
+
} as Record<Language, GetInferenceSnippetReturn>);
|
| 113 |
+
let selectedSnippet = $derived(snippetsByLang[lang][selectedSnippetIdxByLang[lang]]);
|
| 114 |
+
let installInstructions = $derived(
|
| 115 |
+
(function getInstallInstructions(): InstallInstructions | undefined {
|
| 116 |
+
if (lang === "javascript") {
|
| 117 |
+
const isHugging = selectedSnippet?.client.includes("hugging");
|
| 118 |
+
const toInstall = isHugging ? "@huggingface/inference" : "openai";
|
| 119 |
+
const docs = isHugging
|
| 120 |
+
? "https://huggingface.co/docs/huggingface.js/inference/README"
|
| 121 |
+
: "https://platform.openai.com/docs/libraries";
|
| 122 |
+
return {
|
| 123 |
+
title: `Install ${toInstall}`,
|
| 124 |
+
content: `npm install --save ${toInstall}`,
|
| 125 |
+
docs,
|
| 126 |
+
};
|
| 127 |
+
} else if (lang === "python") {
|
| 128 |
+
const isHugging = selectedSnippet?.client.includes("hugging");
|
| 129 |
+
const toInstall = isHugging ? "huggingface_hub" : "openai";
|
| 130 |
+
const docs = isHugging
|
| 131 |
+
? "https://huggingface.co/docs/huggingface_hub/guides/inference"
|
| 132 |
+
: "https://platform.openai.com/docs/libraries";
|
| 133 |
+
return {
|
| 134 |
+
title: `Install the latest`,
|
| 135 |
+
content: `pip install --upgrade ${toInstall}`,
|
| 136 |
+
docs,
|
| 137 |
+
};
|
| 138 |
+
}
|
| 139 |
+
})()
|
| 140 |
+
);
|
| 141 |
</script>
|
| 142 |
|
| 143 |
<div class="px-2 pt-2">
|
|
|
|
| 148 |
{#each entries(labelsByLanguage) as [language, label]}
|
| 149 |
<li>
|
| 150 |
<button
|
| 151 |
+
onclick={() => (lang = language)}
|
| 152 |
class="inline-block rounded-t-lg border-b-2 p-4 {lang === language
|
| 153 |
? 'border-black text-black dark:border-blue-500 dark:text-blue-500'
|
| 154 |
: 'border-transparent hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300'}"
|
|
|
|
| 158 |
{/each}
|
| 159 |
<li class="ml-auto self-center max-sm:hidden">
|
| 160 |
<button
|
| 161 |
+
onclick={() => {
|
| 162 |
dispatch("closeCode");
|
| 163 |
}}
|
| 164 |
class="flex size-7 items-center justify-center rounded-lg px-3 py-2.5 text-xs font-medium text-gray-900 focus:ring-4 focus:ring-gray-100 focus:outline-hidden 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"
|
|
|
|
| 178 |
{isActive
|
| 179 |
? 'bg-black text-gray-100 dark:border-gray-500 dark:bg-gray-700 dark:text-white'
|
| 180 |
: 'text-gray-500 hover:text-gray-600 dark:border-gray-600 dark:hover:text-gray-400'}"
|
| 181 |
+
onclick={() => (selectedSnippetIdxByLang[lang] = idx)}>{client}</button
|
| 182 |
>
|
| 183 |
{/each}
|
| 184 |
</div>
|
src/lib/components/inference-playground/provider-select.svelte
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
import { cn } from "$lib/utils/cn.js";
|
| 6 |
import { createSelect, createSync } from "@melt-ui/svelte";
|
| 7 |
import IconCaret from "~icons/carbon/chevron-down";
|
| 8 |
-
import IconProvider from "../
|
| 9 |
|
| 10 |
export let conversation: Conversation;
|
| 11 |
let classes: string | undefined = undefined;
|
|
|
|
| 5 |
import { cn } from "$lib/utils/cn.js";
|
| 6 |
import { createSelect, createSync } from "@melt-ui/svelte";
|
| 7 |
import IconCaret from "~icons/carbon/chevron-down";
|
| 8 |
+
import IconProvider from "../icon-provider.svelte";
|
| 9 |
|
| 10 |
export let conversation: Conversation;
|
| 11 |
let classes: string | undefined = undefined;
|
src/lib/state/models.svelte.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { page } from "$app/state";
|
| 2 |
+
import type { ModelWithTokenizer } from "$lib/types.js";
|
| 3 |
+
|
| 4 |
+
export const models = $derived({ current: page.data.models as ModelWithTokenizer[] });
|