Spaces:
Runtime error
Runtime error
Imrpove models selector (#44)
Browse filesFiles changed (4)
7 unmodified lines891011121310 unmodified lines242526272829307 unmodified lineshandleStreamingResponse,handleNonStreamingResponse,isSystemPromptSupported,} from "./inferencePlaygroundUtils";import { onDestroy } from "svelte";10 unmodified linesconst startMessageSystem: ChatCompletionInputMessage = { role: "system", content: "" };let conversation: Conversation = {model: models[0],config: defaultGenerationConfig,messages: [{ ...startMessageUser }],systemMessage: startMessageSystem,7 unmodified lines89101112131410 unmodified lines252627282930317 unmodified lineshandleStreamingResponse,handleNonStreamingResponse,isSystemPromptSupported,FEATUED_MODELS_IDS,} from "./inferencePlaygroundUtils";import { onDestroy } from "svelte";10 unmodified linesconst startMessageSystem: ChatCompletionInputMessage = { role: "system", content: "" };let conversation: Conversation = {model: models.find(m => FEATUED_MODELS_IDS.includes(m.id)) ?? models[0],config: defaultGenerationConfig,messages: [{ ...startMessageUser }],systemMessage: startMessageSystem,
2 unmodified lines3456789101112131413 unmodified lines28293031323311 unmodified lines4546474849505152535455565758596061626364656667686970717273747576777879802 unmodified linesimport { createEventDispatcher } from "svelte";import IconSearch from "../Icons/IconSearch.svelte";import IconStar from "../Icons/IconStar.svelte";export let models: ModelEntryWithTokenizer[];let backdropEl: HTMLDivElement;const dispatch = createEventDispatcher<{ modelSelected: string; close: void }>();13 unmodified linesdispatch("close");}}</script><svelte:window on:keydown={handleKeydown} />11 unmodified linesautofocusclass="flex h-10 w-full rounded-md bg-transparent py-3 text-sm placeholder-gray-400 outline-none"placeholder="Search models ..."value=""/></div><div class="max-h-[300px] overflow-y-auto overflow-x-hidden"><div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Trending</div><div><div class="flex cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"><IconStar classNames="lucide lucide-star mr-2 h-4 w-4 text-yellow-400" /><span class="inline-flex items-center"><span class="text-gray-500">meta-llama</span><span class="mx-1 text-black">/</span><spanclass="text-black">Meta-Llama-3-70B-Instruct</span></span></div><div class="flex cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"><IconStar classNames="lucide lucide-star mr-2 h-4 w-4 text-yellow-400" /><span class="inline-flex items-center"><span class="text-gray-500">mistralai</span><span class="mx-1 text-black">/</span><spanclass="text-black">Mixtral-8x7B-Instruct-v0.1</span></span></div></div></div><div class="mx-1 h-px bg-gray-200"></div><div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Other Models</div><div>{#each models as model}{@const [nameSpace, modelName] = model.id.split("/")}<buttonclass="flex cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"2 unmodified lines34567891011121314151613 unmodified lines303132333435363738394041424344454611 unmodified lines585960616263646566676869707172737475767778798081828384858687888990919293942 unmodified linesimport { createEventDispatcher } from "svelte";import { FEATUED_MODELS_IDS } from "./inferencePlaygroundUtils";import IconSearch from "../Icons/IconSearch.svelte";import IconStar from "../Icons/IconStar.svelte";export let models: ModelEntryWithTokenizer[];let backdropEl: HTMLDivElement;let query = "";const dispatch = createEventDispatcher<{ modelSelected: string; close: void }>();13 unmodified linesdispatch("close");}}$: featuredModels = models.filter(m =>query? FEATUED_MODELS_IDS.includes(m.id) && m.id.toLocaleLowerCase().includes(query.toLocaleLowerCase().trim()): FEATUED_MODELS_IDS.includes(m.id));$: otherModels = models.filter(m =>query? !FEATUED_MODELS_IDS.includes(m.id) && m.id.toLocaleLowerCase().includes(query.toLocaleLowerCase().trim()): !FEATUED_MODELS_IDS.includes(m.id));</script><svelte:window on:keydown={handleKeydown} />11 unmodified linesautofocusclass="flex h-10 w-full rounded-md bg-transparent py-3 text-sm placeholder-gray-400 outline-none"placeholder="Search models ..."bind:value={query}/></div><div class="max-h-[300px] overflow-y-auto overflow-x-hidden"><div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Trending</div><div>{#each featuredModels as model}{@const [nameSpace, modelName] = model.id.split("/")}<buttonclass="flex cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"on:click={() => {dispatch("modelSelected", model.id);dispatch("close");}}><IconStar classNames="lucide lucide-star mr-2 h-4 w-4 text-yellow-400" /><span class="inline-flex items-center"><span class="text-gray-500">{nameSpace}</span><span class="mx-1 text-black">/</span><spanclass="text-black">{modelName}</span></span></button>{/each}</div></div><div class="mx-1 h-px bg-gray-200"></div><div class="p-1"><div class="px-2 py-1.5 text-xs font-medium text-gray-500">Other Models</div><div>{#each otherModels as model}{@const [nameSpace, modelName] = model.id.split("/")}<buttonclass="flex cursor-pointer items-center px-2 py-1.5 text-sm hover:bg-gray-100"
60 unmodified lines61626360 unmodified linesexport function isSystemPromptSupported(model: ModelEntryWithTokenizer) {return model.tokenizerConfig?.chat_template?.includes("system");}60 unmodified lines61626364656667686960 unmodified linesexport function isSystemPromptSupported(model: ModelEntryWithTokenizer) {return model.tokenizerConfig?.chat_template?.includes("system");}export const FEATUED_MODELS_IDS = ["meta-llama/Meta-Llama-3-70B-Instruct","google/gemma-1.1-7b-it","mistralai/Mixtral-8x7B-Instruct-v0.1",];
16 unmodified lines171819202122232416 unmodified linesconst promises = compatibleModels.map(async model => {const configUrl = `https://huggingface.co/${model.id}/raw/main/tokenizer_config.json`;const res = await fetch(configUrl);if (!res.ok) {return null; // Ignore failed requests by returning null}const tokenizerConfig = await res.json();16 unmodified lines1718192021222324252627282916 unmodified linesconst promises = compatibleModels.map(async model => {const configUrl = `https://huggingface.co/${model.id}/raw/main/tokenizer_config.json`;const res = await fetch(configUrl, {headers: {Authorization: `Bearer ${HF_TOKEN}`,},});if (!res.ok) {console.error("Error fetching tokenizer file", res.status, res.statusText);return null; // Ignore failed requests by returning null}const tokenizerConfig = await res.json();
src/lib/components/InferencePlayground/InferencePlayground.svelte+2-1
src/lib/components/InferencePlayground/InferencePlaygroundModelSelectorModal.svelte+31-17
src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts+6
src/routes/+page.server.ts+6-1