Class: Vapi::CreateApiRequestToolDto
- Inherits:
-
Object
- Object
- Vapi::CreateApiRequestToolDto
- Defined in:
- lib/vapi_server_sdk/types/create_api_request_tool_dto.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#backoff_plan ⇒ Vapi::BackoffPlan
readonly
This is the backoff plan if the request fails.
-
#body ⇒ Vapi::JsonSchema
readonly
This is the body of the request.
-
#description ⇒ String
readonly
This is the description of the tool.
-
#function ⇒ Vapi::OpenAiFunction
readonly
This is the function definition of the tool.
-
#headers ⇒ Vapi::JsonSchema
readonly
These are the headers to send in the request.
-
#messages ⇒ Array<Vapi::CreateApiRequestToolDtoMessagesItem>
readonly
These are the messages that will be spoken to the user as the tool is running.
- #method ⇒ Vapi::CreateApiRequestToolDtoMethod readonly
-
#name ⇒ String
readonly
This is the name of the tool.
-
#timeout_seconds ⇒ Float
readonly
This is the timeout in seconds for the request.
-
#url ⇒ String
readonly
This is where the request will be sent.
-
#variable_extraction_plan ⇒ Vapi::VariableExtractionPlan
readonly
This is the plan to extract variables from the tool’s response.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::CreateApiRequestToolDto
Deserialize a JSON object to an instance of CreateApiRequestToolDto.
-
.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.
Instance Method Summary collapse
- #initialize(method:, url:, messages: OMIT, timeout_seconds: OMIT, name: OMIT, description: OMIT, body: OMIT, headers: OMIT, backoff_plan: OMIT, variable_extraction_plan: OMIT, function: OMIT, additional_properties: nil) ⇒ Vapi::CreateApiRequestToolDto constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of CreateApiRequestToolDto to a JSON object.
Constructor Details
#initialize(method:, url:, messages: OMIT, timeout_seconds: OMIT, name: OMIT, description: OMIT, body: OMIT, headers: OMIT, backoff_plan: OMIT, variable_extraction_plan: OMIT, function: OMIT, additional_properties: nil) ⇒ Vapi::CreateApiRequestToolDto
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 431 def initialize(method:, url:, messages: OMIT, timeout_seconds: OMIT, name: OMIT, description: OMIT, body: OMIT, headers: OMIT, backoff_plan: OMIT, variable_extraction_plan: OMIT, function: OMIT, additional_properties: nil) @messages = if != OMIT @method = method @timeout_seconds = timeout_seconds if timeout_seconds != OMIT @name = name if name != OMIT @description = description if description != OMIT @url = url @body = body if body != OMIT @headers = headers if headers != OMIT @backoff_plan = backoff_plan if backoff_plan != OMIT @variable_extraction_plan = variable_extraction_plan if variable_extraction_plan != OMIT @function = function if function != OMIT @additional_properties = additional_properties @_field_set = { "messages": , "method": method, "timeoutSeconds": timeout_seconds, "name": name, "description": description, "url": url, "body": body, "headers": headers, "backoffPlan": backoff_plan, "variableExtractionPlan": variable_extraction_plan, "function": function }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
224 225 226 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 224 def additional_properties @additional_properties end |
#backoff_plan ⇒ Vapi::BackoffPlan (readonly)
Returns This is the backoff plan if the request fails. Defaults to undefined (the request will not be retried). @default undefined (the request will not be retried).
39 40 41 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 39 def backoff_plan @backoff_plan end |
#body ⇒ Vapi::JsonSchema (readonly)
Returns This is the body of the request.
33 34 35 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 33 def body @body end |
#description ⇒ String (readonly)
Returns This is the description of the tool. This will be passed to the model.
29 30 31 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 29 def description @description end |
#function ⇒ Vapi::OpenAiFunction (readonly)
Returns This is the function definition of the tool. For ‘endCall`, `transferCall`, and `dtmf` tools, this is auto-filled based on tool-specific fields like `tool.destinations`. But, even in those cases, you can provide a custom function definition for advanced use cases. An example of an advanced use case is if you want to customize the message that’s spoken for ‘endCall` tool. You can specify a function where it returns an argument “reason”. Then, in `messages` array, you can have many “request-complete” messages. One of these messages will be triggered if the `messages[].conditions` matches the “reason” argument.
222 223 224 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 222 def function @function end |
#headers ⇒ Vapi::JsonSchema (readonly)
Returns These are the headers to send in the request.
35 36 37 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 35 def headers @headers end |
#messages ⇒ Array<Vapi::CreateApiRequestToolDtoMessagesItem> (readonly)
Returns These are the messages that will be spoken to the user as the tool is running. For some tools, this is auto-filled based on special fields like ‘tool.destinations`. For others like the function tool, these can be custom configured.
18 19 20 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 18 def @messages end |
#method ⇒ Vapi::CreateApiRequestToolDtoMethod (readonly)
20 21 22 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 20 def method @method end |
#name ⇒ String (readonly)
Returns This is the name of the tool. This will be passed to the model. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 40.
27 28 29 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 27 def name @name end |
#timeout_seconds ⇒ Float (readonly)
Returns This is the timeout in seconds for the request. Defaults to 20 seconds. @default 20.
23 24 25 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 23 def timeout_seconds @timeout_seconds end |
#url ⇒ String (readonly)
Returns This is where the request will be sent.
31 32 33 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 31 def url @url end |
#variable_extraction_plan ⇒ Vapi::VariableExtractionPlan (readonly)
Returns This is the plan to extract variables from the tool’s response. These will be accessible during the call and stored in ‘call.artifact.variableValues` after the call. Usage:
-
Use ‘aliases` to extract variables from the tool’s response body. (Most
common case) “‘json { “aliases”: [ { “key”: “customerName”, “value”: “Vapi::CreateApiRequestToolDto.{customer{customer.name}” }, { “key”: “customerAge”, “value”: “Vapi::CreateApiRequestToolDto.{customer{customer.age}” } ] } “` The tool response body is made available to the liquid template.
-
Use ‘aliases` to extract variables from the tool’s response body if the
response is an array. “‘json { “aliases”: [ { “key”: “customerName”, “value”: “Vapi::CreateApiRequestToolDto.{$[0]{$[0].name}” }, { “key”: “customerAge”, “value”: “Vapi::CreateApiRequestToolDto.{$[0]{$[0].age}” } ] } “` $ is a shorthand for the tool’s response body. ‘$[0]` is the first item in the array. `$[n]` is the nth item in the array. Note, $ is available regardless of the response body type (both object and array).
-
Use ‘aliases` to extract variables from the tool’s response headers.
“‘json { “aliases”: [ { “key”: “customerName”, “value”: “Vapi::CreateApiRequestToolDto.{tool{tool.response{tool.response.headers{tool.response.headers.customer-name}” }, { “key”: “customerAge”, “value”: “Vapi::CreateApiRequestToolDto.{tool{tool.response{tool.response.headers{tool.response.headers.customer-age}” } ] } “` `tool.response` is made available to the liquid template. Particularly, both `tool.response.headers` and `tool.response.body` are available. Note, `tool.response` is available regardless of the response body type (both object and array).
-
Use ‘schema` to extract a large portion of the tool’s response body.
4.1. If you hit example.com and it returns ‘“John”, “age”: 30`, then you can specify the schema as: “`json { “schema”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” } } } } “` 4.2. If you hit example.com and it returns `{“first”: “John”, “last”: “Doe”}`, then you can specify the schema as: “`json { “schema”: { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } } “` These will be extracted as `name }` and `age }` respectively. To emphasize, object properties are extracted as direct global variables. 4.3. If you hit example.com and it returns `{“first”: “John”, “last”: “Doe”}`, then you can specify the schema as: “`json { “schema”: { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } } “` These will be extracted as `name }`. And, `name.first }` and `name.last }` will be accessible. 4.4. If you hit example.com and it returns `[“94123”, “94124”]`, then you can specify the schema as: “`json { “schema”: { “type”: “array”, “title”: “zipCodes”, “items”: { “type”: “string” } } } “` This will be extracted as `zipCodes }`. To access the array items, you can use `zipCodes }` and `zipCodes }`. 4.5. If you hit example.com and it returns `[“John”, “age”: 30, “zipCodes”: [“94123”, “94124”], “Jane”, “age”: 25, “zipCodes”: [“94125”, “94126”]]`, then you can specify the schema as: “`json { “schema”: { “type”: “array”, “title”: “people”, “items”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” }, “zipCodes”: { “type”: “array”, “items”: { “type”: “string” } } } } } } “` This will be extracted as `people }`. To access the array items, you can use `people.name }`, `people.age }`, `people.zipCodes }`, `people.zipCodes }` and `people.zipCodes }`. Note: Both `aliases` and `schema` can be used together.
212 213 214 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 212 def variable_extraction_plan @variable_extraction_plan end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::CreateApiRequestToolDto
Deserialize a JSON object to an instance of CreateApiRequestToolDto
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 466 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) = parsed_json["messages"]&.map do |item| item = item.to_json Vapi::CreateApiRequestToolDtoMessagesItem.from_json(json_object: item) end method = parsed_json["method"] timeout_seconds = parsed_json["timeoutSeconds"] name = parsed_json["name"] description = parsed_json["description"] url = parsed_json["url"] if parsed_json["body"].nil? body = nil else body = parsed_json["body"].to_json body = Vapi::JsonSchema.from_json(json_object: body) end if parsed_json["headers"].nil? headers = nil else headers = parsed_json["headers"].to_json headers = Vapi::JsonSchema.from_json(json_object: headers) end if parsed_json["backoffPlan"].nil? backoff_plan = nil else backoff_plan = parsed_json["backoffPlan"].to_json backoff_plan = Vapi::BackoffPlan.from_json(json_object: backoff_plan) end if parsed_json["variableExtractionPlan"].nil? variable_extraction_plan = nil else variable_extraction_plan = parsed_json["variableExtractionPlan"].to_json variable_extraction_plan = Vapi::VariableExtractionPlan.from_json(json_object: variable_extraction_plan) end if parsed_json["function"].nil? function = nil else function = parsed_json["function"].to_json function = Vapi::OpenAiFunction.from_json(json_object: function) end new( messages: , method: method, timeout_seconds: timeout_seconds, name: name, description: description, url: url, body: body, headers: headers, backoff_plan: backoff_plan, variable_extraction_plan: variable_extraction_plan, 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.
537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 537 def self.validate_raw(obj:) obj.&.is_a?(Array) != false || raise("Passed value for field obj.messages is not the expected type, validation failed.") obj.method.is_a?(Vapi::CreateApiRequestToolDtoMethod) != false || raise("Passed value for field obj.method is not the expected type, validation failed.") obj.timeout_seconds&.is_a?(Float) != false || raise("Passed value for field obj.timeout_seconds 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.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.") obj.url.is_a?(String) != false || raise("Passed value for field obj.url is not the expected type, validation failed.") obj.body.nil? || Vapi::JsonSchema.validate_raw(obj: obj.body) obj.headers.nil? || Vapi::JsonSchema.validate_raw(obj: obj.headers) obj.backoff_plan.nil? || Vapi::BackoffPlan.validate_raw(obj: obj.backoff_plan) obj.variable_extraction_plan.nil? || Vapi::VariableExtractionPlan.validate_raw(obj: obj.variable_extraction_plan) obj.function.nil? || Vapi::OpenAiFunction.validate_raw(obj: obj.function) end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of CreateApiRequestToolDto to a JSON object
527 528 529 |
# File 'lib/vapi_server_sdk/types/create_api_request_tool_dto.rb', line 527 def to_json(*_args) @_field_set&.to_json end |