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
  min_p penalize_newline repeat_last_n numa num_batch
  main_gpu low_vram vocab_only use_mmap use_mlock
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Options

Returns a new instance of Options.

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
# File 'lib/ollama/options.rb', line 31

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.



24
25
26
# File 'lib/ollama/options.rb', line 24

def frequency_penalty
  @frequency_penalty
end

#low_vramObject

Returns the value of attribute low_vram.



24
25
26
# File 'lib/ollama/options.rb', line 24

def low_vram
  @low_vram
end

#main_gpuObject

Returns the value of attribute main_gpu.



24
25
26
# File 'lib/ollama/options.rb', line 24

def main_gpu
  @main_gpu
end

#min_pObject

Returns the value of attribute min_p.



24
25
26
# File 'lib/ollama/options.rb', line 24

def min_p
  @min_p
end

#mirostatObject

Returns the value of attribute mirostat.



24
25
26
# File 'lib/ollama/options.rb', line 24

def mirostat
  @mirostat
end

#mirostat_etaObject

Returns the value of attribute mirostat_eta.



24
25
26
# File 'lib/ollama/options.rb', line 24

def mirostat_eta
  @mirostat_eta
end

#mirostat_tauObject

Returns the value of attribute mirostat_tau.



24
25
26
# File 'lib/ollama/options.rb', line 24

def mirostat_tau
  @mirostat_tau
end

#num_batchObject

Returns the value of attribute num_batch.



24
25
26
# File 'lib/ollama/options.rb', line 24

def num_batch
  @num_batch
end

#num_ctxObject

Returns the value of attribute num_ctx.



24
25
26
# File 'lib/ollama/options.rb', line 24

def num_ctx
  @num_ctx
end

#num_gpuObject

Returns the value of attribute num_gpu.



24
25
26
# File 'lib/ollama/options.rb', line 24

def num_gpu
  @num_gpu
end

#num_keepObject

Returns the value of attribute num_keep.



24
25
26
# File 'lib/ollama/options.rb', line 24

def num_keep
  @num_keep
end

#num_predictObject

Returns the value of attribute num_predict.



24
25
26
# File 'lib/ollama/options.rb', line 24

def num_predict
  @num_predict
end

#num_threadObject

Returns the value of attribute num_thread.



24
25
26
# File 'lib/ollama/options.rb', line 24

def num_thread
  @num_thread
end

#numaObject

Returns the value of attribute numa.



24
25
26
# File 'lib/ollama/options.rb', line 24

def numa
  @numa
end

#penalize_newlineObject

Returns the value of attribute penalize_newline.



24
25
26
# File 'lib/ollama/options.rb', line 24

def penalize_newline
  @penalize_newline
end

#presence_penaltyObject

Returns the value of attribute presence_penalty.



24
25
26
# File 'lib/ollama/options.rb', line 24

def presence_penalty
  @presence_penalty
end

#repeat_last_nObject

Returns the value of attribute repeat_last_n.



24
25
26
# File 'lib/ollama/options.rb', line 24

def repeat_last_n
  @repeat_last_n
end

#repeat_penaltyObject

Returns the value of attribute repeat_penalty.



24
25
26
# File 'lib/ollama/options.rb', line 24

def repeat_penalty
  @repeat_penalty
end

#seedObject

Returns the value of attribute seed.



24
25
26
# File 'lib/ollama/options.rb', line 24

def seed
  @seed
end

#stopObject

Returns the value of attribute stop.



24
25
26
# File 'lib/ollama/options.rb', line 24

def stop
  @stop
end

#temperatureObject

Returns the value of attribute temperature.



24
25
26
# File 'lib/ollama/options.rb', line 24

def temperature
  @temperature
end

#tfs_zObject

Returns the value of attribute tfs_z.



24
25
26
# File 'lib/ollama/options.rb', line 24

def tfs_z
  @tfs_z
end

#top_kObject

Returns the value of attribute top_k.



24
25
26
# File 'lib/ollama/options.rb', line 24

def top_k
  @top_k
end

#top_pObject

Returns the value of attribute top_p.



24
25
26
# File 'lib/ollama/options.rb', line 24

def top_p
  @top_p
end

#typical_pObject

Returns the value of attribute typical_p.



24
25
26
# File 'lib/ollama/options.rb', line 24

def typical_p
  @typical_p
end

#use_mlockObject

Returns the value of attribute use_mlock.



24
25
26
# File 'lib/ollama/options.rb', line 24

def use_mlock
  @use_mlock
end

#use_mmapObject

Returns the value of attribute use_mmap.



24
25
26
# File 'lib/ollama/options.rb', line 24

def use_mmap
  @use_mmap
end

#vocab_onlyObject

Returns the value of attribute vocab_only.



24
25
26
# File 'lib/ollama/options.rb', line 24

def vocab_only
  @vocab_only
end

Instance Method Details

#to_hObject

Convert to hash for API calls



183
184
185
186
187
188
189
190
# File 'lib/ollama/options.rb', line 183

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