Class: Crimson::Message::Assistant
Overview
An assistant (model) response, optionally containing tool calls.
Instance Attribute Summary collapse
- #content ⇒ String, ... readonly
- #tool_calls ⇒ String, ... readonly
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(content: nil, tool_calls: []) ⇒ Assistant
constructor
A new instance of Assistant.
-
#to_anthropic_h ⇒ Hash
Anthropic-compatible representation.
-
#to_openai_h ⇒ Hash
OpenAI-compatible representation.
-
#tool_call? ⇒ Boolean
Whether this message contains tool calls.
Constructor Details
#initialize(content: nil, tool_calls: []) ⇒ Assistant
Returns a new instance of Assistant.
72 73 74 75 76 |
# File 'lib/crimson/message.rb', line 72 def initialize(content: nil, tool_calls: []) super("assistant") @content = content @tool_calls = tool_calls end |
Instance Attribute Details
#content ⇒ String, ... (readonly)
68 69 70 |
# File 'lib/crimson/message.rb', line 68 def content @content end |
#tool_calls ⇒ String, ... (readonly)
68 69 70 |
# File 'lib/crimson/message.rb', line 68 def tool_calls @tool_calls end |
Instance Method Details
#to_anthropic_h ⇒ Hash
Returns Anthropic-compatible representation.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/crimson/message.rb', line 92 def to_anthropic_h content_blocks = [] content_blocks << { type: "text", text: @content } if @content && !@content.empty? @tool_calls.each do |tc| content_blocks << { type: "tool_use", id: tc.id, name: tc.name, input: tc.arguments } end { role: "assistant", content: content_blocks } end |
#to_openai_h ⇒ Hash
Returns OpenAI-compatible representation.
84 85 86 87 88 89 |
# File 'lib/crimson/message.rb', line 84 def to_openai_h h = { role: "assistant" } h[:content] = @content if @content h[:tool_calls] = @tool_calls.map(&:to_openai_h) if tool_call? h end |
#tool_call? ⇒ Boolean
Returns whether this message contains tool calls.
79 80 81 |
# File 'lib/crimson/message.rb', line 79 def tool_call? !@tool_calls.nil? && !@tool_calls.empty? end |