Class: Riffer::Messages::Assistant
- Defined in:
- lib/riffer/messages/assistant.rb
Overview
Defined Under Namespace
Classes: ToolCall
Instance Attribute Summary collapse
-
#token_usage ⇒ Object
readonly
Token usage data for this response.
-
#tool_calls ⇒ Object
readonly
Array of tool calls requested by the assistant.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(content, tool_calls: [], token_usage: nil) ⇒ Assistant
constructor
: (String, ?tool_calls: Array, ?token_usage: Riffer::TokenUsage?) -> void.
-
#role ⇒ Object
: () -> Symbol.
-
#to_h ⇒ Object
Converts the message to a hash.
Constructor Details
#initialize(content, tool_calls: [], token_usage: nil) ⇒ Assistant
: (String, ?tool_calls: Array, ?token_usage: Riffer::TokenUsage?) -> void
23 24 25 26 27 |
# File 'lib/riffer/messages/assistant.rb', line 23 def initialize(content, tool_calls: [], token_usage: nil) super(content) @tool_calls = tool_calls @token_usage = token_usage end |
Instance Attribute Details
#token_usage ⇒ Object (readonly)
Token usage data for this response.
20 21 22 |
# File 'lib/riffer/messages/assistant.rb', line 20 def token_usage @token_usage end |
#tool_calls ⇒ Object (readonly)
Array of tool calls requested by the assistant.
17 18 19 |
# File 'lib/riffer/messages/assistant.rb', line 17 def tool_calls @tool_calls end |
Instance Method Details
#role ⇒ Object
: () -> Symbol
30 31 32 |
# File 'lib/riffer/messages/assistant.rb', line 30 def role :assistant end |
#to_h ⇒ Object
Converts the message to a hash.
: () -> Hash[Symbol, untyped]
37 38 39 40 41 42 |
# File 'lib/riffer/messages/assistant.rb', line 37 def to_h hash = {role: role, content: content} hash[:tool_calls] = tool_calls.map(&:to_h) unless tool_calls.empty? hash[:token_usage] = token_usage.to_h if token_usage hash end |