Spaces:
Sleeping
Sleeping
System message as part of Conversation
Browse filesFiles changed (3)
19 unmodified lines202122232425262728293031323334355 unmodified lines4142434445464713 unmodified lines616263646566676829 unmodified lines989910010110210310410510610710810952 unmodified lines16216316416516616716819 unmodified linesexport let models: ModelEntryWithTokenizer[];const startMessage: ChatCompletionInputMessage = { role: "user", content: "" };let conversation: Conversation = {model: models[0],config: defaultGenerationConfig,messages: [{ ...startMessage }],streaming: true,};let systemMessage: ChatCompletionInputMessage = { role: "system", content: "" };let hfToken: string | undefined = import.meta.env.VITE_HF_TOKEN;let viewCode = false;let showTokenModal = false;5 unmodified lines$: systemPromptSupported = isSystemPromptSupported(conversation.model);$: {if (!systemPromptSupported) {systemMessage = { role: "system", content: "" };}}13 unmodified lines}function reset() {systemMessage.content = "";conversation.messages = [{ ...startMessage }];}function abort() {29 unmodified linesconversation.messages = [...conversation.messages];}},abortController,systemMessage);} else {waitForNonStreaming = true;const newMessage = await handleNonStreamingResponse(hf, conversation, systemMessage);// check if the user did not abort the requestif (waitForNonStreaming) {conversation.messages = [...conversation.messages, newMessage];52 unmodified linesplaceholder={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></div>19 unmodified lines20212223242526272829303132333435365 unmodified lines4243444546474813 unmodified lines626364656667686929 unmodified lines9910010110210310410510610710810952 unmodified lines16216316416516616716819 unmodified linesexport let models: ModelEntryWithTokenizer[];const startMessageUser: ChatCompletionInputMessage = { role: "user", content: "" };const startMessageSystem: ChatCompletionInputMessage = { role: "system", content: "" };let conversation: Conversation = {model: models[0],config: defaultGenerationConfig,messages: [{ ...startMessageUser }],systemMessage: startMessageSystem,streaming: true,};let hfToken: string | undefined = import.meta.env.VITE_HF_TOKEN;let viewCode = false;let showTokenModal = false;5 unmodified lines$: systemPromptSupported = isSystemPromptSupported(conversation.model);$: {if (!systemPromptSupported) {conversation.systemMessage = { role: "system", content: "" };}}13 unmodified lines}function reset() {conversation.systemMessage.content = "";conversation.messages = [{ ...startMessageUser }];}function abort() {29 unmodified linesconversation.messages = [...conversation.messages];}},abortController);} else {waitForNonStreaming = true;const newMessage = await handleNonStreamingResponse(hf, conversation);// check if the user did not abort the requestif (waitForNonStreaming) {conversation.messages = [...conversation.messages, newMessage];52 unmodified linesplaceholder={systemPromptSupported? "Enter a custom prompt": "System prompt is not supported with the chosen model."}bind:value={conversation.systemMessage.content}class="absolute inset-x-0 bottom-0 h-full resize-none bg-transparent px-3 pt-10 text-sm outline-none"></textarea></div>
10 unmodified lines11121314151617181920212223242526279 unmodified lines3738394041424344454647484950515210 unmodified lineshf: HfInference,conversation: Conversation,onChunk: (content: string) => void,abortController: AbortController,systemMessage?: ChatCompletionInputMessage): Promise<void> {const messages = [...(isSystemPromptSupported(conversation.model) && systemMessage?.content?.length ? [systemMessage] : []),...conversation.messages,];let out = "";for await (const chunk of hf.chatCompletionStream({model: conversation.model.id,messages,temperature: conversation.config.temperature,max_tokens: conversation.config.maxTokens,9 unmodified linesexport async function handleNonStreamingResponse(hf: HfInference,conversation: Conversation,systemMessage?: ChatCompletionInputMessage): Promise<ChatCompletionInputMessage> {const messages = [...(isSystemPromptSupported(conversation.model) && systemMessage?.content?.length ? [systemMessage] : []),...conversation.messages,];const response = await hf.chatCompletion({model: conversation.model,messages,temperature: conversation.config.temperature,max_tokens: conversation.config.maxTokens,10 unmodified lines11121314151617181920212223242526279 unmodified lines3738394041424344454647484950515210 unmodified lineshf: HfInference,conversation: Conversation,onChunk: (content: string) => void,abortController: AbortController): Promise<void> {const { model, systemMessage } = conversation;const messages = [...(isSystemPromptSupported(model) && systemMessage.content?.length ? [systemMessage] : []),...conversation.messages,];let out = "";for await (const chunk of hf.chatCompletionStream({model: model.id,messages,temperature: conversation.config.temperature,max_tokens: conversation.config.maxTokens,9 unmodified linesexport async function handleNonStreamingResponse(hf: HfInference,conversation: Conversation): Promise<ChatCompletionInputMessage> {const { model, systemMessage } = conversation;const messages = [...(isSystemPromptSupported(model) && systemMessage.content?.length ? [systemMessage] : []),...conversation.messages,];const response = await hf.chatCompletion({model: model.id,messages,temperature: conversation.config.temperature,max_tokens: conversation.config.maxTokens,
5 unmodified lines678910115 unmodified linesmodel: ModelEntryWithTokenizer;config: GenerationConfig;messages: ChatCompletionInputMessage[];streaming: boolean;};5 unmodified lines67891011125 unmodified linesmodel: ModelEntryWithTokenizer;config: GenerationConfig;messages: ChatCompletionInputMessage[];systemMessage: ChatCompletionInputMessage;streaming: boolean;};
src/lib/components/InferencePlayground/InferencePlayground.svelte+10-10
src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts+8-8
src/lib/components/InferencePlayground/types.ts+1