Spaces:
Runtime error
Runtime error
Check if model support system prompt (#26)
Browse filesFiles changed (2)
1234465678910 unmodified lines202122232324252613 unmodified lines404142434445464768 unmodified lines11611711811711912012112212312412595 unmodified lines221222223224225226220227228229230224231232233234235236<script lang="ts"> import { createHfInference, prepareRequestMessages, handleStreamingResponse, handleNonStreamingResponse handleNonStreamingResponse, isSystemPromptSupported } from './inferencePlaygroundUtils'; import PlaygroundOptions from './InferencePlaygroundGenerationConfig.svelte'; import PlaygroundTokenModal from './InferencePlaygroundHFTokenModal.svelte';10 unmodified lines let conversations: Conversation[] = [ { id: String(Math.random()), model: '01-ai/Yi-1.5-34B-Chat', model: models[0], config: { temperature: 0.5, maxTokens: 2048, streaming: true }, messages: startMessages }13 unmodified lines let abortControllers: AbortController[] = []; let waitForNonStreaming = true;
$: systemPromptSupported = isSystemPromptSupported(conversations[0].model);
onDestroy(() => { for (const abortController of abortControllers) { abortController.abort();68 unmodified lines async function runInference(conversation: Conversation) { const startTime = performance.now(); const hf = createHfInference(hfToken); const requestMessages = prepareRequestMessages(systemMessage, conversation.messages); 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"> <div class="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">SYSTEM</div> <div class="pb-2 text-sm font-semibold uppercase">system</div> <textarea name="" id="" placeholder="Enter a custom prompt" 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>123456788910111213149101147 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 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');}
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