Class: OmniAI::Chat::ToolCallResult
- Inherits:
-
Object
- Object
- OmniAI::Chat::ToolCallResult
- Defined in:
- lib/omniai/chat/tool_call_result.rb
Overview
The result of a tool call.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content:, tool_call_id:) ⇒ ToolCallResult
constructor
A new instance of ToolCallResult.
- #inspect ⇒ String
- #serialize(context: nil) ⇒ Hash
-
#text ⇒ String?
Converts the content of a tool call result to JSON unless the result is a string.
Constructor Details
#initialize(content:, tool_call_id:) ⇒ ToolCallResult
Returns a new instance of ToolCallResult.
17 18 19 20 |
# File 'lib/omniai/chat/tool_call_result.rb', line 17 def initialize(content:, tool_call_id:) @content = content @tool_call_id = tool_call_id end |
Instance Attribute Details
#content ⇒ Object
9 10 11 |
# File 'lib/omniai/chat/tool_call_result.rb', line 9 def content @content end |
#tool_call_id ⇒ ToolCall
13 14 15 |
# File 'lib/omniai/chat/tool_call_result.rb', line 13 def tool_call_id @tool_call_id end |
Class Method Details
.deserialize(data, context: nil) ⇒ ToolCallResult
53 54 55 56 57 58 59 60 61 |
# File 'lib/omniai/chat/tool_call_result.rb', line 53 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:tool_call_result) return deserialize.call(data, context:) if deserialize content = data["content"] tool_call_id = data["tool_call_id"] new(content:, tool_call_id:) end |
Instance Method Details
#inspect ⇒ String
23 24 25 |
# File 'lib/omniai/chat/tool_call_result.rb', line 23 def inspect "#<#{self.class.name} content=#{content.inspect} tool_call_id=#{tool_call_id.inspect}>" end |
#serialize(context: nil) ⇒ Hash
39 40 41 42 43 44 45 46 47 |
# File 'lib/omniai/chat/tool_call_result.rb', line 39 def serialize(context: nil) serializer = context&.serializer(:tool_call_result) return serializer.call(self, context:) if serializer content = text tool_call_id = @tool_call_id { content:, tool_call_id: } end |
#text ⇒ String?
Converts the content of a tool call result to JSON unless the result is a string.
30 31 32 33 34 |
# File 'lib/omniai/chat/tool_call_result.rb', line 30 def text return content if content.nil? || content.is_a?(String) JSON.generate(@content) end |