Class: Riffer::Messages::Assistant
- Defined in:
- lib/riffer/messages/assistant.rb
Overview
Defined Under Namespace
Classes: ToolCall
Instance Attribute Summary collapse
-
#structured_output ⇒ Object
readonly
Parsed structured output hash, or nil when not applicable.
-
#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
-
#+(other) ⇒ Object
– : (Riffer::Messages::Assistant) -> Riffer::Messages::Assistant.
-
#initialize(content, tool_calls: [], token_usage: nil, structured_output: nil) ⇒ Assistant
constructor
– : (String, ?tool_calls: Array, ?token_usage: Riffer::TokenUsage?, ?structured_output: Hash[Symbol, untyped]?) -> void.
-
#role ⇒ Object
– : () -> Symbol.
-
#structured_output? ⇒ Boolean
– : () -> bool.
-
#to_h ⇒ Object
Converts the message to a hash.
Constructor Details
#initialize(content, tool_calls: [], token_usage: nil, structured_output: nil) ⇒ Assistant
– : (String, ?tool_calls: Array, ?token_usage: Riffer::TokenUsage?, ?structured_output: Hash[Symbol, untyped]?) -> void
27 28 29 30 31 32 |
# File 'lib/riffer/messages/assistant.rb', line 27 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 |
Instance Attribute Details
#structured_output ⇒ Object (readonly)
Parsed structured output hash, or nil when not applicable.
23 24 25 |
# File 'lib/riffer/messages/assistant.rb', line 23 def structured_output @structured_output end |
#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
#+(other) ⇒ Object
– : (Riffer::Messages::Assistant) -> Riffer::Messages::Assistant
48 49 50 |
# File 'lib/riffer/messages/assistant.rb', line 48 def +(other) self.class.new("#{content}\n\n#{other.content}", tool_calls: tool_calls + other.tool_calls) end |
#role ⇒ Object
– : () -> Symbol
36 37 38 |
# File 'lib/riffer/messages/assistant.rb', line 36 def role :assistant end |
#structured_output? ⇒ Boolean
– : () -> bool
42 43 44 |
# File 'lib/riffer/messages/assistant.rb', line 42 def structured_output? !@structured_output.nil? end |
#to_h ⇒ Object
Converts the message to a hash.
– : () -> Hash[Symbol, untyped]
56 57 58 59 60 61 62 |
# File 'lib/riffer/messages/assistant.rb', line 56 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 |