Class: ActiveAgent::ActionPrompt::Message
- Inherits:
-
Object
- Object
- ActiveAgent::ActionPrompt::Message
- Defined in:
- lib/active_agent/action_prompt/message.rb
Constant Summary collapse
- VALID_ROLES =
%w[system assistant user tool].freeze
Instance Attribute Summary collapse
-
#action_id ⇒ Object
Returns the value of attribute action_id.
-
#action_name ⇒ Object
Returns the value of attribute action_name.
-
#action_requested ⇒ Object
Returns the value of attribute action_requested.
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#generation_id ⇒ Object
Returns the value of attribute generation_id.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#raw_actions ⇒ Object
Returns the value of attribute raw_actions.
-
#raw_content ⇒ Object
Returns the value of attribute raw_content.
-
#requested_actions ⇒ Object
Returns the value of attribute requested_actions.
-
#role ⇒ Object
Returns the value of attribute role.
Class Method Summary collapse
Instance Method Summary collapse
- #embed ⇒ Object
-
#initialize(attributes = {}) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Message
Returns a new instance of Message.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_agent/action_prompt/message.rb', line 23 def initialize(attributes = {}) @action_id = attributes[:action_id] @action_name = attributes[:action_name] @generation_id = attributes[:generation_id] @metadata = attributes[:metadata] || {} @charset = attributes[:charset] || "UTF-8" @raw_content = attributes[:content] || "" @content_type = detect_content_type(attributes) @content = parse_content(@raw_content, @content_type) @role = attributes[:role] || :user @raw_actions = attributes[:raw_actions] @requested_actions = attributes[:requested_actions] || [] @action_requested = @requested_actions.any? validate_role end |
Instance Attribute Details
#action_id ⇒ Object
Returns the value of attribute action_id.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def action_id @action_id end |
#action_name ⇒ Object
Returns the value of attribute action_name.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def action_name @action_name end |
#action_requested ⇒ Object
Returns the value of attribute action_requested.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def action_requested @action_requested end |
#charset ⇒ Object
Returns the value of attribute charset.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def charset @charset end |
#content ⇒ Object
Returns the value of attribute content.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def content @content end |
#content_type ⇒ Object
Returns the value of attribute content_type.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def content_type @content_type end |
#generation_id ⇒ Object
Returns the value of attribute generation_id.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def generation_id @generation_id end |
#metadata ⇒ Object
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def @metadata end |
#raw_actions ⇒ Object
Returns the value of attribute raw_actions.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def raw_actions @raw_actions end |
#raw_content ⇒ Object
Returns the value of attribute raw_content.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def raw_content @raw_content end |
#requested_actions ⇒ Object
Returns the value of attribute requested_actions.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def requested_actions @requested_actions end |
#role ⇒ Object
Returns the value of attribute role.
21 22 23 |
# File 'lib/active_agent/action_prompt/message.rb', line 21 def role @role end |
Class Method Details
.from_messages(messages) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_agent/action_prompt/message.rb', line 5 def () return if .empty? || .first.is_a?(Message) .map do || if .is_a?(Hash) new() elsif .is_a?(Message) else raise ArgumentError, "Messages must be Hash or Message objects" end end end |
Instance Method Details
#embed ⇒ Object
59 60 61 |
# File 'lib/active_agent/action_prompt/message.rb', line 59 def @agent_class.(@content) end |
#inspect ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/active_agent/action_prompt/message.rb', line 63 def inspect truncated_content = if @content.is_a?(String) && @content.length > 256 @content[0, 256] + "..." elsif @content.is_a?(Array) @content.map do |item| if item.is_a?(String) && item.length > 256 item[0, 256] + "..." else item end end else @content end "#<#{self.class}:0x#{object_id.to_s(16)}\n" + " @action_id=#{@action_id.inspect},\n" + " @action_name=#{@action_name.inspect},\n" + " @action_requested=#{@action_requested.inspect},\n" + " @charset=#{@charset.inspect},\n" + " @content=#{truncated_content.inspect},\n" + " @role=#{@role.inspect}>" end |
#to_h ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/active_agent/action_prompt/message.rb', line 43 def to_h hash = { role: role, action_id: action_id, name: action_name, generation_id: generation_id, content: content, type: content_type, charset: charset } hash[:action_requested] = requested_actions.any? hash[:requested_actions] = requested_actions if requested_actions.any? hash end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/active_agent/action_prompt/message.rb', line 39 def to_s @content.to_s end |