Class: RubyLLM::Message
- Inherits:
-
Object
- Object
- RubyLLM::Message
- Defined in:
- lib/ruby_llm/message.rb
Constant Summary collapse
- VALID_ROLES =
%i[system user assistant tool].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#token_usage ⇒ Object
readonly
Returns the value of attribute token_usage.
-
#tool_calls ⇒ Object
readonly
Returns the value of attribute tool_calls.
-
#tool_results ⇒ Object
readonly
Returns the value of attribute tool_results.
Instance Method Summary collapse
-
#initialize(role:, content: nil, tool_calls: nil, tool_results: nil, token_usage: nil, model_id: nil) ⇒ Message
constructor
A new instance of Message.
- #to_h ⇒ Object
Constructor Details
#initialize(role:, content: nil, tool_calls: nil, tool_results: nil, token_usage: nil, model_id: nil) ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_llm/message.rb', line 9 def initialize(role:, content: nil, tool_calls: nil, tool_results: nil, token_usage: nil, model_id: nil) @role = role.to_sym @content = content @tool_calls = tool_calls @tool_results = tool_results @token_usage = token_usage @model_id = model_id validate! end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def content @content end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def model_id @model_id end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def role @role end |
#token_usage ⇒ Object (readonly)
Returns the value of attribute token_usage.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def token_usage @token_usage end |
#tool_calls ⇒ Object (readonly)
Returns the value of attribute tool_calls.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def tool_calls @tool_calls end |
#tool_results ⇒ Object (readonly)
Returns the value of attribute tool_results.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def tool_results @tool_results end |
Instance Method Details
#to_h ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_llm/message.rb', line 19 def to_h { role: role, content: content, tool_calls: tool_calls, tool_results: tool_results, token_usage: token_usage, model_id: model_id }.compact end |