Class: Aireview::Reviewer
- Inherits:
-
Object
- Object
- Aireview::Reviewer
- Defined in:
- lib/aireview/reviewer.rb
Overview
The review stages on top of the router: Generate and Critique with their own schemas and temperatures. LlmClient makes the request, LlmRouter walks the models.
Instance Attribute Summary collapse
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Instance Method Summary collapse
-
#answered_model(stage) ⇒ Object
The model that answered last in the stage with its place in the chain, for the log.
- #critique(system_prompt:, user_prompt:, pinned: false) ⇒ Object
-
#critique_weaker? ⇒ Boolean
Critique ran on a model below Generate in the pool (allow_weaker).
-
#exclude_answered_model(stage:, reason:) ⇒ Object
An invalid result: the model is excluded for the stage, the next request of the stage goes to another.
-
#fallback_models ⇒ Object
Stages answered by a fallback model, for the report line.
-
#finish_reason(stage) ⇒ Object
Why the last answer of the stage stopped (:stop, :max_tokens, :content_filter…), nil when the provider did not say or no answer came.
-
#generate(system_prompt:, user_prompt:, pinned: false) ⇒ Object
pinned — a request only to the model that answered last in the stage (the repair of its own JSON): its failure is RepairImpossibleError.
-
#initialize(config:, logger: Logger.new($stderr), router: nil, client: nil) ⇒ Reviewer
constructor
A new instance of Reviewer.
Constructor Details
#initialize(config:, logger: Logger.new($stderr), router: nil, client: nil) ⇒ Reviewer
Returns a new instance of Reviewer.
14 15 16 17 18 19 20 |
# File 'lib/aireview/reviewer.rb', line 14 def initialize(config:, logger: Logger.new($stderr), router: nil, client: nil) @config = config @logger = logger @router = router || LlmRouter.new(config: config, logger: logger) @client = client || LlmClient.new(config: config, logger: logger) @finish_reasons = {} end |
Instance Attribute Details
#router ⇒ Object (readonly)
Returns the value of attribute router.
12 13 14 |
# File 'lib/aireview/reviewer.rb', line 12 def router @router end |
Instance Method Details
#answered_model(stage) ⇒ Object
The model that answered last in the stage with its place in the chain, for the log.
42 43 44 |
# File 'lib/aireview/reviewer.rb', line 42 def answered_model(stage) @router.answered(stage) end |
#critique(system_prompt:, user_prompt:, pinned: false) ⇒ Object
30 31 32 33 34 |
# File 'lib/aireview/reviewer.rb', line 30 def critique(system_prompt:, user_prompt:, pinned: false) prompt = LlmClient::Prompt.new(stage: 'critique', system: system_prompt, user: user_prompt, temperature: @config.critique_temperature, schema: CritiqueOutputSchema) call_llm(prompt, pinned: pinned) end |
#critique_weaker? ⇒ Boolean
Critique ran on a model below Generate in the pool (allow_weaker).
47 48 49 |
# File 'lib/aireview/reviewer.rb', line 47 def critique_weaker? @router.critique_weaker? end |
#exclude_answered_model(stage:, reason:) ⇒ Object
An invalid result: the model is excluded for the stage, the next request of the stage goes to another. Returns the excluded model or nil.
59 60 61 |
# File 'lib/aireview/reviewer.rb', line 59 def exclude_answered_model(stage:, reason:) @router.exclude_answered(stage: stage, reason: reason) end |
#fallback_models ⇒ Object
Stages answered by a fallback model, for the report line.
37 38 39 |
# File 'lib/aireview/reviewer.rb', line 37 def fallback_models @router.fallback_models end |
#finish_reason(stage) ⇒ Object
Why the last answer of the stage stopped (:stop, :max_tokens, :content_filter…), nil when the provider did not say or no answer came.
53 54 55 |
# File 'lib/aireview/reviewer.rb', line 53 def finish_reason(stage) @finish_reasons[stage.to_s] end |
#generate(system_prompt:, user_prompt:, pinned: false) ⇒ Object
pinned — a request only to the model that answered last in the stage (the repair of its own JSON): its failure is RepairImpossibleError.
24 25 26 27 28 |
# File 'lib/aireview/reviewer.rb', line 24 def generate(system_prompt:, user_prompt:, pinned: false) prompt = LlmClient::Prompt.new(stage: 'generate', system: system_prompt, user: user_prompt, temperature: @config.generate_temperature, schema: GenerateOutputSchema) call_llm(prompt, pinned: pinned) end |