Class: ActivePrompt::Base
- Inherits:
-
Object
- Object
- ActivePrompt::Base
- Defined in:
- lib/active_prompt/base.rb
Overview
Base class for all prompt classes
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #render_messages ⇒ Object
- #render_system ⇒ Object
- #render_user ⇒ Object
- #run ⇒ Object
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 |
.variables ⇒ Object
11 12 13 |
# File 'lib/active_prompt/base.rb', line 11 def self.variables @variables ||= [] end |
Instance Method Details
#render_messages ⇒ Object
36 37 38 39 40 41 |
# File 'lib/active_prompt/base.rb', line 36 def [ { role: "system", content: render_system }, { role: "user", content: render_user } ] end |
#render_system ⇒ Object
28 29 30 |
# File 'lib/active_prompt/base.rb', line 28 def render_system render_template("system.liquid") end |
#render_user ⇒ Object
32 33 34 |
# File 'lib/active_prompt/base.rb', line 32 def render_user render_template("user.liquid") end |
#run ⇒ Object
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 |