Spaces:
Runtime error
Runtime error
Implemented chat completion streaming functionality in the Playground component.
Browse files62 unmodified lines636465666667686970717273747576777868697071727374757662 unmodified lines try { const hf = new HfInference(hfToken);
const stream = await hf.textGenerationStream({ for await (const chunk of hf.chatCompletionStream({ model: currentModel, inputs: messages.map(m => m.content).join('\n'), parameters: { max_new_tokens: maxTokens, temperature: temperature, return_full_text: false } });
for await (const response of stream) { if (streamingMessage) { streamingMessage.content += response.token.text; messages: messages.map(({ role, content }) => ({ role, content })), temperature: temperature, max_tokens: maxTokens })) { if (streamingMessage && chunk.choices[0]?.delta?.content) { streamingMessage.content += chunk.choices[0].delta.content; messages = [...messages]; } }src/lib/components/Playground/Playground.svelte+7-12