import { AnimusClient } from 'animus-client';
const client = new AnimusClient({
tokenProviderUrl: 'https://your-backend.com/api/get-animus-token',
chat: {
model: 'vivian-llama3.1-70b-1.0-fp8',
systemMessage: 'You are a helpful assistant.',
// Note: autoTurn must be false or undefined for streaming to work
autoTurn: false
}
});
try {
// Enable streaming in the request
const stream = await client.chat.completions({
messages: [
{ role: 'user', content: 'Write a short story about a robot learning to paint.' }
],
stream: true
});
let fullContent = '';
// Process each chunk as it arrives
for await (const chunk of stream) {
const delta = chunk.choices?.[0]?.delta?.content || '';
fullContent += delta;
// Update UI incrementally
updateChatDisplay(fullContent);
console.log('Streaming:', delta);
}
console.log('Stream complete. Final content:', fullContent);
} catch (error) {
console.error('Streaming error:', error);
}