Class: Vellum::FulfilledPromptExecutionMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb

Overview

The subset of the metadata tracked by Vellum during prompt execution that the request opted into with ‘expand_meta`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latency: nil, finish_reason: nil, additional_properties: nil) ⇒ FulfilledPromptExecutionMeta

Parameters:

  • latency (Integer) (defaults to: nil)
  • finish_reason (FINISH_REASON_ENUM) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



15
16
17
18
19
20
21
22
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 15

def initialize(latency: nil, finish_reason: nil, additional_properties: nil)
  # @type [Integer]
  @latency = latency
  # @type [FINISH_REASON_ENUM]
  @finish_reason = finish_reason
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



9
10
11
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 9

def additional_properties
  @additional_properties
end

#finish_reasonObject (readonly)

Returns the value of attribute finish_reason.



9
10
11
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 9

def finish_reason
  @finish_reason
end

#latencyObject (readonly)

Returns the value of attribute latency.



9
10
11
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 9

def latency
  @latency
end

Class Method Details

.from_json(json_object:) ⇒ FulfilledPromptExecutionMeta

Deserialize a JSON object to an instance of FulfilledPromptExecutionMeta

Parameters:

  • json_object (JSON)

Returns:



28
29
30
31
32
33
34
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 28

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  latency = struct.latency
  finish_reason = FINISH_REASON_ENUM.key(parsed_json["finish_reason"]) || parsed_json["finish_reason"]
  new(latency: latency, finish_reason: finish_reason, 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)


47
48
49
50
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 47

def self.validate_raw(obj:)
  obj.latency&.is_a?(Integer) != false || raise("Passed value for field obj.latency is not the expected type, validation failed.")
  obj.finish_reason&.is_a?(FINISH_REASON_ENUM) != false || raise("Passed value for field obj.finish_reason is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of FulfilledPromptExecutionMeta to a JSON object

Returns:

  • (JSON)


39
40
41
# File 'lib/vellum_ai/types/fulfilled_prompt_execution_meta.rb', line 39

def to_json(*_args)
  { "latency": @latency, "finish_reason": FINISH_REASON_ENUM[@finish_reason] || @finish_reason }.to_json
end