Class: OmniAI::Chat::ToolCallMessage
- Defined in:
- lib/omniai/chat/tool_call_message.rb
Overview
A specific message that contains the result of a tool call.
Instance Attribute Summary collapse
Attributes inherited from Message
#content, #role, #tool_call_list
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content:, tool_call_id:, role: OmniAI::Chat::Role::TOOL) ⇒ ToolCallMessage
constructor
A new instance of ToolCallMessage.
- #inspect ⇒ String
-
#serialize(context: nil) ⇒ Hash
Usage:.
Methods inherited from Message
#arrayify, build, #role?, #summarize, #system?, #text, #text?, #tool?, #user?
Constructor Details
#initialize(content:, tool_call_id:, role: OmniAI::Chat::Role::TOOL) ⇒ ToolCallMessage
Returns a new instance of ToolCallMessage.
12 13 14 15 |
# File 'lib/omniai/chat/tool_call_message.rb', line 12 def initialize(content:, tool_call_id:, role: OmniAI::Chat::Role::TOOL) super(content:, role:) @tool_call_id = tool_call_id end |
Instance Attribute Details
#tool_call_id ⇒ String
8 9 10 |
# File 'lib/omniai/chat/tool_call_message.rb', line 8 def tool_call_id @tool_call_id end |
Class Method Details
.deserialize(data, context: nil) ⇒ ToolMessage
Usage:
ToolCall.deserialize({ 'role' => 'tool', content: '{ 'temperature': 0 }' }) # => #<ToolCall ...>
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/omniai/chat/tool_call_message.rb', line 30 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:tool_message) return deserialize.call(data, context:) if deserialize role = data['role'] content = JSON.parse(data['content']) tool_call_id = data['tool_call_id'] new(role:, content:, tool_call_id:) end |
Instance Method Details
#inspect ⇒ String
18 19 20 |
# File 'lib/omniai/chat/tool_call_message.rb', line 18 def inspect "#<#{self.class.name} content=#{content.inspect} tool_call_id=#{tool_call_id.inspect}>" end |
#serialize(context: nil) ⇒ Hash
Usage:
.serialize # => { role: :user, content: 'Hello!' }
.serialize # => { role: :user, content: [{ type: 'text', text: 'Hello!' }] }
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omniai/chat/tool_call_message.rb', line 49 def serialize(context: nil) serializer = context&.serializer(:tool_message) return serializer.call(self, context:) if serializer role = @role content = JSON.generate(@content) tool_call_id = @tool_call_id { role:, content:, tool_call_id: } end |