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(id:, type:, function:, additional_properties: nil) ⇒ Vapi::ToolCall



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

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

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)



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

def additional_properties
  @additional_properties
end

#functionVapi::ToolCallFunction (readonly)



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

def function
  @function
end

#idString (readonly)



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

def id
  @id
end

#typeString (readonly)



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

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::ToolCall

Deserialize a JSON object to an instance of ToolCall



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)
  id = parsed_json["id"]
  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
  new(
    id: id,
    type: type,
    function: function,
    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.


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

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  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)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of ToolCall to a JSON object



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

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