Class: RubyConversations::Prompt
- Inherits:
-
Object
- Object
- RubyConversations::Prompt
- Defined in:
- lib/ruby_conversations/prompt.rb
Overview
Represents a prompt template used to generate AI messages.
Constant Summary collapse
- ROLES =
Constants
%w[system user assistant].freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Define attributes.
-
#id ⇒ Object
Define attributes.
-
#latest_version_id ⇒ Object
Define attributes.
-
#llm ⇒ Object
Define attributes.
-
#message ⇒ Object
Define attributes.
-
#metadata ⇒ Object
Define attributes.
-
#name ⇒ Object
Define attributes.
-
#role ⇒ Object
Define attributes.
-
#temperature ⇒ Object
Define attributes.
-
#updated_at ⇒ Object
Define attributes.
-
#valid_placeholders ⇒ Object
Define attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ Object
Basic attributes method.
-
#attributes_for_api ⇒ Object
Method for API serialization.
-
#initialize(attributes = {}) ⇒ Prompt
constructor
A new instance of Prompt.
-
#interpolate(variables = {}) ⇒ Object
Interpolate placeholders in the message.
Constructor Details
#initialize(attributes = {}) ⇒ Prompt
Returns a new instance of Prompt.
15 16 17 18 19 |
# File 'lib/ruby_conversations/prompt.rb', line 15 def initialize(attributes = {}) attributes.each do |key, value| public_send("#{key}=", value) if respond_to?("#{key}=") end end |
Instance Attribute Details
#created_at ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def created_at @created_at end |
#id ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def id @id end |
#latest_version_id ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def latest_version_id @latest_version_id end |
#llm ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def llm @llm end |
#message ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def @message end |
#metadata ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def @metadata end |
#name ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def name @name end |
#role ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def role @role end |
#temperature ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def temperature @temperature end |
#updated_at ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def updated_at @updated_at end |
#valid_placeholders ⇒ Object
Define attributes
9 10 11 |
# File 'lib/ruby_conversations/prompt.rb', line 9 def valid_placeholders @valid_placeholders end |
Class Method Details
.find_by!(conditions) ⇒ Object
33 34 35 36 |
# File 'lib/ruby_conversations/prompt.rb', line 33 def self.find_by!(conditions) name = conditions[:name] find_by_name!(name) end |
.find_by_name!(name) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ruby_conversations/prompt.rb', line 26 def self.find_by_name!(name) prompt_data = RubyConversations.client.fetch_prompt(name) raise "Prompt not found: #{name}" unless prompt_data new(prompt_data) end |
.roles ⇒ Object
Class methods
22 23 24 |
# File 'lib/ruby_conversations/prompt.rb', line 22 def self.roles ROLES end |
Instance Method Details
#attributes ⇒ Object
Basic attributes method
39 40 41 42 43 44 45 46 |
# File 'lib/ruby_conversations/prompt.rb', line 39 def attributes { 'id' => id, 'name' => name, 'role' => role, 'message' => , 'valid_placeholders' => valid_placeholders, 'temperature' => temperature, 'metadata' => , 'created_at' => created_at, 'updated_at' => updated_at, 'latest_version_id' => latest_version_id, 'llm' => llm } end |
#attributes_for_api ⇒ Object
Method for API serialization
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_conversations/prompt.rb', line 49 def attributes_for_api { id: id, name: name, role: role, message: , valid_placeholders: valid_placeholders, temperature: temperature, metadata: , latest_version_id: latest_version_id }.compact end |
#interpolate(variables = {}) ⇒ Object
Interpolate placeholders in the message
63 64 65 66 67 |
# File 'lib/ruby_conversations/prompt.rb', line 63 def interpolate(variables = {}) return if .nil? || variables.empty? format(, **variables) end |