Class: LlmConductor::Prompts::BasePrompt

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject (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

#renderObject

Override this method in subclasses to define the prompt

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/llm_conductor/prompts/base_prompt.rb', line 16

def render
  raise NotImplementedError, 'Subclasses must implement #render method'
end

#to_sObject

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