Class: Vapi::ToolCall

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/tool_call.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, function:, id:, additional_properties: nil) ⇒ Vapi::ToolCall

Parameters:

  • type (String)

    This is the type of tool the model called.

  • function (Vapi::ToolCallFunction)

    This is the function the model called.

  • id (String)

    This is the unique identifier for the tool call.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



28
29
30
31
32
33
34
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 28

def initialize(type:, function:, id:, additional_properties: nil)
  @type = type
  @function = function
  @id = id
  @additional_properties = additional_properties
  @_field_set = { "type": type, "function": function, "id": id }
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



16
17
18
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 16

def additional_properties
  @additional_properties
end

#functionVapi::ToolCallFunction (readonly)

Returns This is the function the model called.

Returns:



12
13
14
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 12

def function
  @function
end

#idString (readonly)

Returns This is the unique identifier for the tool call.

Returns:

  • (String)

    This is the unique identifier for the tool call.



14
15
16
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 14

def id
  @id
end

#typeString (readonly)

Returns This is the type of tool the model called.

Returns:

  • (String)

    This is the type of tool the model called.



10
11
12
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 10

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::ToolCall

Deserialize a JSON object to an instance of ToolCall

Parameters:

  • json_object (String)

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 40

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  type = parsed_json["type"]
  if parsed_json["function"].nil?
    function = nil
  else
    function = parsed_json["function"].to_json
    function = Vapi::ToolCallFunction.from_json(json_object: function)
  end
  id = parsed_json["id"]
  new(
    type: type,
    function: function,
    id: id,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


72
73
74
75
76
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 72

def self.validate_raw(obj:)
  obj.type.is_a?(String) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  Vapi::ToolCallFunction.validate_raw(obj: obj.function)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of ToolCall to a JSON object

Returns:

  • (String)


62
63
64
# File 'lib/vapi_server_sdk/types/tool_call.rb', line 62

def to_json(*_args)
  @_field_set&.to_json
end