Module: Raif::ReasoningEffort

Defined in:
lib/raif/reasoning_effort.rb

Overview

The provider-neutral reasoning effort levels. Each model declares the subset it accepts in its manifest capabilities (reasoning_effort_levels), and each adapter maps a level to its own request field. nil means "no level from this source" and is distinct from :none, which asks the provider to turn reasoning off.

Constant Summary collapse

LEVELS =
[:none, :minimal, :low, :medium, :high, :xhigh].freeze

Class Method Summary collapse

Class Method Details

.accepted_levels_for(model_key) ⇒ Object

The levels a model key accepts: the registered config when the key is registered, else its manifest entry, so a key whose provider is not enabled on this machine still validates. nil when the key is neither, which callers treat as a typo.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/raif/reasoning_effort.rb', line 27

def self.accepted_levels_for(model_key)
  key = normalize_key(model_key)
  capabilities = if (config = Raif.llm_config(key))
    config[:capabilities] || {}
  else
    Raif.model_manifest.llm_entries.find { |entry| entry.key == key }&.capabilities
  end
  return if capabilities.nil?

  Array(capabilities[:reasoning_effort_levels]).map { |level| level.to_s.downcase.to_sym }
end

.lookup(hash, model_key) ⇒ Object

Hosts may write either string or symbol keys, so look up both.



40
41
42
43
44
45
46
# File 'lib/raif/reasoning_effort.rb', line 40

def self.lookup(hash, model_key)
  return if hash.blank?

  key = normalize_key(model_key)
  _, level = hash.find { |candidate, _| normalize_key(candidate) == key }
  normalize(level)
end

.normalize(value) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/raif/reasoning_effort.rb', line 11

def self.normalize(value)
  return if value.nil?

  level = value.to_s.downcase.to_sym if value.is_a?(String) || value.is_a?(Symbol)
  return level if LEVELS.include?(level)

  raise ArgumentError, "Invalid reasoning effort #{value.inspect}. Must be one of: #{LEVELS.join(", ")}"
end

.normalize_key(key) ⇒ Object



20
21
22
# File 'lib/raif/reasoning_effort.rb', line 20

def self.normalize_key(key)
  key.to_s.to_sym
end