Class: Vapi::OpenAiFunction
- Inherits:
-
Object
- Object
- Vapi::OpenAiFunction
- Defined in:
- lib/vapi_server_sdk/types/open_ai_function.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
- #description ⇒ String readonly
-
#name ⇒ String
readonly
This is the the name of the function to be called.
-
#parameters ⇒ Vapi::OpenAiFunctionParameters
readonly
These are the parameters the functions accepts, described as a JSON Schema object.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::OpenAiFunction
Deserialize a JSON object to an instance of OpenAiFunction.
-
.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(name:, description: OMIT, parameters: OMIT, additional_properties: nil) ⇒ Vapi::OpenAiFunction constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of OpenAiFunction to a JSON object.
Constructor Details
#initialize(name:, description: OMIT, parameters: OMIT, additional_properties: nil) ⇒ Vapi::OpenAiFunction
44 45 46 47 48 49 50 51 52 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 44 def initialize(name:, description: OMIT, parameters: OMIT, additional_properties: nil) @name = name @description = description if description != OMIT @parameters = parameters if parameters != OMIT @additional_properties = additional_properties @_field_set = { "name": name, "description": description, "parameters": parameters }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
24 25 26 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 24 def additional_properties @additional_properties end |
#description ⇒ String (readonly)
14 15 16 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 14 def description @description end |
#name ⇒ String (readonly)
Returns This is the the name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
12 13 14 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 12 def name @name end |
#parameters ⇒ Vapi::OpenAiFunctionParameters (readonly)
Returns These are the parameters the functions accepts, described as a JSON Schema object. See the [OpenAI guide](platform.openai.com/docs/guides/function-calling) for examples, and the [JSON Schema reference](json-schema.org/understanding-json-schema) for documentation about the format. Omitting parameters defines a function with an empty parameter list.
22 23 24 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 22 def parameters @parameters end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::OpenAiFunction
Deserialize a JSON object to an instance of OpenAiFunction
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 58 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) name = parsed_json["name"] description = parsed_json["description"] if parsed_json["parameters"].nil? parameters = nil else parameters = parsed_json["parameters"].to_json parameters = Vapi::OpenAiFunctionParameters.from_json(json_object: parameters) end new( name: name, description: description, parameters: parameters, 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.
90 91 92 93 94 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 90 def self.validate_raw(obj:) 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.parameters.nil? || Vapi::OpenAiFunctionParameters.validate_raw(obj: obj.parameters) end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of OpenAiFunction to a JSON object
80 81 82 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 80 def to_json(*_args) @_field_set&.to_json end |