Class: Riffer::Messages::Assistant
- Defined in:
- lib/riffer/messages/assistant.rb
Overview
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
Creates a new assistant message.
-
#role ⇒ Object
Returns :assistant.
-
#to_h ⇒ Object
Converts the message to a hash.
Constructor Details
#initialize(content, tool_calls: [], token_usage: nil) ⇒ Assistant
Creates a new assistant message.
- content
-
String - the message content
- tool_calls
-
Array of Hash - optional tool calls
- token_usage
-
Riffer::TokenUsage or nil - optional token usage data
30 31 32 33 34 |
# File 'lib/riffer/messages/assistant.rb', line 30 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.
Returns Riffer::TokenUsage or nil.
23 24 25 |
# File 'lib/riffer/messages/assistant.rb', line 23 def token_usage @token_usage end |
#tool_calls ⇒ Object (readonly)
Array of tool calls requested by the assistant.
Each tool call is a Hash with :id, :call_id, :name, and :arguments keys.
Returns Array of Hash.
18 19 20 |
# File 'lib/riffer/messages/assistant.rb', line 18 def tool_calls @tool_calls end |
Instance Method Details
#role ⇒ Object
Returns :assistant.
37 38 39 |
# File 'lib/riffer/messages/assistant.rb', line 37 def role :assistant end |
#to_h ⇒ Object
Converts the message to a hash.
Returns Hash with :role, :content, and optionally :tool_calls and :token_usage.
44 45 46 47 48 49 |
# File 'lib/riffer/messages/assistant.rb', line 44 def to_h hash = {role: role, content: content} hash[:tool_calls] = tool_calls unless tool_calls.empty? hash[:token_usage] = token_usage.to_h if token_usage hash end |