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) ⇒ 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 (used by describe/summarize for user-visible labels).
-
#schema(**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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 22 def initialize(verb) @verb = verb.to_sym @prompt = nil @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) ⇒ LLM::Node
Builds the LLM::Node.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 134 def build(id) validate!(id) schema_obj = @schema_fields.empty? ? nil : Schema.new(**@schema_fields) LLM::Node.new( id:, verb: @verb, prompt: @prompt, 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.
94 95 96 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 94 def fallback(&block) @fallback = block end |
#from(*step_ids) ⇒ Object
Adds source step id(s) whose answers feed the LLM prompt.
57 58 59 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 57 def from(*step_ids) @from_steps.concat(step_ids.flatten) end |
#from_all(value = true) ⇒ Object
Passes all collected answers to the LLM prompt.
64 65 66 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 64 def from_all(value = true) @from_all = !!value end |
#max_tokens(value) ⇒ Object
Optional maximum output tokens.
85 86 87 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 85 def max_tokens(value) @max_tokens = value.to_i end |
#model(name) ⇒ Object
Optional model hint for the adapter.
71 72 73 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 71 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.
42 43 44 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 42 def prompt(text) @prompt = text end |
#question(content) ⇒ Object
Optional display text (used by describe/summarize for user-visible labels).
118 119 120 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 118 def question(content) @question = content end |
#schema(**fields) ⇒ Object
Declares the expected output schema. Each key is a field name, each value is an Inquirex data type symbol.
50 51 52 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 50 def schema(**fields) @schema_fields.merge!(fields) end |
#skip_if(rule) ⇒ Object
Sets a rule that skips this step entirely when true.
111 112 113 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 111 def skip_if(rule) @skip_if = rule end |
#temperature(value) ⇒ Object
Optional sampling temperature.
78 79 80 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 78 def temperature(value) @temperature = value.to_f end |
#text(content) ⇒ Object
Optional display text for context.
125 126 127 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 125 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.
104 105 106 |
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 104 def transition(to:, if_rule: nil, requires_server: true) @transitions << Inquirex::Transition.new(target: to, rule: if_rule, requires_server:) end |