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.
Completion
Ollama model interactions
Example
prompt := "What number is this?";
file := System.IO.Filesystem.File->New("../gemini/thirteen.png");
Completion->Generate("llava", prompt, file)->PrintLine();Operations
BuildGenerateRequest # function
Builds the /api/generate request body every Generate overload sends.
function : BuildGenerateRequest(model:String, prompt:String, format:String, options:Options, images:File[]) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name |
| prompt | String | prompt |
| format | String | output format ("json"), or Nil |
| options | Options | options and request settings, or Nil |
| images | File[] | image files, or Nil |
Return
| Type | Description |
|---|---|
| JsonElement | request body, or Nil with the last error set if an image cannot be read |
Generate # function
Generates a response from the model given an input
function : Generate(model:String, prompt:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
Return
| Type | Description |
|---|---|
| String | query response, or Nil with the last error set |
Example
response := Completion->Generate("llama3", "What is the capital of France?");
response->PrintLine();Generate # function
Generates a response from the model given an input with options
function : Generate(model:String, prompt:String, options:Options) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
| options | Options | options and request settings (temperature, top_p, format, think, etc.) |
Return
| Type | Description |
|---|---|
| String | query response, or Nil with the last error set |
Example
opts := Options->New()->SetTemperature(0.3)->SetTopP(0.85);
response := Completion->Generate("llama3", "Summarize quantum entanglement briefly.", opts);
response->PrintLine();Generate # function
Generates a response from the model given an input
function : Generate(model:String, prompt:String, format:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
| format | String | output format ("json") |
Return
| Type | Description |
|---|---|
| String | query response, or Nil with the last error set |
Generate # function
Generates a response from the model given an input
function : Generate(model:String, prompt:String, format:String, options:Options) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
| format | String | output format ("json"); for a JSON schema use Options->SetFormat |
| options | Options | options and request settings, or Nil |
Return
| Type | Description |
|---|---|
| String | query response, or Nil with the last error set |
Generate # function
Generates a response from the model given an input
function : Generate(model:String, prompt:String, image:File) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
| image | File | image file |
Return
| Type | Description |
|---|---|
| String | query response, or Nil with the last error set |
Example
image := System.IO.Filesystem.File->New("photo.png");
response := Completion->Generate("llava", "Describe what you see in this image.", image);
response->PrintLine();Generate # function
Generates a response from the model given an input
function : Generate(model:String, prompt:String, images:File[]) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
| images | File[] | image files |
Return
| Type | Description |
|---|---|
| String | query response, or Nil with the last error set |
GenerateReply # function
Generates a reply with its metadata (thinking, done reason, token counts, timings)
function : GenerateReply(model:String, prompt:String, options:Options) ~ ReplyParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llama3, llava) |
| prompt | String | prompt |
| options | Options | options and request settings, or Nil |
Return
| Type | Description |
|---|---|
| Reply | reply, or Nil with the last error set |
GenerateReply # function
Generates a reply about images, with its metadata
function : GenerateReply(model:String, prompt:String, images:File[], options:Options) ~ ReplyParameters
| Name | Type | Description |
|---|---|---|
| model | String | model name (i.e. llava) |
| prompt | String | prompt |
| images | File[] | image files, or Nil |
| options | Options | options and request settings, or Nil |
Return
| Type | Description |
|---|---|
| Reply | reply, or Nil with the last error set |
ParseGenerateResponse # function
The response handling behind every Generate overload, as a function of the body text so it can be tested without a server.
function : ParseGenerateResponse(body:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| body | String | response text from /api/generate |
Return
| Type | Description |
|---|---|
| String | the generated text, or Nil with the last error set |