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
- #content ⇒ Object
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #tool_call_id ⇒ ToolCall
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content:, tool_call_id:, **options) ⇒ 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:, **options) ⇒ ToolCallResult
Returns a new instance of ToolCallResult.
22 23 24 25 26 |
# File 'lib/omniai/chat/tool_call_result.rb', line 22 def initialize(content:, tool_call_id:, **) @content = content @tool_call_id = tool_call_id @options = end |
Instance Attribute Details
#content ⇒ Object
9 10 11 |
# File 'lib/omniai/chat/tool_call_result.rb', line 9 def content @content end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/omniai/chat/tool_call_result.rb', line 17 def @options 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
59 60 61 62 63 64 65 66 67 |
# File 'lib/omniai/chat/tool_call_result.rb', line 59 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
29 30 31 |
# File 'lib/omniai/chat/tool_call_result.rb', line 29 def inspect "#<#{self.class.name} content=#{content.inspect} tool_call_id=#{tool_call_id.inspect}>" end |
#serialize(context: nil) ⇒ Hash
45 46 47 48 49 50 51 52 53 |
# File 'lib/omniai/chat/tool_call_result.rb', line 45 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.
36 37 38 39 40 |
# File 'lib/omniai/chat/tool_call_result.rb', line 36 def text return content if content.nil? || content.is_a?(String) JSON.generate(@content) end |