Class: RubyLLM::Contract::Eval::Evaluator::ProcEvaluator
- Inherits:
-
Object
- Object
- RubyLLM::Contract::Eval::Evaluator::ProcEvaluator
- Defined in:
- lib/ruby_llm/contract/eval/evaluator/proc_evaluator.rb
Instance Method Summary collapse
-
#call(output:, expected: nil, input: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument,Metrics.
-
#initialize(callable) ⇒ ProcEvaluator
constructor
A new instance of ProcEvaluator.
Constructor Details
#initialize(callable) ⇒ ProcEvaluator
Returns a new instance of ProcEvaluator.
8 9 10 |
# File 'lib/ruby_llm/contract/eval/evaluator/proc_evaluator.rb', line 8 def initialize(callable) @callable = callable end |
Instance Method Details
#call(output:, expected: nil, input: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument,Metrics
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_llm/contract/eval/evaluator/proc_evaluator.rb', line 12 def call(output:, expected: nil, input: nil) # rubocop:disable Lint/UnusedMethodArgument,Metrics result = if @callable.arity == 2 || (@callable.arity.negative? && @callable.parameters.length >= 2) @callable.call(output, input) else @callable.call(output) end if result.nil? warn "[ruby_llm-contract] verify/evaluator proc returned nil. " \ "This usually means a key mismatch (string vs symbol). " \ "Output keys are always symbols." end case result when true EvaluationResult.new(score: 1.0, passed: true, details: "passed") when false EvaluationResult.new(score: 0.0, passed: false, details: "not passed") when Numeric EvaluationResult.new(score: result, passed: result >= 0.5, details: "custom score: #{result}") else EvaluationResult.new(score: result ? 1.0 : 0.0, passed: !!result, details: "custom: #{result}") end end |