Class: LLM::Message
- Inherits:
-
Object
- Object
- LLM::Message
- Defined in:
- lib/llm/message.rb
Instance Attribute Summary collapse
-
#role ⇒ Symbol
readonly
Returns the role of the message.
-
#content ⇒ String
readonly
Returns the content of the message.
-
#extra ⇒ Hash
readonly
Returns extra context associated with the message.
Instance Method Summary collapse
-
#initialize(role, content, extra = {}) ⇒ LLM::Message
constructor
Returns a new message.
-
#to_h ⇒ Hash
Returns a hash representation of the message.
-
#==(other) ⇒ Boolean
(also: #eql?)
Returns true when two objects have the same role and content.
-
#assistant? ⇒ Boolean
Returns true when the message is from the LLM.
-
#inspect ⇒ String
Returns a string representation of the message.
Constructor Details
#initialize(role, content, extra = {}) ⇒ LLM::Message
Returns a new message
26 27 28 29 30 |
# File 'lib/llm/message.rb', line 26 def initialize(role, content, extra = {}) @role = role.to_s @content = content @extra = extra end |
Instance Attribute Details
#role ⇒ Symbol (readonly)
Returns the role of the message
8 9 10 |
# File 'lib/llm/message.rb', line 8 def role @role end |
#content ⇒ String (readonly)
Returns the content of the message
13 14 15 |
# File 'lib/llm/message.rb', line 13 def content @content end |
#extra ⇒ Hash (readonly)
Returns extra context associated with the message
18 19 20 |
# File 'lib/llm/message.rb', line 18 def extra @extra end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the message
35 36 37 |
# File 'lib/llm/message.rb', line 35 def to_h {role:, content:} end |
#==(other) ⇒ Boolean Also known as: eql?
Returns true when two objects have the same role and content
44 45 46 47 48 49 50 |
# File 'lib/llm/message.rb', line 44 def ==(other) if other.respond_to?(:to_h) to_h == other.to_h else false end end |
#assistant? ⇒ Boolean
Returns true when the message is from the LLM
56 57 58 |
# File 'lib/llm/message.rb', line 56 def assistant? role == "assistant" || role == "model" end |
#inspect ⇒ String
Returns a string representation of the message
63 64 65 66 |
# File 'lib/llm/message.rb', line 63 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} " \ "role=#{role.inspect} content=#{content.inspect}>" end |