Streaming Responses
Response streaming can be enabled by setting stream: true
, modifying function calls to return an AsyncGenerator
where each part is an object in the stream.
const ollama = useOllama()
const message = { role: 'user', content: 'Why is the sky blue?' }
const response = await ollama.chat({ model: 'llama3.1', messages: [message], stream: true })
for await (const part of response) {
process.stdout.write(part.message.content)
}