Class: Aireview::ResultParser
- Inherits:
-
Object
- Object
- Aireview::ResultParser
- Defined in:
- lib/aireview/result_parser.rb
Overview
Parses and validates the shape of an LLM answer: JSON (code fences
included) or a ready structure by the schema → a hash with string keys
and checked ids. A shape error is SchemaError; whether to repair the
answer with another request is the pipeline's decision. The same parser
lets aireview models check judge whether a model holds the schema.
Defined Under Namespace
Classes: SchemaError
Constant Summary collapse
- DECISIONS =
%w[keep reject].freeze
Instance Method Summary collapse
-
#parse(raw, expected:, critique_candidate_ids: nil) ⇒ Object
expected — :generate or :critique; critique_candidate_ids — the candidate ids Critique must give a verdict on, each of them.
Instance Method Details
#parse(raw, expected:, critique_candidate_ids: nil) ⇒ Object
expected — :generate or :critique; critique_candidate_ids — the candidate ids Critique must give a verdict on, each of them.
19 20 21 22 23 24 25 26 27 |
# File 'lib/aireview/result_parser.rb', line 19 def parse(raw, expected:, critique_candidate_ids: nil) parsed = Utils.normalize_hash(raw.is_a?(Hash) ? raw : JSON.parse(strip_code_fences(raw.to_s))) case expected.to_sym when :generate then generate_result(parsed) when :critique then critique_result(parsed, critique_candidate_ids) else raise ArgumentError, "Unknown expected JSON schema: #{expected.inspect}" end end |