Class: Inquirex::LLM::Adapter
- Inherits:
-
Object
- Object
- Inquirex::LLM::Adapter
- Defined in:
- lib/inquirex/llm/adapter.rb
Overview
Abstract interface for LLM adapters. Adapters bridge the gap between LLM::Node definitions and actual LLM API calls.
Implementations must:
1. Accept an LLM::Node and current answers
2. Construct the appropriate prompt (using node.prompt, node.from_steps, etc.)
3. Call the LLM API
4. Parse and validate the response against node.schema (if present)
5. Return a Hash or String result
The adapter is invoked server-side when the engine reaches an LLM step. It is never called on the frontend.
Direct Known Subclasses
Instance Method Summary collapse
-
#call(node, answers) ⇒ Hash, String
Processes an LLM step and returns the result.
-
#source_answers(node, answers) ⇒ Hash
Gathers the source answer data that feeds the LLM prompt.
-
#validate_output!(node, output) ⇒ Object
Validates adapter output against the node’s schema.
Instance Method Details
#call(node, answers) ⇒ Hash, String
Processes an LLM step and returns the result.
34 35 36 |
# File 'lib/inquirex/llm/adapter.rb', line 34 def call(node, answers) raise NotImplementedError, "#{self.class}#call must be implemented" end |
#source_answers(node, answers) ⇒ Hash
Gathers the source answer data that feeds the LLM prompt.
43 44 45 46 47 48 49 50 51 |
# File 'lib/inquirex/llm/adapter.rb', line 43 def source_answers(node, answers) if node.from_all answers.dup else node.from_steps.each_with_object({}) do |step_id, acc| acc[step_id] = answers[step_id] if answers.key?(step_id) end end end |
#validate_output!(node, output) ⇒ Object
Validates adapter output against the node’s schema.
58 59 60 61 62 63 64 65 66 |
# File 'lib/inquirex/llm/adapter.rb', line 58 def validate_output!(node, output) return unless node.schema missing = node.schema.missing_fields(output) return if missing.empty? raise Errors::SchemaViolationError, "LLM output for #{node.id.inspect} missing fields: #{missing.join(", ")}" end |