Class: RubyConversations::MessagePrompt
- Inherits:
-
Object
- Object
- RubyConversations::MessagePrompt
- Includes:
- ActiveModel::Model
- Defined in:
- lib/ruby_conversations/message_prompt.rb
Overview
Represents a prompt used to generate a message in a conversation
Instance Attribute Summary collapse
-
#content ⇒ Object
Define attributes.
-
#created_at ⇒ Object
Define attributes.
-
#draft ⇒ Object
Define attributes.
-
#id ⇒ Object
Define attributes.
-
#llm ⇒ Object
Define attributes.
-
#message ⇒ Object
Define attributes.
-
#message_id ⇒ Object
Define attributes.
-
#message_inputs ⇒ Object
Define attributes.
-
#metadata ⇒ Object
Define attributes.
-
#name ⇒ Object
Define attributes.
-
#prompt_version_id ⇒ Object
Define attributes.
-
#role ⇒ Object
Define attributes.
-
#updated_at ⇒ Object
Define attributes.
Instance Method Summary collapse
-
#attributes ⇒ Object
Attributes method for serialization/logging.
-
#attributes_for_api ⇒ Object
Method for API serialization.
-
#initialize(attributes = {}) ⇒ MessagePrompt
constructor
Initialization.
-
#initialize_message_inputs(attributes_array) ⇒ Object
Handle nested inputs initialization.
-
#message_inputs_attributes=(attributes) ⇒ Object
Define nested attributes writer.
Constructor Details
#initialize(attributes = {}) ⇒ MessagePrompt
Initialization
24 25 26 27 28 29 30 31 |
# File 'lib/ruby_conversations/message_prompt.rb', line 24 def initialize(attributes = {}) @message_inputs = [] # Initialize inputs array # Extract nested inputs before super inputs_attributes = extract_nested_attributes!(attributes, :message_inputs) super (inputs_attributes) end |
Instance Attribute Details
#content ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def content @content end |
#created_at ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def created_at @created_at end |
#draft ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def draft @draft end |
#id ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def id @id end |
#llm ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def llm @llm end |
#message ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def @message end |
#message_id ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def @message_id end |
#message_inputs ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def @message_inputs end |
#metadata ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def @metadata end |
#name ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def name @name end |
#prompt_version_id ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def prompt_version_id @prompt_version_id end |
#role ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def role @role end |
#updated_at ⇒ Object
Define attributes
12 13 14 |
# File 'lib/ruby_conversations/message_prompt.rb', line 12 def updated_at @updated_at end |
Instance Method Details
#attributes ⇒ Object
Attributes method for serialization/logging
43 44 45 |
# File 'lib/ruby_conversations/message_prompt.rb', line 43 def attributes base_attributes.merge() end |
#attributes_for_api ⇒ Object
Method for API serialization
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_conversations/message_prompt.rb', line 48 def attributes_for_api { id: id, prompt_version_id: prompt_version_id, name: name, role: role, content: content, metadata: , draft: draft, ai_message_inputs_attributes: .map(&:attributes_for_api) }.compact end |
#initialize_message_inputs(attributes_array) ⇒ Object
Handle nested inputs initialization
34 35 36 37 38 39 40 |
# File 'lib/ruby_conversations/message_prompt.rb', line 34 def (attributes_array) (attributes_array || []).each do |attrs| next if attrs.blank? @message_inputs << RubyConversations::MessageInput.new(attrs) end end |
#message_inputs_attributes=(attributes) ⇒ Object
Define nested attributes writer
16 17 18 19 20 21 |
# File 'lib/ruby_conversations/message_prompt.rb', line 16 def (attributes) @message_inputs ||= [] attributes.each do |attrs| @message_inputs << RubyConversations::MessageInput.new(attrs) end end |