Class: Intelligence::Conversation
- Inherits:
-
Object
- Object
- Intelligence::Conversation
- Includes:
- DynamicSchema::Buildable, DynamicSchema::Definable
- 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.
Instance Method Summary collapse
- #append_message(*messages) ⇒ Object (also: #<<)
- #has_messages? ⇒ Boolean
- #has_system_message? ⇒ 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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/intelligence/conversation.rb', line 15 def initialize( attributes = nil ) @messages = [] if attributes if attributes[ :system_message ]&.any? = 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.
13 14 15 |
# File 'lib/intelligence/conversation.rb', line 13 def @messages end |
#system_message ⇒ Object
Returns the value of attribute system_message.
12 13 14 |
# File 'lib/intelligence/conversation.rb', line 12 def @system_message end |
Instance Method Details
#append_message(*messages) ⇒ Object Also known as: <<
50 51 52 53 |
# File 'lib/intelligence/conversation.rb', line 50 def ( * ) @messages.concat( .flatten ) self end |
#has_messages? ⇒ Boolean
38 39 40 |
# File 'lib/intelligence/conversation.rb', line 38 def !@messages.empty? end |
#has_system_message? ⇒ Boolean
34 35 36 |
# File 'lib/intelligence/conversation.rb', line 34 def ( @system_message || false ) && !@system_message.empty? end |
#to_h ⇒ Object
57 58 59 60 61 62 |
# File 'lib/intelligence/conversation.rb', line 57 def to_h result = {} result[ :system_message ] = @system_message.to_h if @system_message result[ :messages ] = @messages.map { | m | m.to_h } result end |