class Riffer::Messages::Assistant
Represents an assistant (LLM) message in a conversation.
May include tool calls when the LLM requests tool execution.
msg = Riffer::Messages::Assistant.new(โHello!โ) msg.role # => :assistant msg.content # => โHello!โ msg.tool_calls # => []
Constants
- ToolCall
Attributes
Parsed structured output hash, or nil when not applicable.
Token usage data for this response.
Array of tool calls requested by the assistant.
Public Class Methods
Source
# File lib/riffer/messages/assistant.rb, line 26 def initialize(content, tool_calls: [], token_usage: nil, structured_output: nil) super(content) @tool_calls = tool_calls @token_usage = token_usage @structured_output = structured_output end
: (String, ?tool_calls: Array, ?token_usage: Riffer::TokenUsage?, ?structured_output: Hash[Symbol, untyped]?) -> void
Calls superclass method
Riffer::Messages::Base::new
Public Instance Methods
Source
# File lib/riffer/messages/assistant.rb, line 34 def role :assistant end
: () -> Symbol
Source
# File lib/riffer/messages/assistant.rb, line 39 def structured_output? !@structured_output.nil? end
: () -> bool
Source
# File lib/riffer/messages/assistant.rb, line 46 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[:structured_output] = structured_output if structured_output? hash end
Converts the message to a hash.
: () -> Hash[Symbol, untyped]