v2026.11.3
All Bundles
Bundle

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.

Inherits: EndPoint

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) ~ Chat

Parameters

NameTypeDescription
roleString"system", "user", "assistant" or "tool"
contentStringmessage text

Return

TypeDescription
Chatself for chaining

AddReply #

Records a reply in the history: an assistant message with its text and tool calls.

method : public : AddReply(reply:Reply) ~ Nil

Parameters

NameTypeDescription
replyReplyreply 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) ~ Chat

Parameters

NameTypeDescription
tool_nameStringname of the function that was called
contentStringthe function's result

Return

TypeDescription
Chatself for chaining

BuildRequest #

Builds the /api/chat request body for the current history.

method : public : BuildRequest(format:String, options:Options, tools:Vector<Tool>) ~ JsonElement

Parameters

NameTypeDescription
formatStringoutput format ("json"), or Nil
optionsOptionsoptions and request settings, or Nil
toolsVector<Tool>tool definitions, or Nil

Return

TypeDescription
JsonElementrequest body

GetLastReply #

Get the last reply received, with its tool calls, thinking and metadata

method : public : GetLastReply() ~ Reply

Return

TypeDescription
Replylast reply, or Nil

GetMessages #

Get the message history

method : public : GetMessages() ~ JsonElement

Return

TypeDescription
JsonElementmessages, as sent in the request

GetModel #

Get the model name

method : public : GetModel() ~ String

Return

TypeDescription
Stringmodel name

New # constructor

Constructor; asks the server to load the model

New(model:String)

Parameters

NameTypeDescription
modelStringmodel name (i.e. llama3, llava)

New # constructor

Constructor

New(model:String, preload:Bool)

Parameters

NameTypeDescription
modelStringmodel name (i.e. llama3, llava)
preloadBooltrue to ask the server to load the model now

Send #

Chat response from the model given an input

method : public : Send(message:String) ~ String

Parameters

NameTypeDescription
messageStringchat message

Return

TypeDescription
Stringchat 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) ~ String

Parameters

NameTypeDescription
messageStringchat message
optionsOptionsoptions and request settings

Return

TypeDescription
Stringchat 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>) ~ String

Parameters

NameTypeDescription
messageStringchat message
formatStringoutput format ("json" or Nil); for a JSON schema use Options->SetFormat
optionsOptionsoptions and request settings
toolsVector<Tool>tool definitions for function calling

Return

TypeDescription
Stringchat 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) ~ String

Parameters

NameTypeDescription
messageStringchat message
imageFileimage file

Return

TypeDescription
Stringchat 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[]) ~ String

Parameters

NameTypeDescription
messageStringchat query
imagesFile[]image files

Return

TypeDescription
Stringchat 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>) ~ Reply

Parameters

NameTypeDescription
messageStringuser message, or Nil to send the history as it stands
optionsOptionsoptions and request settings, or Nil
toolsVector<Tool>tool definitions, or Nil

Return

TypeDescription
Replyreply, 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>) ~ Reply

Parameters

NameTypeDescription
messageStringuser message
imagesFile[]image files, or Nil
optionsOptionsoptions and request settings, or Nil
toolsVector<Tool>tool definitions, or Nil

Return

TypeDescription
Replyreply, or Nil with the last error set