Class: OmniAI::Chat::ToolCallResult

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(content:, tool_call_id:) ⇒ ToolCallResult

Returns a new instance of ToolCallResult.

Parameters:

  • content (Object)
  • tool_call_id (String)


15
16
17
18
# File 'lib/omniai/chat/tool_call_result.rb', line 15

def initialize(content:, tool_call_id:)
  @content = content
  @tool_call_id = tool_call_id
end

Instance Attribute Details

#contentObject

Returns:

  • (Object)


8
9
10
# File 'lib/omniai/chat/tool_call_result.rb', line 8

def content
  @content
end

#tool_call_idToolCall

Returns:



11
12
13
# File 'lib/omniai/chat/tool_call_result.rb', line 11

def tool_call_id
  @tool_call_id
end

Class Method Details

.deserialize(data, context: nil) ⇒ ToolCallResult

Parameters:

  • data (Hash)
  • context (Context) (defaults to: nil)

    optional

Returns:



40
41
42
43
44
45
46
47
48
# File 'lib/omniai/chat/tool_call_result.rb', line 40

def self.deserialize(data, context: nil)
  deserialize = context&.deserializer(:tool_call_result)
  return deserialize.call(data, context:) if deserialize

  content = JSON.parse(data['content'])
  tool_call_id = data['tool_call_id']

  new(content:, tool_call_id:)
end

Instance Method Details

#inspectString

Returns:

  • (String)


21
22
23
# File 'lib/omniai/chat/tool_call_result.rb', line 21

def inspect
  "#<#{self.class.name} content=#{content.inspect} tool_call_id=#{tool_call_id.inspect}>"
end

#serialize(context: nil) ⇒ Hash

Parameters:

  • context (Context) (defaults to: nil)

    optional

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
35
# File 'lib/omniai/chat/tool_call_result.rb', line 27

def serialize(context: nil)
  serializer = context&.serializer(:tool_call_result)
  return serializer.call(self, context:) if serializer

  content = JSON.generate(@content)
  tool_call_id = @tool_call_id

  { content:, tool_call_id: }
end