Class: Vapi::OpenAiFunctionParameters

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, properties:, required: OMIT, additional_properties: nil) ⇒ Vapi::OpenAiFunctionParameters

Parameters:

  • type (String)

    This must be set to ‘object’. It instructs the model to return a JSON object containing the function call properties.

  • properties (Hash{String => Vapi::JsonSchema})

    This provides a description of the properties required by the function. JSON Schema can be used to specify expectations for each property. Refer to [this doc](ajv.js.org/json-schema.html#json-data-type) for a comprehensive guide on JSON Schema.

  • required (Array<String>) (defaults to: OMIT)

    This specifies the properties that are required by the function.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



35
36
37
38
39
40
41
42
43
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 35

def initialize(type:, properties:, required: OMIT, additional_properties: nil)
  @type = type
  @properties = properties
  @required = required if required != OMIT
  @additional_properties = additional_properties
  @_field_set = { "type": type, "properties": properties, "required": required }.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



19
20
21
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 19

def additional_properties
  @additional_properties
end

#propertiesHash{String => Vapi::JsonSchema} (readonly)

Returns This provides a description of the properties required by the function. JSON Schema can be used to specify expectations for each property. Refer to [this doc](ajv.js.org/json-schema.html#json-data-type) for a comprehensive guide on JSON Schema.

Returns:



15
16
17
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 15

def properties
  @properties
end

#requiredArray<String> (readonly)

Returns This specifies the properties that are required by the function.

Returns:

  • (Array<String>)

    This specifies the properties that are required by the function.



17
18
19
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 17

def required
  @required
end

#typeString (readonly)

Returns This must be set to ‘object’. It instructs the model to return a JSON object containing the function call properties.

Returns:

  • (String)

    This must be set to ‘object’. It instructs the model to return a JSON object containing the function call properties.



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

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::OpenAiFunctionParameters

Deserialize a JSON object to an instance of OpenAiFunctionParameters

Parameters:

  • json_object (String)

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 49

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  type = parsed_json["type"]
  properties = parsed_json["properties"]&.transform_values do |value|
    value = value.to_json
    Vapi::JsonSchema.from_json(json_object: value)
  end
  required = parsed_json["required"]
  new(
    type: type,
    properties: properties,
    required: required,
    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)


79
80
81
82
83
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 79

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

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of OpenAiFunctionParameters to a JSON object

Returns:

  • (String)


69
70
71
# File 'lib/vapi_server_sdk/types/open_ai_function_parameters.rb', line 69

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