struct

Slim::Options

Inherits Struct < Value < Object

Sampling options for text generation.

These are standard LLM parameters supported by most inference engines. They control how the model selects the next token during generation.

Common Parameters

  • temperature - Controls randomness. 0 = deterministic, 1 = creative
  • top_p - Nucleus sampling. Consider tokens with cumulative probability p
  • top_k - Only consider the k most likely tokens
  • repeat_penalty - Penalize repeated tokens (reduces repetition)
  • seed - Random seed for reproducible outputs

Ollama-Specific Parameters

These are passed through but are specific to the Ollama/llama.cpp backend:

  • num_ctx - Context window size (default: 2048)
  • num_predict - Max tokens to generate (default: 128, -1 = infinite)
  • stop - Stop sequences to end generation

Example

# For classification (deterministic)
opts = Slim::Options.new(temperature: 0.1, top_k: 1)

# For creative generation
opts = Slim::Options.new(temperature: 0.8, top_p: 0.9)

response = client.generate("llama3.2:3b", prompt, options: opts)

Constructors

classification

Preset for classification tasks (deterministic).

Source
creative

Preset for creative generation.

Source
new(temperature : Float64 | Nil = nil, top_p : Float64 | Nil = nil, top_k : Int32 | Nil = nil, repeat_penalty : Float64 | Nil = nil, seed : Int32 | Nil = nil, num_ctx : Int32 | Nil = nil, num_predict : Int32 | Nil = nil, stop : Array(String) | Nil = nil)
Source

Instance methods

num_ctx

Context window size in tokens. Default: 2048

Source
num_ctx=(num_ctx : Int32 | Nil)

Context window size in tokens. Default: 2048

Source
num_predict

Maximum tokens to generate. -1 for unlimited. Default: 128

Source
num_predict=(num_predict : Int32 | Nil)

Maximum tokens to generate. -1 for unlimited. Default: 128

Source
repeat_penalty

Penalize tokens that have appeared. Higher = less repetition. Range: 0.0-2.0. Default: 1.1

Source
repeat_penalty=(repeat_penalty : Float64 | Nil)

Penalize tokens that have appeared. Higher = less repetition. Range: 0.0-2.0. Default: 1.1

Source
seed

Random seed for reproducible generation. Same seed = same output.

Source
seed=(seed : Int32 | Nil)

Random seed for reproducible generation. Same seed = same output.

Source
stop

Stop sequences - generation stops when these are encountered.

Source
stop=(stop : Array(String) | Nil)

Stop sequences - generation stops when these are encountered.

Source
temperature

Randomness of output. 0.0 = deterministic, 1.0 = creative, 2.0 = chaotic. For classification tasks, use 0.0-0.3. Default: 0.8

Source
temperature=(temperature : Float64 | Nil)

Randomness of output. 0.0 = deterministic, 1.0 = creative, 2.0 = chaotic. For classification tasks, use 0.0-0.3. Default: 0.8

Source
to_h

Convert to hash for JSON serialization.

Source
top_k

Only consider the k most likely next tokens. Default: 40

Source
top_k=(top_k : Int32 | Nil)

Only consider the k most likely next tokens. Default: 40

Source
top_p

Nucleus sampling threshold. Only consider tokens whose cumulative probability mass reaches this value. Range: 0.0-1.0. Default: 0.9

Source
top_p=(top_p : Float64 | Nil)

Nucleus sampling threshold. Only consider tokens whose cumulative probability mass reaches this value. Range: 0.0-1.0. Default: 0.9

Source