Class: OmniAI::Chat::ToolCall

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/chat/tool_call.rb

Overview

A tool-call that includes an ID / function.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, function:) ⇒ ToolCall

Returns a new instance of ToolCall.

Parameters:



17
18
19
20
# File 'lib/omniai/chat/tool_call.rb', line 17

def initialize(id:, function:)
  @id = id
  @function = function
end

Instance Attribute Details

#functionFunction

Returns:



13
14
15
# File 'lib/omniai/chat/tool_call.rb', line 13

def function
  @function
end

#idString

Returns:

  • (String)


9
10
11
# File 'lib/omniai/chat/tool_call.rb', line 9

def id
  @id
end

Class Method Details

.deserialize(data, context: nil) ⇒ ToolCall

Parameters:

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

    optional

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/omniai/chat/tool_call.rb', line 31

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

  id = data["id"]
  function = Function.deserialize(data["function"], context:)

  new(id:, function:)
end

Instance Method Details

#inspectString

Returns:

  • (String)


23
24
25
# File 'lib/omniai/chat/tool_call.rb', line 23

def inspect
  "#<#{self.class.name} id=#{id.inspect} function=#{function.inspect}>"
end

#serialize(context: nil) ⇒ Hash

Parameters:

  • context (Context) (defaults to: nil)

    optional

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
52
53
# File 'lib/omniai/chat/tool_call.rb', line 44

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

  {
    id: @id,
    type: "function",
    function: @function.serialize(context:),
  }
end