Class: RubyLLM::Contract::Eval::Evaluator::Regex
- Inherits:
-
Object
- Object
- RubyLLM::Contract::Eval::Evaluator::Regex
- Defined in:
- lib/ruby_llm/contract/eval/evaluator/regex.rb
Instance Method Summary collapse
-
#call(output:, expected: nil, input: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(pattern) ⇒ Regex
constructor
A new instance of Regex.
Constructor Details
#initialize(pattern) ⇒ Regex
Returns a new instance of Regex.
8 9 10 |
# File 'lib/ruby_llm/contract/eval/evaluator/regex.rb', line 8 def initialize(pattern) @pattern = pattern.is_a?(::Regexp) ? pattern : ::Regexp.new(pattern) end |
Instance Method Details
#call(output:, expected: nil, input: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_llm/contract/eval/evaluator/regex.rb', line 12 def call(output:, expected: nil, input: nil) # rubocop:disable Lint/UnusedMethodArgument text = output.is_a?(Hash) ? output.values.join(" ") : output.to_s if text.match?(@pattern) EvaluationResult.new(score: 1.0, passed: true, details: "matches #{@pattern.inspect}") else EvaluationResult.new(score: 0.0, passed: false, details: "does not match #{@pattern.inspect}") end end |