Class: RubyLLM::Contract::Eval::Recommender

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/contract/eval/recommender.rb

Instance Method Summary collapse

Constructor Details

#initialize(comparison:, min_score:, min_first_try_pass_rate: 0.8, current_config: nil) ⇒ Recommender

Returns a new instance of Recommender.



7
8
9
10
11
12
# File 'lib/ruby_llm/contract/eval/recommender.rb', line 7

def initialize(comparison:, min_score:, min_first_try_pass_rate: 0.8, current_config: nil)
  @comparison = comparison
  @min_score = min_score
  @min_first_try_pass_rate = min_first_try_pass_rate
  @current_config = current_config
end

Instance Method Details

#recommendObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_llm/contract/eval/recommender.rb', line 14

def recommend
  scored = build_scored_candidates
  best = select_best(scored)
  chain = build_retry_chain(scored, best)
  rationale = build_rationale(scored, best)
  warnings = build_warnings(scored)
  savings = best ? calculate_savings(best) : {}

  Recommendation.new(
    best: best&.dig(:config),
    retry_chain: chain,
    score: best&.dig(:score) || 0.0,
    cost_per_call: best&.dig(:cost_per_call) || 0.0,
    rationale: rationale,
    current_config: @current_config,
    savings: savings,
    warnings: warnings
  )
end