Class: RubyLLM::Contract::Prompt::Builder
- Inherits:
-
Object
- Object
- RubyLLM::Contract::Prompt::Builder
- Defined in:
- lib/ruby_llm/contract/prompt/builder.rb
Constant Summary collapse
- NOT_PROVIDED =
Object.new.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #build(input = NOT_PROVIDED) ⇒ Object
- #example(input:, output:) ⇒ Object
-
#initialize(block) ⇒ Builder
constructor
A new instance of Builder.
- #rule(text) ⇒ Object
- #section(name, text) ⇒ Object
- #system(text) ⇒ Object
- #user(text) ⇒ Object
Constructor Details
#initialize(block) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 9 def initialize(block) @block = block @nodes = [] end |
Class Method Details
.build(input: NOT_PROVIDED, &block) ⇒ Object
44 45 46 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 44 def self.build(input: NOT_PROVIDED, &block) new(block).build(input) end |
Instance Method Details
#build(input = NOT_PROVIDED) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 14 def build(input = NOT_PROVIDED) @nodes = [] if input != NOT_PROVIDED && @block.arity >= 1 instance_exec(input, &@block) else instance_eval(&@block) end AST.new(@nodes) end |
#example(input:, output:) ⇒ Object
32 33 34 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 32 def example(input:, output:) @nodes << Nodes::ExampleNode.new(input: input, output: output) end |
#rule(text) ⇒ Object
28 29 30 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 28 def rule(text) @nodes << Nodes::RuleNode.new(text) end |
#section(name, text) ⇒ Object
40 41 42 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 40 def section(name, text) @nodes << Nodes::SectionNode.new(name, text) end |
#system(text) ⇒ Object
24 25 26 |
# File 'lib/ruby_llm/contract/prompt/builder.rb', line 24 def system(text) @nodes << Nodes::SystemNode.new(text) end |