Class: ActivePrompt::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_prompt/base.rb

Overview

Base class for all prompt classes

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



20
21
22
23
24
25
26
# File 'lib/active_prompt/base.rb', line 20

def initialize(params = {})
  self.class.variables.each do |var|
    raise MissingVariableError, var unless params.key?(var)

    send("#{var}=", params[var]) # Dynamic method call to set the variable
  end
end

Class Method Details

.variable(name) ⇒ Object



15
16
17
18
# File 'lib/active_prompt/base.rb', line 15

def self.variable(name)
  variables << name
  attr_accessor name
end

.variablesObject



11
12
13
# File 'lib/active_prompt/base.rb', line 11

def self.variables
  @variables ||= []
end

Instance Method Details

#render_messagesObject



36
37
38
39
40
41
# File 'lib/active_prompt/base.rb', line 36

def render_messages
  [
    { role: "system", content: render_system },
    { role: "user", content: render_user }
  ]
end

#render_systemObject



28
29
30
# File 'lib/active_prompt/base.rb', line 28

def render_system
  render_template("system.liquid")
end

#render_userObject



32
33
34
# File 'lib/active_prompt/base.rb', line 32

def render_user
  render_template("user.liquid")
end

#runObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/active_prompt/base.rb', line 43

def run
  raise NotImplementedError, "Please implement this function using your chosen LLM library"
end