Class: Intelligence::Conversation
- Inherits:
-
Object
- Object
- Intelligence::Conversation
- Extended by:
- AdaptiveConfiguration::Configurable
- Defined in:
- lib/intelligence/conversation.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#system_message ⇒ Object
Returns the value of attribute system_message.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Class Method Summary collapse
Instance Method Summary collapse
- #append_message(*messages) ⇒ Object (also: #<<)
- #has_messages? ⇒ Boolean
- #has_system_message? ⇒ Boolean
- #has_tools? ⇒ Boolean
-
#initialize(attributes = nil) ⇒ Conversation
constructor
A new instance of Conversation.
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = nil) ⇒ Conversation
Returns a new instance of Conversation.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/intelligence/conversation.rb', line 20 def initialize( attributes = nil ) @messages = [] @tools = [] if attributes if attributes[ :system_message ] = Message.new( attributes[ :system_message ][ :role ], attributes[ :system_message ] ) @system_message = unless .empty? end attributes[ :messages ]&.each do | | @messages << Message.new( [ :role ], ) end end end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
17 18 19 |
# File 'lib/intelligence/conversation.rb', line 17 def @messages end |
#system_message ⇒ Object
Returns the value of attribute system_message.
16 17 18 |
# File 'lib/intelligence/conversation.rb', line 16 def @system_message end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
18 19 20 |
# File 'lib/intelligence/conversation.rb', line 18 def tools @tools end |
Class Method Details
.build(attributes = nil, &block) ⇒ Object
11 12 13 14 |
# File 'lib/intelligence/conversation.rb', line 11 def self.build( attributes = nil, &block ) configuration = self.configure( attributes, &block ) self.new( configuration.to_h ) end |
Instance Method Details
#append_message(*messages) ⇒ Object Also known as: <<
60 61 62 63 |
# File 'lib/intelligence/conversation.rb', line 60 def ( * ) @messages.concat( .flatten ) self end |
#has_messages? ⇒ Boolean
44 45 46 |
# File 'lib/intelligence/conversation.rb', line 44 def !@messages.empty? end |
#has_system_message? ⇒ Boolean
40 41 42 |
# File 'lib/intelligence/conversation.rb', line 40 def ( @system_message || false ) && !@system_message.empty? end |
#has_tools? ⇒ Boolean
48 49 50 |
# File 'lib/intelligence/conversation.rb', line 48 def has_tools? !@tools.empty? end |
#to_h ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/intelligence/conversation.rb', line 67 def to_h result = {} result[ :system_message ] = @system_message.to_h if @system_message result[ :messages ] = @messages.map { | m | m.to_h } result[ :tools ] = @tools.map { | t | t.to_h } result end |