Class: LLM::Message
- Inherits:
-
Object
- Object
- LLM::Message
- Defined in:
- lib/llm/message.rb
Instance Attribute Summary collapse
- #content ⇒ String readonly
- #extra ⇒ Hash readonly
- #role ⇒ Symbol readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Returns true when the “other” object has the same role and content.
- #initialize(role, content, extra = {}) ⇒ LLM::Message constructor
- #logprobs ⇒ OpenStruct
- #to_h ⇒ Hash
Constructor Details
#initialize(role, content, extra = {}) ⇒ LLM::Message
22 23 24 25 26 |
# File 'lib/llm/message.rb', line 22 def initialize(role, content, extra = {}) @role = role.to_s @content = content @extra = extra end |
Instance Attribute Details
#content ⇒ String (readonly)
11 12 13 |
# File 'lib/llm/message.rb', line 11 def content @content end |
#extra ⇒ Hash (readonly)
15 16 17 |
# File 'lib/llm/message.rb', line 15 def extra @extra end |
#role ⇒ Symbol (readonly)
7 8 9 |
# File 'lib/llm/message.rb', line 7 def role @role end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true when the “other” object has the same role and content
46 47 48 49 50 51 52 |
# File 'lib/llm/message.rb', line 46 def ==(other) if other.respond_to?(:to_h) to_h == other.to_h else false end end |
#logprobs ⇒ OpenStruct
30 31 32 33 |
# File 'lib/llm/message.rb', line 30 def logprobs return nil unless extra.key?(:logprobs) OpenStruct.from_hash(extra[:logprobs]) end |
#to_h ⇒ Hash
37 38 39 |
# File 'lib/llm/message.rb', line 37 def to_h {role:, content:} end |