Class: Ollama::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/options.rb

Overview

Options class for model parameters with basic type checking

Provides type-safe access to Ollama model runtime options. These are passed under the ‘options:` key in API requests.

Example:

options = Ollama::Options.new(temperature: 0.7, top_p: 0.95, num_predict: 256)
client.chat(messages: [...], options: options.to_h)
client.generate(prompt: "...", options: options.to_h)

Constant Summary collapse

VALID_KEYS =
%i[
  temperature top_p top_k num_ctx repeat_penalty seed
  num_predict stop tfs_z mirostat mirostat_tau mirostat_eta
  num_gpu num_thread num_keep typical_p
  presence_penalty frequency_penalty
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Options

Returns a new instance of Options.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'lib/ollama/options.rb', line 27

def initialize(**options)
  unknown_keys = options.keys - VALID_KEYS
  raise ArgumentError, "Unknown options: #{unknown_keys.join(", ")}" if unknown_keys.any?

  VALID_KEYS.each do |key|
    assign_option(key, options[key])
  end
end

Instance Attribute Details

#frequency_penaltyObject

Returns the value of attribute frequency_penalty.



22
23
24
# File 'lib/ollama/options.rb', line 22

def frequency_penalty
  @frequency_penalty
end

#mirostatObject

Returns the value of attribute mirostat.



22
23
24
# File 'lib/ollama/options.rb', line 22

def mirostat
  @mirostat
end

#mirostat_etaObject

Returns the value of attribute mirostat_eta.



22
23
24
# File 'lib/ollama/options.rb', line 22

def mirostat_eta
  @mirostat_eta
end

#mirostat_tauObject

Returns the value of attribute mirostat_tau.



22
23
24
# File 'lib/ollama/options.rb', line 22

def mirostat_tau
  @mirostat_tau
end

#num_ctxObject

Returns the value of attribute num_ctx.



22
23
24
# File 'lib/ollama/options.rb', line 22

def num_ctx
  @num_ctx
end

#num_gpuObject

Returns the value of attribute num_gpu.



22
23
24
# File 'lib/ollama/options.rb', line 22

def num_gpu
  @num_gpu
end

#num_keepObject

Returns the value of attribute num_keep.



22
23
24
# File 'lib/ollama/options.rb', line 22

def num_keep
  @num_keep
end

#num_predictObject

Returns the value of attribute num_predict.



22
23
24
# File 'lib/ollama/options.rb', line 22

def num_predict
  @num_predict
end

#num_threadObject

Returns the value of attribute num_thread.



22
23
24
# File 'lib/ollama/options.rb', line 22

def num_thread
  @num_thread
end

#presence_penaltyObject

Returns the value of attribute presence_penalty.



22
23
24
# File 'lib/ollama/options.rb', line 22

def presence_penalty
  @presence_penalty
end

#repeat_penaltyObject

Returns the value of attribute repeat_penalty.



22
23
24
# File 'lib/ollama/options.rb', line 22

def repeat_penalty
  @repeat_penalty
end

#seedObject

Returns the value of attribute seed.



22
23
24
# File 'lib/ollama/options.rb', line 22

def seed
  @seed
end

#stopObject

Returns the value of attribute stop.



22
23
24
# File 'lib/ollama/options.rb', line 22

def stop
  @stop
end

#temperatureObject

Returns the value of attribute temperature.



22
23
24
# File 'lib/ollama/options.rb', line 22

def temperature
  @temperature
end

#tfs_zObject

Returns the value of attribute tfs_z.



22
23
24
# File 'lib/ollama/options.rb', line 22

def tfs_z
  @tfs_z
end

#top_kObject

Returns the value of attribute top_k.



22
23
24
# File 'lib/ollama/options.rb', line 22

def top_k
  @top_k
end

#top_pObject

Returns the value of attribute top_p.



22
23
24
# File 'lib/ollama/options.rb', line 22

def top_p
  @top_p
end

#typical_pObject

Returns the value of attribute typical_p.



22
23
24
# File 'lib/ollama/options.rb', line 22

def typical_p
  @typical_p
end

Instance Method Details

#to_hObject

Convert to hash for API calls



129
130
131
132
133
134
135
136
# File 'lib/ollama/options.rb', line 129

def to_h
  hash = {}
  VALID_KEYS.each do |key|
    val = instance_variable_get(:"@#{key}")
    hash[key] = val unless val.nil?
  end
  hash
end