Class: Vapi::OpenAiFunction

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, strict: OMIT, description: OMIT, parameters: OMIT, additional_properties: nil) ⇒ Vapi::OpenAiFunction

Parameters:

  • strict (Boolean) (defaults to: OMIT)

    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

  • name (String)

    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.

  • description (String) (defaults to: OMIT)

    This is the description of what the function does, used by the AI to choose when and how to call the function.

  • parameters (Vapi::OpenAiFunctionParameters) (defaults to: OMIT)

    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.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    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

#descriptionString (readonly)

Returns This is the description of what the function does, used by the AI to choose when and how to call the function.

Returns:

  • (String)

    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

#nameString (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.

Returns:

  • (String)

    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

#parametersVapi::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.

Returns:



31
32
33
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 31

def parameters
  @parameters
end

#strictBoolean (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.

Returns:

  • (Boolean)

    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

Parameters:

  • json_object (String)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (String)


105
106
107
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 105

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