Spaces:
Runtime error
Runtime error
Thomas G. Lopes commited on
Commit ·
631cc27
1
Parent(s): 95a0fb1
fix type check
Browse filesFiles changed (9)
- .github/workflows/lint-and-test.yml-3
- .prettierignore+14
- package.json+5-5
- pnpm-lock.yaml+20-33
- src/lib/components/InferencePlayground/InferencePlayground.svelte+13-14
- src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte+13-12
- src/lib/components/InferencePlayground/InferencePlaygroundMessage.svelte+2-2
- src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts+8-11
- src/lib/components/InferencePlayground/types.ts+4-2
30 unmodified lines31323334353634353630 unmodified lines ${{ runner.os }}-pnpm-store- - name: Install dependencies run: pnpm install --frozen-lockfile - name: "SvelteKit sync" run: | pnpm run sync - name: "Checking lint/format errors" run: | pnpm run lint1 unmodified line234567891011121314151617181 unmodified linepackage-lock.jsonpnpm-lock.yamlyarn.lock.pnpm-store
.DS_Storenode_modules/build/.svelte-kit/package.env.env.*!.env.example
# Ignore files for PNPM, NPM and YARNpnpm-lock.yamlyarn.lock5 unmodified lines678910111224 unmodified lines37383939404142434041424344455 unmodified lines "dev": "vite dev", "build": "vite build", "preview": "vite preview", "prepare": "svelte-kit sync || echo ''", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "lint": "prettier . --check . && eslint --ext .js,.ts,.svelte src/",24 unmodified lines }, "type": "module", "dependencies": { "@huggingface/hub": "^0.15.1", "@huggingface/inference": "^2.7.0", "@huggingface/tasks": "^0.10.22", "@tailwindcss/container-queries": "^0.1.1", "runed": "^0.23.4" "@huggingface/hub": "^1.0.1", "@huggingface/inference": "^3.5.1", "@huggingface/tasks": "^0.17.1", "@tailwindcss/container-queries": "^0.1.1" }}8 unmodified lines910111213121314151615161718191819202122232425232425225 unmodified lines2512522532572582542552562572612622582592602612652662622632642682692652662672682691122 unmodified lines13921393139413981399140014011402139513961397369 unmodified lines176717681769177817701771178017721773178217741775178417761777178617781779178817801781178217831052 unmodified lines283628372838284728482849285028512839284028418 unmodified lines .: dependencies: '@huggingface/hub': specifier: ^0.15.1 version: 0.15.2 specifier: ^1.0.1 version: 1.0.1 '@huggingface/inference': specifier: ^2.7.0 version: 2.8.1 specifier: ^3.5.1 version: 3.5.1 '@huggingface/tasks': specifier: ^0.10.22 version: 0.10.22 specifier: ^0.17.1 version: 0.17.1 '@tailwindcss/container-queries': specifier: ^0.1.1 version: 0.1.1(tailwindcss@3.4.17) runed: specifier: ^0.23.4 version: 0.23.4(svelte@4.2.19) devDependencies: '@sveltejs/adapter-auto': specifier: ^3.2.2225 unmodified lines resolution: {integrity: sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
'@huggingface/hub@0.15.2': resolution: {integrity: sha512-MKu7RTkEBp8tvn0ZhBIjQwC1CHA+q8rzTYXAVklOTJEo/SZwCewVL+IcEuj4CoA5DnJ1IhyjkBquxN2dFVnEHg==} '@huggingface/hub@1.0.1': resolution: {integrity: sha512-wogGVETaNUV/wYBkny0uQD48L0rK9cttVtbaA1Rw/pGCuSYoZ8YlvTV6zymsGJfXaxQU8zup0aOR2XLIf6HVfg==} engines: {node: '>=18'}
'@huggingface/inference@2.8.1': resolution: {integrity: sha512-EfsNtY9OR6JCNaUa5bZu2mrs48iqeTz0Gutwf+fU0Kypx33xFQB4DKMhp8u4Ee6qVbLbNWvTHuWwlppLQl4p4Q==} '@huggingface/inference@3.5.1': resolution: {integrity: sha512-NwTj5MS1eb4HfSp/O1/PyH1bEhTXl/iFh/K+8yYkUTHtK4AHXi/NDsV2LblhACaTEIhpOpYswL9cZx7z3y1tlg==} engines: {node: '>=18'}
'@huggingface/tasks@0.10.22': resolution: {integrity: sha512-sCtp+A6sq6NXoUU7NXuXWoVNNjKddk1GTQIh3cJ6illF8S4zmFoerCVRvFf19BdgICGvF+RVZiv9sGGK9KRDTg==} '@huggingface/tasks@0.15.9': resolution: {integrity: sha512-cbnZcpMHKdhURWIplVP4obHxAZcxjyRm0zI7peTPksZN4CtIOMmJC4ZqGEymo0lk+0VNkXD7ULwFJ3JjT/VpkQ==}
'@huggingface/tasks@0.12.30': resolution: {integrity: sha512-A1ITdxbEzx9L8wKR8pF7swyrTLxWNDFIGDLUWInxvks2ruQ8PLRBZe8r0EcjC3CDdtlj9jV1V4cgV35K/iy3GQ==} '@huggingface/tasks@0.17.1': resolution: {integrity: sha512-kN5F/pzwxtmdZ0jORumNyegNKOX/ciU5G/DMZcqK3SJShod4C6yfvBRCMn5sEDzanxtU8VjX+7TaInQFmmU8Nw==}
'@humanwhocodes/config-array@0.13.0': resolution: {integrity: sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==}1122 unmodified lines run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
runed@0.23.4: resolution: {integrity: sha512-9q8oUiBYeXIDLWNK5DfCWlkL0EW3oGbk845VdKlPeia28l751VpfesaB/+7pI6rnbx1I6rqoZ2fZxptOJLxILA==} peerDependencies: svelte: ^5.7.0
sade@1.8.1: resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} engines: {node: '>=6'}369 unmodified lines
'@eslint/js@8.57.1': {}
'@huggingface/hub@0.15.2': '@huggingface/hub@1.0.1': dependencies: '@huggingface/tasks': 0.12.30 '@huggingface/tasks': 0.15.9
'@huggingface/inference@2.8.1': '@huggingface/inference@3.5.1': dependencies: '@huggingface/tasks': 0.12.30 '@huggingface/tasks': 0.17.1
'@huggingface/tasks@0.10.22': {} '@huggingface/tasks@0.15.9': {}
'@huggingface/tasks@0.12.30': {} '@huggingface/tasks@0.17.1': {}
'@humanwhocodes/config-array@0.13.0': dependencies:1052 unmodified lines dependencies: queue-microtask: 1.2.3
runed@0.23.4(svelte@4.2.19): dependencies: esm-env: 1.2.2 svelte: 4.2.19
sade@1.8.1: dependencies: mri: 1.2.01232345679891011121213141516171819202122232425192021222324262627272829313031323433343536<script lang="ts"> import type { Conversation, ModelEntryWithTokenizer, Session } from "./types"; import type { ChatCompletionInputMessage } from "@huggingface/tasks"; import type { Conversation, ConversationMessage, ModelEntryWithTokenizer, Session } from "./types";
import { page } from "$app/stores"; import { defaultGenerationConfig } from "./generationConfigSettings"; import { createHfInference, handleStreamingResponse, FEATURED_MODELS_IDS, handleNonStreamingResponse, handleStreamingResponse, isSystemPromptSupported, FEATURED_MODELS_IDS, } from "./inferencePlaygroundUtils";
import { goto } from "$app/navigation"; import { onDestroy, onMount } from "svelte"; import IconCode from "../Icons/IconCode.svelte"; import IconCompare from "../Icons/IconCompare.svelte"; import IconDelete from "../Icons/IconDelete.svelte"; import IconInfo from "../Icons/IconInfo.svelte"; import IconThrashcan from "../Icons/IconThrashcan.svelte"; import PlaygroundConversation from "./InferencePlaygroundConversation.svelte"; import PlaygroundConversationHeader from "./InferencePlaygroundConversationHeader.svelte"; import GenerationConfig, { defaultSystemMessage } from "./InferencePlaygroundGenerationConfig.svelte"; import HFTokenModal from "./InferencePlaygroundHFTokenModal.svelte"; import ModelSelector from "./InferencePlaygroundModelSelector.svelte"; import PlaygroundConversation from "./InferencePlaygroundConversation.svelte"; import PlaygroundConversationHeader from "./InferencePlaygroundConversationHeader.svelte"; import IconDelete from "../Icons/IconDelete.svelte"; import IconCode from "../Icons/IconCode.svelte"; import IconInfo from "../Icons/IconInfo.svelte"; import IconCompare from "../Icons/IconCompare.svelte"; import ModelSelectorModal from "./InferencePlaygroundModelSelectorModal.svelte"; import IconThrashcan from "../Icons/IconThrashcan.svelte"; import { goto } from "$app/navigation";
export let models: ModelEntryWithTokenizer[];
const startMessageUser: ChatCompletionInputMessage = { role: "user", content: "" }; const startMessageUser: ConversationMessage = { role: "user", content: "" }; const modelIdsFromQueryParam = $page.url.searchParams.get("modelId")?.split(","); const modelsFromQueryParam = modelIdsFromQueryParam?.map(id => models.find(model => model.id === id)); const systemMessage: ChatCompletionInputMessage = { const systemMessage: ConversationMessage = { role: "system", content: modelIdsFromQueryParam ? (defaultSystemMessage?.[modelIdsFromQueryParam[0]] ?? "") : "", };84 unmodified lines85868788888990919293939495969742 unmodified lines14014114214214314414514664 unmodified lines21121221321321421521621753 unmodified lines27127227327327427427527627727813 unmodified lines29229329429429529529629729829939 unmodified lines33934034134134234234334434534616 unmodified lines36336436536536636636736836937084 unmodified lines messages.unshift(systemMessage); }
messages = messages.map(({ role, content }) => ({ const res = messages.map(({ role, content }) => ({ role, content: JSON.stringify(content).slice(1, -1), })); messages = res;
return messages; return res; }
function highlight(code: string, language: Language) {42 unmodified lines const newContent = chunk.choices[0].delta.content; out += newContent; console.log(newContent); } }}`, }); } else {64 unmodified lines const newContent = chunk.choices[0].delta.content; out += newContent; console.log(newContent); } }}`, }); } else {53 unmodified linesmessages = ${formattedMessages({ sep: ",\n\t", start: `[\n\t`, end: `\n]` })}
stream = client.chat.completions.create( model="${conversation.model.id}", messages=messages, model="${conversation.model.id}", messages=messages, ${formattedConfig({ sep: ",\n\t", start: "", end: "", connector: "=" })}, stream=True)13 unmodified linesmessages = ${formattedMessages({ sep: ",\n\t", start: `[\n\t`, end: `\n]` })}
completion = client.chat.completions.create( model="${conversation.model.id}", messages=messages, model="${conversation.model.id}", messages=messages, ${formattedConfig({ sep: ",\n\t", start: "", end: "", connector: "=" })})
39 unmodified linesmessages = ${formattedMessages({ sep: ",\n\t", start: `[\n\t`, end: `\n]` })}
stream = client.chat.completions.create( model="${conversation.model.id}", messages=messages, model="${conversation.model.id}", messages=messages, ${formattedConfig({ sep: ",\n\t", start: "", end: "", connector: "=" })}, stream=True)16 unmodified linesmessages = ${formattedMessages({ sep: ",\n\t", start: `[\n\t`, end: `\n]` })}
completion = client.chat.completions.create( model="${conversation.model.id}", messages=messages, model="${conversation.model.id}", messages=messages, ${formattedConfig({ sep: ",\n\t", start: "", end: "", connector: "=" })})
1223455678<script lang="ts"> import { type ChatCompletionInputMessage } from "@huggingface/tasks"; import { createEventDispatcher } from "svelte"; import type { ConversationMessage } from "./types";
export let message: ChatCompletionInputMessage; export let message: ConversationMessage; export let loading: boolean = false; export let autofocus: boolean = false;
1123420 unmodified lines25262728282930315 unmodified lines373839404041424344454647484950515253544748495051525354import { type ChatCompletionInputMessage } from "@huggingface/tasks";import { type ChatCompletionOutputMessage } from "@huggingface/tasks";import type { Conversation, ModelEntryWithTokenizer } from "./types";
import { HfInference } from "@huggingface/inference";20 unmodified lines messages, ...conversation.config, }, { signal: abortController.signal, use_cache: false } { signal: abortController.signal } )) { if (chunk.choices && chunk.choices.length > 0 && chunk.choices[0]?.delta?.content) { out += chunk.choices[0].delta.content;5 unmodified linesexport async function handleNonStreamingResponse( hf: HfInference, conversation: Conversation): Promise<{ message: ChatCompletionInputMessage; completion_tokens: number }> {): Promise<{ message: ChatCompletionOutputMessage; completion_tokens: number }> { const { model, systemMessage } = conversation; const messages = [ ...(isSystemPromptSupported(model) && systemMessage.content?.length ? [systemMessage] : []), ...conversation.messages, ];
const response = await hf.chatCompletion( { model: model.id, messages, ...conversation.config, }, { use_cache: false } ); const response = await hf.chatCompletion({ model: model.id, messages, ...conversation.config, });
if (response.choices && response.choices.length > 0) { const { message } = response.choices[0];1 unmodified line234567898910111213141 unmodified lineimport type { ModelEntry } from "@huggingface/hub";import type { ChatCompletionInputMessage } from "@huggingface/tasks";
export type ConversationMessage = Omit<ChatCompletionInputMessage, "content"> & { content?: string };
export type Conversation = { model: ModelEntryWithTokenizer; config: GenerationConfig; messages: ChatCompletionInputMessage[]; systemMessage: ChatCompletionInputMessage; messages: ConversationMessage[]; systemMessage: ConversationMessage; streaming: boolean;};
.github/workflows/lint-and-test.yml-3
.prettierignore+14
package.json+5-5
pnpm-lock.yaml+20-33
src/lib/components/InferencePlayground/InferencePlayground.svelte+13-14
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte+13-12
src/lib/components/InferencePlayground/InferencePlaygroundMessage.svelte+2-2
src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts+8-11
src/lib/components/InferencePlayground/types.ts+4-2