OllamaOptions

Typed options for controlling model generation behavior.

Only non-default (explicitly set) fields are serialized to JSON. Float fields use float.nan as the "unset" sentinel; integer fields use 0.

Members

Functions

toJson
JSONValue toJson()

Serializes only non-default fields to a JSONValue object.

Variables

min_p
float min_p;

Minimum probability threshold.

mirostat
int mirostat;

Mirostat strategy (0=off,1=v1,2=v2).

mirostat_eta
float mirostat_eta;

Mirostat learning rate.

mirostat_tau
float mirostat_tau;

Mirostat target entropy.

num_ctx
int num_ctx;

Context window size; 0 = model default.

num_predict
int num_predict;

Max tokens to generate; 0 = unlimited.

repeat_last_n
int repeat_last_n;

Tokens considered for repeat penalty.

repeat_penalty
float repeat_penalty;

Penalty for repeated tokens.

seed
int seed;

Random seed; 0 = random.

stop
string[] stop;

Stop sequences; empty = disabled.

temperature
float temperature;

Sampling temperature (0 = deterministic).

top_k
int top_k;

Top-K sampling; 0 = disabled.

top_p
float top_p;

Nucleus sampling threshold.

Examples

OllamaOptions opts;
opts.temperature = 0.8f;
opts.num_ctx     = 4096;
opts.stop        = ["<|end|>", "\n\n"];
// Default options serialize to an empty JSON object
OllamaOptions def;
auto j0 = def.toJson();
assert(j0.type == JSONType.object);
assert(j0.objectNoRef.length == 0, "Default OllamaOptions should be empty");

// Only set fields appear in output
OllamaOptions opts;
opts.temperature = 0.5f;  // 0.5 is exactly representable in float and double
opts.top_k       = 40;
opts.num_ctx     = 4096;
opts.stop        = ["<|end|>"];
auto j = opts.toJson();
assert(j["temperature"].type == JSONType.float_);
assert(j["temperature"].floating == 0.5);  // exact double comparison
assert(j["top_k"].integer == 40);
assert(j["num_ctx"].integer == 4096);
assert(j["stop"].arrayNoRef[0].str == "<|end|>");
assert("top_p"          !in j);
assert("min_p"          !in j);
assert("repeat_penalty" !in j);
assert("mirostat"       !in j);

// temperature = 0.0 is a valid explicit value and must be included
OllamaOptions zeroTemp;
zeroTemp.temperature = 0.0f;
auto jz = zeroTemp.toJson();
assert("temperature" in jz);
assert(jz["temperature"].floating == 0.0);

Meta