Class: RubyLLM::Contract::Eval::Recommendation

Inherits:
Object
  • Object
show all
Includes:
Concerns::DeepFreeze
Defined in:
lib/ruby_llm/contract/eval/recommendation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(best:, retry_chain:, score:, cost_per_call:, rationale:, current_config:, savings:, warnings:) ⇒ Recommendation

Returns a new instance of Recommendation.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 12

def initialize(best:, retry_chain:, score:, cost_per_call:,
               rationale:, current_config:, savings:, warnings:)
  @best = deep_dup_freeze(best)
  @retry_chain = deep_dup_freeze(retry_chain)
  @score = score
  @cost_per_call = cost_per_call
  @rationale = deep_dup_freeze(rationale)
  @current_config = deep_dup_freeze(current_config)
  @savings = deep_dup_freeze(savings)
  @warnings = deep_dup_freeze(warnings)
  freeze
end

Instance Attribute Details

#bestObject (readonly)

Returns the value of attribute best.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def best
  @best
end

#cost_per_callObject (readonly)

Returns the value of attribute cost_per_call.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def cost_per_call
  @cost_per_call
end

#current_configObject (readonly)

Returns the value of attribute current_config.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def current_config
  @current_config
end

#rationaleObject (readonly)

Returns the value of attribute rationale.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def rationale
  @rationale
end

#retry_chainObject (readonly)

Returns the value of attribute retry_chain.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def retry_chain
  @retry_chain
end

#savingsObject (readonly)

Returns the value of attribute savings.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def savings
  @savings
end

#scoreObject (readonly)

Returns the value of attribute score.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def score
  @score
end

#warningsObject (readonly)

Returns the value of attribute warnings.



9
10
11
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 9

def warnings
  @warnings
end

Instance Method Details

#to_dslObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_llm/contract/eval/recommendation.rb', line 25

def to_dsl
  return "# No recommendation — no candidate met the minimum score" if retry_chain.empty?

  if retry_chain.length == 1 && retry_chain.first.keys == [:model]
    "model \"#{retry_chain.first[:model]}\""
  elsif retry_chain.all? { |c| c.keys == [:model] }
    models_str = retry_chain.map { |c| c[:model] }.join(" ")
    "retry_policy models: %w[#{models_str}]"
  else
    args = retry_chain.map { |c| config_to_ruby(c) }.join(",\n             ")
    "retry_policy do\n  escalate(#{args})\nend"
  end
end