Class: Raif::Evals::LlmJudges::Comparative
- Inherits:
-
Raif::Evals::LlmJudge
- Object
- ApplicationRecord
- Task
- Raif::Evals::LlmJudge
- Raif::Evals::LlmJudges::Comparative
- Defined in:
- lib/raif/evals/llm_judges/comparative.rb
Constant Summary
Constants included from Concerns::LlmResponseParsing
Concerns::LlmResponseParsing::ASCII_CONTROL_CHARS
Instance Attribute Summary collapse
-
#content_a ⇒ Object
Returns the value of attribute content_a.
-
#content_b ⇒ Object
Returns the value of attribute content_b.
-
#expected_winner ⇒ Object
Returns the value of attribute expected_winner.
Attributes inherited from Task
Instance Method Summary collapse
- #build_prompt ⇒ Object
- #build_system_prompt ⇒ Object
- #correct_expected_winner? ⇒ Boolean
- #tie? ⇒ Boolean
- #winner ⇒ Object
Methods inherited from Raif::Evals::LlmJudge
#default_llm_model_key, #judgment_confidence, #judgment_reasoning, #low_confidence?
Methods inherited from Task
json_response_schema, prompt, #re_run, run, #run, #status, system_prompt
Methods included from Concerns::LlmResponseParsing
#parse_html_response, #parse_json_response, #parsed_response
Methods included from Concerns::HasAvailableModelTools
Methods included from Concerns::HasRequestedLanguage
#requested_language_name, #system_prompt_language_preference
Methods included from Concerns::HasLlm
Methods inherited from ApplicationRecord
Instance Attribute Details
#content_a ⇒ Object
Returns the value of attribute content_a.
11 12 13 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 11 def content_a @content_a end |
#content_b ⇒ Object
Returns the value of attribute content_b.
11 12 13 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 11 def content_b @content_b end |
#expected_winner ⇒ Object
Returns the value of attribute expected_winner.
11 12 13 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 11 def expected_winner @expected_winner end |
Instance Method Details
#build_prompt ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 43 def build_prompt " Comparison criteria: \#{comparison_criteria}\n \#{additional_context_prompt}\n Compare the following two pieces of content:\n\n CONTENT A:\n \#{content_a}\n\n CONTENT B:\n \#{content_b}\n\n Which content better meets the comparison criteria?\n PROMPT\nend\n".strip |
#build_system_prompt ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 31 def build_system_prompt " You are an expert evaluator comparing two pieces of content to determine which better meets specified criteria.\n\n \#{allow_ties ? \"You may declare a tie if both pieces of content are equally good.\" : \"You must choose a winner even if the difference is minimal.\"}\n\n First, provide detailed reasoning for your choice. Then, provide a precise winner \#{allow_ties ? \"(A, B, or tie)\" : \"(A or B)\"}.\n\n Respond with JSON matching the required schema.\n PROMPT\nend\n".strip |
#correct_expected_winner? ⇒ Boolean
69 70 71 72 73 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 69 def correct_expected_winner? return unless completed? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition parsed_response["winner"] == expected_winner end |
#tie? ⇒ Boolean
63 64 65 66 67 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 63 def tie? return unless completed? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition parsed_response["winner"] == "tie" end |
#winner ⇒ Object
59 60 61 |
# File 'lib/raif/evals/llm_judges/comparative.rb', line 59 def winner parsed_response["winner"] if completed? end |