Class: RubricLLM::RSpecMatchers::HallucinationMatcher
Instance Attribute Summary
Attributes inherited from BaseMatcher
#config, #result, #threshold
Instance Method Summary
collapse
Methods inherited from BaseMatcher
#with_config, #with_threshold
Constructor Details
Returns a new instance of HallucinationMatcher.
114
115
116
117
118
|
# File 'lib/rubric_llm/rspec.rb', line 114
def initialize(context, question: nil)
super()
@context = context
@question = question
end
|
Instance Method Details
#failure_message ⇒ Object
125
126
127
|
# File 'lib/rubric_llm/rspec.rb', line 125
def failure_message
"expected hallucination (faithfulness < #{threshold}), got #{result[:score]}"
end
|
#failure_message_when_negated ⇒ Object
129
130
131
|
# File 'lib/rubric_llm/rspec.rb', line 129
def failure_message_when_negated
"expected no hallucination (faithfulness >= #{threshold}), got #{result[:score] || "nil"}"
end
|
#matches?(answer) ⇒ Boolean
120
121
122
123
|
# File 'lib/rubric_llm/rspec.rb', line 120
def matches?(answer)
score = evaluate(Metrics::Faithfulness, question: @question || "", answer:, context: @context)
score.nil? || score < threshold
end
|