Class: RubyLLM::Contract::Step::PromptCompiler
- Inherits:
-
Object
- Object
- RubyLLM::Contract::Step::PromptCompiler
- Defined in:
- lib/ruby_llm/contract/step/prompt_compiler.rb
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(prompt_block:) ⇒ PromptCompiler
constructor
A new instance of PromptCompiler.
Constructor Details
#initialize(prompt_block:) ⇒ PromptCompiler
Returns a new instance of PromptCompiler.
7 8 9 |
# File 'lib/ruby_llm/contract/step/prompt_compiler.rb', line 7 def initialize(prompt_block:) @prompt_block = prompt_block end |
Instance Method Details
#call(input) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_llm/contract/step/prompt_compiler.rb', line 11 def call(input) dynamic_prompt = @prompt_block.arity >= 1 builder_input = dynamic_prompt ? input : nil ast = Prompt::Builder.build(input: builder_input, &@prompt_block) Prompt::Renderer.render(ast, variables: template_variables_for(input, dynamic_prompt)) rescue StandardError => error raise RubyLLM::Contract::Error, "Prompt build failed: #{error.class}: #{error.}" end |