Class: Langfuse::Evaluators::ExactMatchEvaluator

Inherits:
BaseEvaluator show all
Defined in:
lib/langfuse/evaluation.rb

Instance Method Summary collapse

Constructor Details

#initialize(name: 'exact_match', description: 'Exact match evaluator') ⇒ ExactMatchEvaluator

Returns a new instance of ExactMatchEvaluator.



86
87
88
# File 'lib/langfuse/evaluation.rb', line 86

def initialize(name: 'exact_match', description: 'Exact match evaluator')
  super(name: name, description: description)
end

Instance Method Details

#evaluate(input, output, expected: nil, context: nil) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/langfuse/evaluation.rb', line 90

def evaluate(input, output, expected: nil, context: nil)
  return create_score(value: 0, comment: 'No expected value provided') unless expected

  score = output.to_s.strip == expected.to_s.strip ? 1 : 0
  create_score(
    value: score,
    comment: score == 1 ? 'Exact match' : 'No match'
  )
end