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.
Options
Generation options and request settings. Model parameters (temperature, top_p, num_ctx, seed, stop, ...) are sent in the request's 'options' object; request settings (format, think, keep_alive, and for Completion system, template, suffix and raw) are sent as top-level request fields.
Example
schema := JsonParser->TextToElement("{\"type\":\"object\",\"properties\":{\"answer\":{\"type\":\"integer\"}},\"required\":[\"answer\"]}");
options := Options->New();
options->SetTemperature(0.0)->SetSeed(42)->SetNumCtx(8192);
options->SetFormat(schema)->SetKeepAlive("10m");Operations
- ApplyTo
- Set
- SetFormat
- SetKeepAlive
- SetMinP
- SetNumCtx
- SetNumPredict
- SetRaw
- SetRepeatPenalty
- SetSeed
- SetStop
- SetSuffix
- SetSystem
- SetTemperature
- SetTemplate
- SetThink
- SetTopK
- SetTopP
- ToJson
ApplyTo #
Adds the model parameters and request settings to a request body.
method : public : ApplyTo(request:JsonElement, generate:Bool) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| request | JsonElement | request body |
| generate | Bool | true for an /api/generate request; system, template, suffix and raw are sent only then |
Set #
Sets any numeric model parameter by name (see the Modelfile parameter list).
method : public : Set(name:String, value:Float) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| name | String | parameter name |
| value | Float | parameter value |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
Set #
Sets any integer model parameter by name (see the Modelfile parameter list).
method : public : Set(name:String, value:Int) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| name | String | parameter name |
| value | Int | parameter value |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetFormat #
Sets the output format to "json" (any JSON value).
method : public : SetFormat(format:String) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| format | String | "json" |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetFormat #
Sets the output format to a JSON schema (structured output); the reply text is JSON matching the schema.
method : public : SetFormat(schema:JsonElement) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| schema | JsonElement | JSON schema |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetKeepAlive #
Sets how long the model stays loaded after the request (e.g. "5m", "1h", "0" to unload).
method : public : SetKeepAlive(duration:String) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| duration | String | keep-alive duration |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetMinP #
Sets the min-p sampling value.
method : public : SetMinP(p:Float) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| p | Float | min-p value (0.0 to 1.0) |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetNumCtx #
Sets the context window size in tokens.
method : public : SetNumCtx(n:Int) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| n | Int | context size |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetNumPredict #
Sets the maximum number of tokens to generate (-1 for no limit).
method : public : SetNumPredict(n:Int) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| n | Int | token limit |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetRaw #
Sends the prompt without applying the prompt template (Completion only).
method : public : SetRaw(raw:Bool) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| raw | Bool | true for a raw prompt |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetRepeatPenalty #
Sets the repeat penalty.
method : public : SetRepeatPenalty(penalty:Float) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| penalty | Float | penalty value (1.0 is no penalty) |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetSeed #
Sets the random seed, for reproducible output.
method : public : SetSeed(seed:Int) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| seed | Int | seed value |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetStop #
Sets the stop sequences; generation ends when one is produced.
method : public : SetStop(stops:String[]) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| stops | String | stop sequences |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetSuffix #
Sets the text that follows the generated text, for fill-in-the-middle (Completion only).
method : public : SetSuffix(suffix:String) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| suffix | String | suffix text |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetSystem #
Sets the system prompt, overriding the Modelfile's (Completion only; a Chat takes a "system" message instead).
method : public : SetSystem(system:String) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| system | String | system prompt |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetTemperature #
Sets the temperature (0.0 to 2.0). Lower is more deterministic.
method : public : SetTemperature(t:Float) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| t | Float | temperature value |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetTemplate #
Sets the prompt template, overriding the Modelfile's (Completion only).
method : public : SetTemplate(template:String) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| template | String | prompt template |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetThink #
Enables or disables thinking for thinking models; the reasoning is returned separately (see Reply->GetThinking).
method : public : SetThink(think:Bool) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| think | Bool | true to think |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetThink #
Sets the thinking level for models that support levels ("low", "medium" or "high").
method : public : SetThink(level:String) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| level | String | thinking level |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetTopK #
Sets the top-k sampling value.
method : public : SetTopK(k:Int) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| k | Int | top-k value |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
SetTopP #
Sets the top-p (nucleus sampling) value.
method : public : SetTopP(p:Float) ~ OptionsParameters
| Name | Type | Description |
|---|---|---|
| p | Float | top-p value (0.0 to 1.0) |
Return
| Type | Description |
|---|---|
| Options | self for chaining |
ToJson #
Converts the model parameters to JSON for the request's 'options' object.
method : public : ToJson() ~ JsonElementReturn
| Type | Description |
|---|---|
| JsonElement | JSON element, or Nil if no model parameters are set |