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:, description: OMIT, parameters: OMIT, additional_properties: nil) ⇒ Vapi::OpenAiFunction

Parameters:

  • 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)
  • 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



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

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    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

#descriptionString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 14

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.



12
13
14
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 12

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:



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

Parameters:

  • json_object (String)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (String)


80
81
82
# File 'lib/vapi_server_sdk/types/open_ai_function.rb', line 80

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