Module: OllamaChat::MessageMixin
- Included in:
- Message
- Defined in:
- lib/ollama_chat/message.rb
Overview
Mixin to provide write access to attributes that are read-only in the base class and add utility methods for content cleaning.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#as_json(*a) ⇒ Hash
Converts the message to a JSON-compatible hash, including the sender name if present.
-
#initialize(**attributes) ⇒ Object
Initializes a new message, ensuring the sender_name is set if provided.
-
#tool? ⇒ Boolean
Returns true if the message is a tool message.
Instance Attribute Details
#content ⇒ Object
20 |
# File 'lib/ollama_chat/message.rb', line 20 attr_writer :content |
#images ⇒ Object
28 |
# File 'lib/ollama_chat/message.rb', line 28 attr_writer :images |
#sender_name ⇒ Object
33 34 35 |
# File 'lib/ollama_chat/message.rb', line 33 def sender_name @sender_name end |
#thinking ⇒ Object
24 |
# File 'lib/ollama_chat/message.rb', line 24 attr_writer :thinking |
Instance Method Details
#as_json(*a) ⇒ Hash
Converts the message to a JSON-compatible hash, including the sender name if present.
47 48 49 50 51 52 53 |
# File 'lib/ollama_chat/message.rb', line 47 def as_json(*a) if sender_name { sender_name: } | super else super end end |
#initialize(**attributes) ⇒ Object
Initializes a new message, ensuring the sender_name is set if provided.
11 12 13 14 15 16 |
# File 'lib/ollama_chat/message.rb', line 11 def initialize(**attributes) super if sender_name = attributes[:sender_name] self.sender_name = sender_name end end |
#tool? ⇒ Boolean
Returns true if the message is a tool message.
39 40 41 |
# File 'lib/ollama_chat/message.rb', line 39 def tool? tool_name.present? end |