Class: RubyLLM::Message
- Inherits:
-
Object
- Object
- RubyLLM::Message
- Defined in:
- lib/ruby_llm/message.rb
Direct Known Subclasses
Constant Summary collapse
- ROLES =
%i[system user assistant tool].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#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(options = {}) ⇒ Message
constructor
A new instance of Message.
- #to_h ⇒ Object
- #tool_call? ⇒ Boolean
- #tool_result? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_llm/message.rb', line 9 def initialize( = {}) @role = [:role].to_sym @content = [:content] @tool_calls = [:tool_calls] @tool_results = [:tool_results] @input_tokens = [:input_tokens] @output_tokens = [:output_tokens] @model_id = [:model_id] ensure_valid_role 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 |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def input_tokens @input_tokens 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 |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens.
7 8 9 |
# File 'lib/ruby_llm/message.rb', line 7 def output_tokens @output_tokens 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 |
#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
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_llm/message.rb', line 29 def to_h { role: role, content: content, tool_calls: tool_calls, tool_results: tool_results, input_tokens: input_tokens, output_tokens: output_tokens, model_id: model_id }.compact end |
#tool_call? ⇒ Boolean
21 22 23 |
# File 'lib/ruby_llm/message.rb', line 21 def tool_call? !tool_calls.nil? && !tool_calls.empty? end |
#tool_result? ⇒ Boolean
25 26 27 |
# File 'lib/ruby_llm/message.rb', line 25 def tool_result? !tool_results.nil? && !tool_results.empty? end |