Class: LlmConductor::Prompts::BasePrompt
- Inherits:
-
Object
- Object
- LlmConductor::Prompts::BasePrompt
- Defined in:
- lib/llm_conductor/prompts/base_prompt.rb
Overview
Base class for all prompt templates Provides common functionality and data access patterns
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#data_dig(*keys) ⇒ Object
(also: #dig)
Safe access to nested hash values.
-
#initialize(data = {}) ⇒ BasePrompt
constructor
A new instance of BasePrompt.
-
#render ⇒ Object
Override this method in subclasses to define the prompt.
-
#to_s ⇒ Object
Get the rendered prompt as a string.
Constructor Details
#initialize(data = {}) ⇒ BasePrompt
Returns a new instance of BasePrompt.
10 11 12 13 |
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 10 def initialize(data = {}) @data = data || {} setup_data_methods end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
Handle missing methods by checking data hash
73 74 75 76 77 78 79 80 81 |
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 73 def method_missing(method_name, *args, &block) if @data.respond_to?(:[]) && @data.key?(method_name) @data[method_name] elsif @data.respond_to?(:[]) && @data.key?(method_name.to_s) @data[method_name.to_s] else super end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 8 def data @data end |
Instance Method Details
#data_dig(*keys) ⇒ Object Also known as: dig
Safe access to nested hash values
26 27 28 |
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 26 def data_dig(*keys) @data.dig(*keys) if @data.respond_to?(:dig) end |
#render ⇒ Object
Override this method in subclasses to define the prompt
16 17 18 |
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 16 def render raise NotImplementedError, 'Subclasses must implement #render method' end |
#to_s ⇒ Object
Get the rendered prompt as a string
21 22 23 |
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 21 def to_s render.strip end |