Spaces:
Runtime error
Runtime error
Check if model support system prompt (#26)
Browse filesFiles changed (2)
12345678910 unmodified lines2021222324252613 unmodified lines40414243444568 unmodified lines11411511611711811912095 unmodified lines216217218219220221222223224225226227<script lang="ts">import {createHfInference,prepareRequestMessages,handleStreamingResponse,handleNonStreamingResponse} from './inferencePlaygroundUtils';import PlaygroundOptions from './InferencePlaygroundGenerationConfig.svelte';import PlaygroundTokenModal from './InferencePlaygroundHFTokenModal.svelte';10 unmodified lineslet conversations: Conversation[] = [{id: String(Math.random()),model: '01-ai/Yi-1.5-34B-Chat',config: { temperature: 0.5, maxTokens: 2048, streaming: true },messages: startMessages}13 unmodified lineslet abortControllers: AbortController[] = [];let waitForNonStreaming = true;onDestroy(() => {for (const abortController of abortControllers) {abortController.abort();68 unmodified linesasync function runInference(conversation: Conversation) {const startTime = performance.now();const hf = createHfInference(hfToken);const requestMessages = prepareRequestMessages(systemMessage, conversation.messages);if (conversation.config.streaming) {const streamingMessage = { role: 'assistant', content: '' };95 unmodified lines<div class=" flex flex-col overflow-y-auto py-3 pr-3"><divclass="relative flex flex-1 flex-col gap-6 overflow-y-hidden rounded-r-xl border-x border-y border-gray-200/80 bg-gradient-to-b from-white via-white p-3 shadow-sm dark:border-white/5 dark:from-gray-800/40 dark:via-gray-800/40"><div class="pb-2 text-sm font-semibold">SYSTEM</div><textareaname=""id=""placeholder="Enter a custom prompt"bind:value={systemMessage.content}class="absolute inset-x-0 bottom-0 h-full resize-none bg-transparent px-3 pt-10 text-sm outline-none"></textarea>12345678910 unmodified lines2021222324252613 unmodified lines404142434445464768 unmodified lines11611711811912012112212312412595 unmodified lines221222223224225226227228229230231232233234235236<script lang="ts">import {createHfInference,handleStreamingResponse,handleNonStreamingResponse,isSystemPromptSupported} from './inferencePlaygroundUtils';import PlaygroundOptions from './InferencePlaygroundGenerationConfig.svelte';import PlaygroundTokenModal from './InferencePlaygroundHFTokenModal.svelte';10 unmodified lineslet conversations: Conversation[] = [{id: String(Math.random()),model: models[0],config: { temperature: 0.5, maxTokens: 2048, streaming: true },messages: startMessages}13 unmodified lineslet abortControllers: AbortController[] = [];let waitForNonStreaming = true;$: systemPromptSupported = isSystemPromptSupported(conversations[0].model);onDestroy(() => {for (const abortController of abortControllers) {abortController.abort();68 unmodified linesasync function runInference(conversation: Conversation) {const startTime = performance.now();const hf = createHfInference(hfToken);const requestMessages = [...(systemPromptSupported && systemMessage?.content?.length ? [systemMessage] : []),...conversation.messages];if (conversation.config.streaming) {const streamingMessage = { role: 'assistant', content: '' };95 unmodified lines<div class=" flex flex-col overflow-y-auto py-3 pr-3"><divclass="relative flex flex-1 flex-col gap-6 overflow-y-hidden rounded-r-xl border-x border-y border-gray-200/80 bg-gradient-to-b from-white via-white p-3 shadow-sm dark:border-white/5 dark:from-gray-800/40 dark:via-gray-800/40"class:pointer-events-none={!systemPromptSupported}class:opacity-70={!systemPromptSupported}><div class="pb-2 text-sm font-semibold uppercase">system</div><textareaname=""id=""placeholder={systemPromptSupported? 'Enter a custom prompt': 'System prompt is not supported with the chosen model.'}bind:value={systemMessage.content}class="absolute inset-x-0 bottom-0 h-full resize-none bg-transparent px-3 pt-10 text-sm outline-none"></textarea>
123456789101112131415161747 unmodified lines656667import { type ChatCompletionInputMessage } from '@huggingface/tasks';import { HfInference } from '@huggingface/inference';export function createHfInference(token: string): HfInference {return new HfInference(token);}export function prepareRequestMessages(systemMessage: ChatCompletionInputMessage,messages: ChatCompletionInputMessage[]): ChatCompletionInputMessage[] {return [...(systemMessage.content.length ? [systemMessage] : []), ...messages];}export async function handleStreamingResponse(hf: HfInference,model: string,47 unmodified lines}throw new Error('No response from the model');}123456789101147 unmodified lines59606162636465import { type ChatCompletionInputMessage } from '@huggingface/tasks';import { HfInference } from '@huggingface/inference';import type { ModelEntryWithTokenizer } from '$lib/types';export function createHfInference(token: string): HfInference {return new HfInference(token);}export async function handleStreamingResponse(hf: HfInference,model: string,47 unmodified lines}throw new Error('No response from the model');}export function isSystemPromptSupported(model: ModelEntryWithTokenizer) {return model.tokenizerConfig.chat_template?.includes('system');}
src/lib/components/InferencePlayground/InferencePlayground.svelte+15-6
src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts+5-7