Class: Inquirex::LLM::DSL::LlmStepBuilder
- Inherits:
-
Object
- Object
- Inquirex::LLM::DSL::LlmStepBuilder
- Includes:
- DSL::RuleHelpers
- Defined in:
- lib/inquirex/llm/dsl/llm_step_builder.rb
Overview
Builds an LLM::Node from a step DSL block. Handles the LLM-specific methods (from, prompt, schema, model, temperature, max_tokens, fallback) while inheriting transition and skip_if from the core StepBuilder.
Instance Method Summary collapse
-
#build(id, nodes: nil) ⇒ LLM::Node
Builds the LLM::Node.
-
#fallback {|Hash| ... } ⇒ Object
Server-side fallback block, invoked when the LLM call fails.
-
#from(*step_ids) ⇒ Object
Adds source step id(s) whose answers feed the LLM prompt.
-
#from_all(value = true) ⇒ Object
Passes all collected answers to the LLM prompt.
-
#initialize(verb) ⇒ LlmStepBuilder
constructor
A new instance of LlmStepBuilder.
-
#max_tokens(value) ⇒ Object
Optional maximum output tokens.
-
#model(name) ⇒ Object
Optional model hint for the adapter.
-
#prompt(text) ⇒ Object
Sets the LLM prompt template.
-
#question(content) ⇒ Object
Optional display text (user-visible label for the step).
-
#schema(*question_ids, **fields) ⇒ Object
Declares the expected output schema.
-
#skip_if(rule) ⇒ Object
Sets a rule that skips this step entirely when true.
-
#temperature(value) ⇒ Object
Optional sampling temperature.
-
#text(content) ⇒ Object
Optional display text for context.
-
#transition(to:, if_rule: nil, requires_server: true) ⇒ Object
Adds a conditional transition.
Constructor Details
#initialize(verb) ⇒ LlmStepBuilder
Returns a new instance of LlmStepBuilder.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 30 def initialize(verb) @verb = verb.to_sym @prompt = nil @schema_refs = [] @schema_fields = {} @from_steps = [] @from_all = false @model = nil @temperature = nil @max_tokens = nil @fallback = nil @transitions = [] @skip_if = nil @question = nil @text = nil end |
Instance Method Details
#build(id, nodes: nil) ⇒ LLM::Node
Builds the LLM::Node. Question references in the schema are resolved against the full node map, so the flow builder defers this call until every step — including ones defined after this one — is known.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 165 def build(id, nodes: nil) validate!(id) field_map = resolve_schema_refs(id, nodes).merge(@schema_fields) schema_obj = field_map.empty? ? nil : Schema.new(**field_map) prompt_text = @prompt == :auto ? auto_prompt(nodes) : @prompt LLM::Node.new( id:, verb: @verb, prompt: prompt_text, schema: schema_obj, from_steps: @from_steps, from_all: @from_all, model: @model, temperature: @temperature, max_tokens: @max_tokens, fallback: @fallback, question: @question, text: @text, transitions: @transitions, skip_if: @skip_if ) end |
#fallback {|Hash| ... } ⇒ Object
Server-side fallback block, invoked when the LLM call fails. Stripped from JSON serialization.
120 121 122 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 120 def fallback(&block) @fallback = block end |
#from(*step_ids) ⇒ Object
Adds source step id(s) whose answers feed the LLM prompt.
83 84 85 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 83 def from(*step_ids) @from_steps.concat(step_ids.flatten) end |
#from_all(value = true) ⇒ Object
Passes all collected answers to the LLM prompt.
90 91 92 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 90 def from_all(value = true) @from_all = !!value end |
#max_tokens(value) ⇒ Object
Optional maximum output tokens.
111 112 113 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 111 def max_tokens(value) @max_tokens = value.to_i end |
#model(name) ⇒ Object
Optional model hint for the adapter.
97 98 99 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 97 def model(name) @model = name.to_sym end |
#prompt(text) ⇒ Object
Sets the LLM prompt template. Use {field_name} for interpolation placeholders that the adapter resolves at runtime.
Pass :auto to generate the prompt from the schema's question
references at build time: each referenced question's own wording is
enumerated, so the LLM sees what was actually asked. Requires at
least one question reference in the schema.
56 57 58 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 56 def prompt(text) @prompt = text end |
#question(content) ⇒ Object
Optional display text (user-visible label for the step).
144 145 146 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 144 def question(content) @question = content end |
#schema(*question_ids, **fields) ⇒ Object
Declares the expected output schema.
Positional symbols name questions defined elsewhere in the flow; each is resolved against that step's declared type, and for :enum / :multi_enum questions the allowed option values are folded into the schema sent to the LLM. A symbol that matches no ask/confirm step in the flow fails validation as invalid DSL.
Keyword pairs declare explicit field => type mappings, for output fields that have no corresponding question. Both forms compose:
schema :filing_status, :income_types, confidence: :decimal
75 76 77 78 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 75 def schema(*question_ids, **fields) @schema_refs.concat(question_ids.flatten.map(&:to_sym)) @schema_fields.merge!(fields) end |
#skip_if(rule) ⇒ Object
Sets a rule that skips this step entirely when true.
137 138 139 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 137 def skip_if(rule) @skip_if = rule end |
#temperature(value) ⇒ Object
Optional sampling temperature.
104 105 106 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 104 def temperature(value) @temperature = value.to_f end |
#text(content) ⇒ Object
Optional display text for context.
151 152 153 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 151 def text(content) @text = content end |
#transition(to:, if_rule: nil, requires_server: true) ⇒ Object
Adds a conditional transition. Inherited concept from core DSL. All LLM transitions are implicitly requires_server: true.
130 131 132 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 130 def transition(to:, if_rule: nil, requires_server: true) @transitions << Inquirex::Transition.new(target: to, rule: if_rule, requires_server:) end |