Class: Vapi::ToolCallResult

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, tool_call_id:, message: OMIT, result: OMIT, error: OMIT, additional_properties: nil) ⇒ Vapi::ToolCallResult

Parameters:

  • message (Array<Vapi::ToolCallResultMessageItem>) (defaults to: OMIT)

    This is the message that will be spoken to the user. If this is not returned, assistant will speak:

    1. a ‘request-complete` or `request-failed` message from `tool.messages`, if it

    exists

    1. a response generated by the model, if not

  • name (String)

    This is the name of the function the model called.

  • tool_call_id (String)

    This is the unique identifier for the tool call.

  • result (String) (defaults to: OMIT)

    This is the result if the tool call was successful. This is added to the conversation history. Further, if this is returned, assistant will speak:

    1. the ‘message`, if it exists and is of type `request-complete`

    2. a ‘request-complete` message from `tool.messages`, if it exists

    3. a response generated by the model, if neither exist

  • error (String) (defaults to: OMIT)

    This is the error if the tool call was not successful. This is added to the conversation history. Further, if this is returned, assistant will speak:

    1. the ‘message`, if it exists and is of type `request-failed`

    2. a ‘request-failed` message from `tool.messages`, if it exists

    3. a response generated by the model, if neither exist

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 62

def initialize(name:, tool_call_id:, message: OMIT, result: OMIT, error: OMIT, additional_properties: nil)
  @message = message if message != OMIT
  @name = name
  @tool_call_id = tool_call_id
  @result = result if result != OMIT
  @error = error if error != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "message": message,
    "name": name,
    "toolCallId": tool_call_id,
    "result": result,
    "error": error
  }.reject do |_k, v|
    v == OMIT
  end
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



34
35
36
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 34

def additional_properties
  @additional_properties
end

#errorString (readonly)

Returns This is the error if the tool call was not successful. This is added to the conversation history. Further, if this is returned, assistant will speak:

  1. the ‘message`, if it exists and is of type `request-failed`

  2. a ‘request-failed` message from `tool.messages`, if it exists

  3. a response generated by the model, if neither exist.

Returns:

  • (String)

    This is the error if the tool call was not successful. This is added to the conversation history. Further, if this is returned, assistant will speak:

    1. the ‘message`, if it exists and is of type `request-failed`

    2. a ‘request-failed` message from `tool.messages`, if it exists

    3. a response generated by the model, if neither exist



32
33
34
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 32

def error
  @error
end

#messageArray<Vapi::ToolCallResultMessageItem> (readonly)

Returns This is the message that will be spoken to the user. If this is not returned, assistant will speak:

  1. a ‘request-complete` or `request-failed` message from `tool.messages`, if it

exists

  1. a response generated by the model, if not.

Returns:

  • (Array<Vapi::ToolCallResultMessageItem>)

    This is the message that will be spoken to the user. If this is not returned, assistant will speak:

    1. a ‘request-complete` or `request-failed` message from `tool.messages`, if it

    exists

    1. a response generated by the model, if not



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

def message
  @message
end

#nameString (readonly)

Returns This is the name of the function the model called.

Returns:

  • (String)

    This is the name of the function the model called.



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

def name
  @name
end

#resultString (readonly)

Returns This is the result if the tool call was successful. This is added to the conversation history. Further, if this is returned, assistant will speak:

  1. the ‘message`, if it exists and is of type `request-complete`

  2. a ‘request-complete` message from `tool.messages`, if it exists

  3. a response generated by the model, if neither exist.

Returns:

  • (String)

    This is the result if the tool call was successful. This is added to the conversation history. Further, if this is returned, assistant will speak:

    1. the ‘message`, if it exists and is of type `request-complete`

    2. a ‘request-complete` message from `tool.messages`, if it exists

    3. a response generated by the model, if neither exist



25
26
27
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 25

def result
  @result
end

#tool_call_idString (readonly)

Returns This is the unique identifier for the tool call.

Returns:

  • (String)

    This is the unique identifier for the tool call.



18
19
20
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 18

def tool_call_id
  @tool_call_id
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::ToolCallResult

Deserialize a JSON object to an instance of ToolCallResult

Parameters:

  • json_object (String)

Returns:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 84

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  message = parsed_json["message"]&.map do |item|
    item = item.to_json
    Vapi::ToolCallResultMessageItem.from_json(json_object: item)
  end
  name = parsed_json["name"]
  tool_call_id = parsed_json["toolCallId"]
  result = parsed_json["result"]
  error = parsed_json["error"]
  new(
    message: message,
    name: name,
    tool_call_id: tool_call_id,
    result: result,
    error: error,
    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)


118
119
120
121
122
123
124
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 118

def self.validate_raw(obj:)
  obj.message&.is_a?(Array) != false || raise("Passed value for field obj.message is not the expected type, validation failed.")
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.tool_call_id.is_a?(String) != false || raise("Passed value for field obj.tool_call_id is not the expected type, validation failed.")
  obj.result&.is_a?(String) != false || raise("Passed value for field obj.result is not the expected type, validation failed.")
  obj.error&.is_a?(String) != false || raise("Passed value for field obj.error is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of ToolCallResult to a JSON object

Returns:

  • (String)


108
109
110
# File 'lib/vapi_server_sdk/types/tool_call_result.rb', line 108

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