Class: Vapi::ModelCost

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, prompt_tokens:, completion_tokens:, cost:, additional_properties: nil) ⇒ Vapi::ModelCost

Parameters:

  • model (Hash{String => Object})

    This is the model that was used during the call. This matches one of the following:

  • prompt_tokens (Float)

    This is the number of prompt tokens used in the call. These should be total prompt tokens used in the call for single assistant calls, while squad calls will have multiple model costs one for each assistant that was used.

  • completion_tokens (Float)

    This is the number of completion tokens generated in the call. These should be total completion tokens used in the call for single assistant calls, while squad calls will have multiple model costs one for each assistant that was used.

  • cost (Float)

    This is the cost of the component in USD.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

def initialize(model:, prompt_tokens:, completion_tokens:, cost:, additional_properties: nil)
  @model = model
  @prompt_tokens = prompt_tokens
  @completion_tokens = completion_tokens
  @cost = cost
  @additional_properties = additional_properties
  @_field_set = {
    "model": model,
    "promptTokens": prompt_tokens,
    "completionTokens": completion_tokens,
    "cost": cost
  }
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



28
29
30
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 28

def additional_properties
  @additional_properties
end

#completion_tokensFloat (readonly)

Returns This is the number of completion tokens generated in the call. These should be total completion tokens used in the call for single assistant calls, while squad calls will have multiple model costs one for each assistant that was used.

Returns:

  • (Float)

    This is the number of completion tokens generated in the call. These should be total completion tokens used in the call for single assistant calls, while squad calls will have multiple model costs one for each assistant that was used.



24
25
26
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 24

def completion_tokens
  @completion_tokens
end

#costFloat (readonly)

Returns This is the cost of the component in USD.

Returns:

  • (Float)

    This is the cost of the component in USD.



26
27
28
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 26

def cost
  @cost
end

#modelHash{String => Object} (readonly)

Returns This is the model that was used during the call. This matches one of the following:

Returns:

  • (Hash{String => Object})

    This is the model that was used during the call. This matches one of the following:



16
17
18
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 16

def model
  @model
end

#prompt_tokensFloat (readonly)

Returns This is the number of prompt tokens used in the call. These should be total prompt tokens used in the call for single assistant calls, while squad calls will have multiple model costs one for each assistant that was used.

Returns:

  • (Float)

    This is the number of prompt tokens used in the call. These should be total prompt tokens used in the call for single assistant calls, while squad calls will have multiple model costs one for each assistant that was used.



20
21
22
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 20

def prompt_tokens
  @prompt_tokens
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::ModelCost

Deserialize a JSON object to an instance of ModelCost

Parameters:

  • json_object (String)

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 70

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  model = parsed_json["model"]
  prompt_tokens = parsed_json["promptTokens"]
  completion_tokens = parsed_json["completionTokens"]
  cost = parsed_json["cost"]
  new(
    model: model,
    prompt_tokens: prompt_tokens,
    completion_tokens: completion_tokens,
    cost: cost,
    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)


99
100
101
102
103
104
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 99

def self.validate_raw(obj:)
  obj.model.is_a?(Hash) != false || raise("Passed value for field obj.model is not the expected type, validation failed.")
  obj.prompt_tokens.is_a?(Float) != false || raise("Passed value for field obj.prompt_tokens is not the expected type, validation failed.")
  obj.completion_tokens.is_a?(Float) != false || raise("Passed value for field obj.completion_tokens is not the expected type, validation failed.")
  obj.cost.is_a?(Float) != false || raise("Passed value for field obj.cost is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of ModelCost to a JSON object

Returns:

  • (String)


89
90
91
# File 'lib/vapi_server_sdk/types/model_cost.rb', line 89

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