OllamaClient.chatStream

Streaming chat — calls onChunk for every assistant token.

Each chunk contains "message": {"role": "assistant", "content": "<token>"}. The final chunk has "done": true and carries usage metadata.

class OllamaClient
@safe
void
chatStream
(
string model
,,,
Tool[] tools = null
,
JSONValue format = JSONValue.init
,
string keepAlive = null
,)

Parameters

model string

Model name.

messages Message[]

Conversation history.

onChunk StreamCallback

Callback invoked per chunk; must be @safe.

tools Tool[]

Optional tool definitions.

format JSONValue

Structured output schema or JSONValue("json").

keepAlive string

How long to keep the model loaded.

opts OllamaOptions

Typed generation options.

Meta