Ollama local LLM client. Runs models (Llama, Mistral, Phi, Qwen, etc.) locally via the Ollama server. Supports text generation, chat sessions with tool calling, structured (JSON schema) output, thinking models, images, batch embeddings and model management. Every request completes before returning -- responses are not streamed, so a long generation produces nothing until it finishes. Compile with -lib ollama.
Chat
Ollama chat client. The session keeps the message history, including tool calls and tool results.
Example
chat := Chat->New("llama3");
chat->AddMessage("system", "Answer in one sentence.");
chat->Send("How many people live in San Pablo, CA?")->PrintLine();
chat->Send("What are the major landmarks?")->PrintLine();Operations
AddMessage #
Adds a message to the history without sending it (e.g. a "system" prompt)
method : public : AddMessage(role:String, content:String) ~ ChatParameters
| Name | Type | Description |
|---|---|---|
| role | String | "system", "user", "assistant" or "tool" |
| content | String | message text |
Return
| Type | Description |
|---|---|
| Chat | self for chaining |
AddReply #
Records a reply in the history: an assistant message with its text and tool calls.
method : public : AddReply(reply:Reply) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| reply | Reply | reply to record |
AddToolResult #
Adds the result of a tool call to the history, as a "tool" message. Send it with SendReply(Nil, ...).
method : public : AddToolResult(tool_name:String, content:String) ~ ChatParameters
| Name | Type | Description |
|---|---|---|
| tool_name | String | name of the function that was called |
| content | String | the function's result |
Return
| Type | Description |
|---|---|
| Chat | self for chaining |
BuildRequest #
Builds the /api/chat request body for the current history.
method : public : BuildRequest(format:String, options:Options, tools:Vector<Tool>) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| format | String | output format ("json"), or Nil |
| options | Options | options and request settings, or Nil |
| tools | Vector<Tool> | tool definitions, or Nil |
Return
| Type | Description |
|---|---|
| JsonElement | request body |
GetLastReply #
Get the last reply received, with its tool calls, thinking and metadata
method : public : GetLastReply() ~ ReplyReturn
| Type | Description |
|---|---|
| Reply | last reply, or Nil |
GetMessages #
Get the message history
method : public : GetMessages() ~ JsonElementReturn
| Type | Description |
|---|---|
| JsonElement | messages, as sent in the request |
GetModel #
Get the model name
method : public : GetModel() ~ StringReturn
| Type | Description |
|---|---|
| String | model name |
New # constructor
Constructor; asks the server to load the model
New(model:String)Parameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
New # constructor
Constructor
New(model:String, preload:Bool)Parameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| preload | Bool | true to ask the server to load the model now |
Send #
Chat response from the model given an input
method : public : Send(message:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| message | String | chat message |
Return
| Type | Description |
|---|---|
| String | chat response, or Nil with the last error set |
Example
chat := Chat->New("llama3");
chat->Send("What year did the Berlin Wall fall?")->PrintLine();
chat->Send("Who was the US president at the time?")->PrintLine();Send #
Chat response with options
method : public : Send(message:String, options:Options) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| message | String | chat message |
| options | Options | options and request settings |
Return
| Type | Description |
|---|---|
| String | chat response, or Nil with the last error set |
Example
opts := Options->New()->SetTemperature(0.5);
chat := Chat->New("llama3");
chat->Send("Write a haiku about mountains.", opts)->PrintLine();Send #
Chat response with format, options and tools. When the model calls a tool the text is empty; GetLastReply()->GetToolCalls() has the calls.
method : public : Send(message:String, format:String, options:Options, tools:Vector<Tool>) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| message | String | chat message |
| format | String | output format ("json" or Nil); for a JSON schema use Options->SetFormat |
| options | Options | options and request settings |
| tools | Vector<Tool> | tool definitions for function calling |
Return
| Type | Description |
|---|---|
| String | chat response, or Nil with the last error set |
Example
opts := Options->New()->SetTemperature(0.0);
chat := Chat->New("llama3");
json_reply := chat->Send("List three colors as JSON.", "json", opts, Nil);
json_reply->PrintLine();Send #
Chat response from the model given an input
method : public : Send(message:String, image:File) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| message | String | chat message |
| image | File | image file |
Return
| Type | Description |
|---|---|
| String | chat response, or Nil with the last error set |
Example
chat := Chat->New("llava");
image := System.IO.Filesystem.File->New("diagram.png");
chat->Send("What does this diagram show?", image)->PrintLine();Send #
Chat response from the model given an input
method : public : Send(message:String, images:File[]) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| message | String | chat query |
| images | File[] | image files |
Return
| Type | Description |
|---|---|
| String | chat response, or Nil with the last error set |
SendReply #
Sends a message and returns the full reply, including tool calls. When the reply has tool calls, run them, add each result with AddToolResult and call SendReply(Nil, ...) to get the model's answer.
method : public : SendReply(message:String, options:Options, tools:Vector<Tool>) ~ ReplyParameters
| Name | Type | Description |
|---|---|---|
| message | String | user message, or Nil to send the history as it stands |
| options | Options | options and request settings, or Nil |
| tools | Vector<Tool> | tool definitions, or Nil |
Return
| Type | Description |
|---|---|
| Reply | reply, or Nil with the last error set (the message is then not kept in the history) |
Example
params := JsonParser->TextToElement("{\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\"}},\"required\":[\"city\"]}");
tools := Vector->New()<Tool>;
tools->AddBack(Tool->New("get_weather", "Get the weather for a city", params));
chat := Chat->New("qwen3");
reply := chat->SendReply("What is the weather in Paris?", Nil, tools);
while(reply <> Nil & reply->HasToolCalls()) {
each(call in reply->GetToolCalls()) {
city := call->GetArgument("city");
chat->AddToolResult(call->GetName(), "18C and sunny in {$city}");
};
reply := chat->SendReply(Nil, Nil, tools);
};
reply->GetText()->PrintLine();SendReply #
Sends a message with images and returns the full reply
method : public : SendReply(message:String, images:File[], options:Options, tools:Vector<Tool>) ~ ReplyParameters
| Name | Type | Description |
|---|---|---|
| message | String | user message |
| images | File[] | image files, or Nil |
| options | Options | options and request settings, or Nil |
| tools | Vector<Tool> | tool definitions, or Nil |
Return
| Type | Description |
|---|---|
| Reply | reply, or Nil with the last error set |