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
This is the description of what the function does, used by the AI to choose when and how to call the function.
-
#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.
-
#strict ⇒ Boolean
readonly
This is a boolean that controls whether to enable strict schema adherence when generating the function call.
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:, strict: OMIT, 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:, strict: OMIT, description: OMIT, parameters: OMIT, additional_properties: nil) ⇒ Vapi::OpenAiFunction
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 61 def initialize(name:, strict: OMIT, description: OMIT, parameters: OMIT, additional_properties: nil) @strict = strict if strict != OMIT @name = name @description = description if description != OMIT @parameters = parameters if parameters != OMIT @additional_properties = additional_properties @_field_set = { "strict": strict, "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.
33 34 35 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 33 def additional_properties @additional_properties end |
#description ⇒ String (readonly)
Returns This is the description of what the function does, used by the AI to choose when and how to call the function.
23 24 25 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 23 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.
20 21 22 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 20 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.
31 32 33 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 31 def parameters @parameters end |
#strict ⇒ Boolean (readonly)
Returns This is a boolean that controls whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters field. Only a subset of JSON Schema is supported when strict is true. Learn more about Structured Outputs in the [OpenAI guide](openai.com/index/introducing-structured-outputs-in-the-api/). @default false.
16 17 18 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 16 def strict @strict end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::OpenAiFunction
Deserialize a JSON object to an instance of OpenAiFunction
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 81 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) strict = parsed_json["strict"] 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( strict: strict, 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.
115 116 117 118 119 120 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 115 def self.validate_raw(obj:) obj.strict&.is_a?(Boolean) != false || raise("Passed value for field obj.strict 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.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
105 106 107 |
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 105 def to_json(*_args) @_field_set&.to_json end |