Class: RSpec::LLM::Matchers::PassLlmJudge
- Inherits:
-
Object
- Object
- RSpec::LLM::Matchers::PassLlmJudge
- Defined in:
- lib/rspec/llm/matchers/pass_llm_judge.rb
Overview
LLM-as-judge matcher. Asks the configured judge model whether the actual response satisfies the given criterion. Parses YES/NO from the first non-whitespace token of the judge’s reply.
Direct Known Subclasses
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(criterion) ⇒ PassLlmJudge
constructor
A new instance of PassLlmJudge.
- #matches?(actual) ⇒ Boolean
-
#using(judge) ⇒ Object
Override the judge for this matcher invocation (optional).
Constructor Details
#initialize(criterion) ⇒ PassLlmJudge
Returns a new instance of PassLlmJudge.
10 11 12 13 |
# File 'lib/rspec/llm/matchers/pass_llm_judge.rb', line 10 def initialize(criterion) @criterion = criterion @judge = nil end |
Instance Method Details
#description ⇒ Object
28 29 30 |
# File 'lib/rspec/llm/matchers/pass_llm_judge.rb', line 28 def description "pass LLM judge with criterion: #{@criterion.inspect}" end |
#failure_message ⇒ Object
32 33 34 35 |
# File 'lib/rspec/llm/matchers/pass_llm_judge.rb', line 32 def "expected response to pass judge criterion #{@criterion.inspect}, " \ "but judge said: #{format_reason}\n\nResponse:\n#{@actual}" end |
#failure_message_when_negated ⇒ Object
37 38 39 40 |
# File 'lib/rspec/llm/matchers/pass_llm_judge.rb', line 37 def "expected response NOT to pass judge criterion #{@criterion.inspect}, " \ "but judge said: #{format_reason}\n\nResponse:\n#{@actual}" end |
#matches?(actual) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/rspec/llm/matchers/pass_llm_judge.rb', line 21 def matches?(actual) @actual = actual.to_s @verdict_text = judge_adapter.chat(prompt_for(@actual, @criterion)) @verdict, @reason = parse_verdict(@verdict_text) @verdict == true end |
#using(judge) ⇒ Object
Override the judge for this matcher invocation (optional).
16 17 18 19 |
# File 'lib/rspec/llm/matchers/pass_llm_judge.rb', line 16 def using(judge) @judge = judge self end |