Class: Vellum::EnrichedNormalizedCompletion

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, text:, model_version_id:, prompt_version_id:, deployment_release_tag:, model_name:, external_id: nil, finish_reason: nil, logprobs: nil, type: nil, additional_properties: nil) ⇒ EnrichedNormalizedCompletion

Parameters:

  • id (String)

    The Vellum-generated ID of the completion.

  • external_id (String) (defaults to: nil)

    The external ID that was originally provided along with the generation request, which uniquely identifies this generation in an external system.

  • text (String)

    The text generated by the LLM.

  • finish_reason (FINISH_REASON_ENUM) (defaults to: nil)

    The reason the generation finished.

    • ‘LENGTH` - LENGTH

    • ‘STOP` - STOP

    • ‘UNKNOWN` - UNKNOWN

  • logprobs (NormalizedLogProbs) (defaults to: nil)

    The logprobs of the completion. Only present if specified in the original request options.

  • model_version_id (String)

    The ID of the model version used to generate this completion.

  • prompt_version_id (String)
  • type (VELLUM_VARIABLE_TYPE) (defaults to: nil)
  • deployment_release_tag (String)
  • model_name (String)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 28

def initialize(id:, text:, model_version_id:, prompt_version_id:, deployment_release_tag:, model_name:,
               external_id: nil, finish_reason: nil, logprobs: nil, type: nil, additional_properties: nil)
  # @type [String] The Vellum-generated ID of the completion.
  @id = id
  # @type [String] The external ID that was originally provided along with the generation request, which uniquely identifies this generation in an external system.
  @external_id = external_id
  # @type [String] The text generated by the LLM.
  @text = text
  # @type [FINISH_REASON_ENUM] The reason the generation finished.
  #   - `LENGTH` - LENGTH
  #   - `STOP` - STOP
  #   - `UNKNOWN` - UNKNOWN
  @finish_reason = finish_reason
  # @type [NormalizedLogProbs] The logprobs of the completion. Only present if specified in the original request options.
  @logprobs = logprobs
  # @type [String] The ID of the model version used to generate this completion.
  @model_version_id = model_version_id
  # @type [String]
  @prompt_version_id = prompt_version_id
  # @type [VELLUM_VARIABLE_TYPE]
  @type = type
  # @type [String]
  @deployment_release_tag = deployment_release_tag
  # @type [String]
  @model_name = model_name
  # @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.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def additional_properties
  @additional_properties
end

#deployment_release_tagObject (readonly)

Returns the value of attribute deployment_release_tag.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def deployment_release_tag
  @deployment_release_tag
end

#external_idObject (readonly)

Returns the value of attribute external_id.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def external_id
  @external_id
end

#finish_reasonObject (readonly)

Returns the value of attribute finish_reason.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def finish_reason
  @finish_reason
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def id
  @id
end

#logprobsObject (readonly)

Returns the value of attribute logprobs.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def logprobs
  @logprobs
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def model_name
  @model_name
end

#model_version_idObject (readonly)

Returns the value of attribute model_version_id.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def model_version_id
  @model_version_id
end

#prompt_version_idObject (readonly)

Returns the value of attribute prompt_version_id.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def prompt_version_id
  @prompt_version_id
end

#textObject (readonly)

Returns the value of attribute text.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 10

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ EnrichedNormalizedCompletion

Deserialize a JSON object to an instance of EnrichedNormalizedCompletion

Parameters:

  • json_object (JSON)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 61

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  external_id = struct.external_id
  text = struct.text
  finish_reason = FINISH_REASON_ENUM.key(parsed_json["finish_reason"]) || parsed_json["finish_reason"]
  if parsed_json["logprobs"].nil?
    logprobs = nil
  else
    logprobs = parsed_json["logprobs"].to_json
    logprobs = NormalizedLogProbs.from_json(json_object: logprobs)
  end
  model_version_id = struct.model_version_id
  prompt_version_id = struct.prompt_version_id
  type = VELLUM_VARIABLE_TYPE.key(parsed_json["type"]) || parsed_json["type"]
  deployment_release_tag = struct.deployment_release_tag
  model_name = struct.model_name
  new(id: id, external_id: external_id, text: text, finish_reason: finish_reason, logprobs: logprobs,
      model_version_id: model_version_id, prompt_version_id: prompt_version_id, type: type, deployment_release_tag: deployment_release_tag, model_name: model_name, 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)


105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 105

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.external_id&.is_a?(String) != false || raise("Passed value for field obj.external_id is not the expected type, validation failed.")
  obj.text.is_a?(String) != false || raise("Passed value for field obj.text 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.")
  obj.logprobs.nil? || NormalizedLogProbs.validate_raw(obj: obj.logprobs)
  obj.model_version_id.is_a?(String) != false || raise("Passed value for field obj.model_version_id is not the expected type, validation failed.")
  obj.prompt_version_id.is_a?(String) != false || raise("Passed value for field obj.prompt_version_id is not the expected type, validation failed.")
  obj.type&.is_a?(VELLUM_VARIABLE_TYPE) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.deployment_release_tag.is_a?(String) != false || raise("Passed value for field obj.deployment_release_tag is not the expected type, validation failed.")
  obj.model_name.is_a?(String) != false || raise("Passed value for field obj.model_name is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of EnrichedNormalizedCompletion to a JSON object

Returns:

  • (JSON)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vellum_ai/types/enriched_normalized_completion.rb', line 86

def to_json(*_args)
  {
    "id": @id,
    "external_id": @external_id,
    "text": @text,
    "finish_reason": FINISH_REASON_ENUM[@finish_reason] || @finish_reason,
    "logprobs": @logprobs,
    "model_version_id": @model_version_id,
    "prompt_version_id": @prompt_version_id,
    "type": VELLUM_VARIABLE_TYPE[@type] || @type,
    "deployment_release_tag": @deployment_release_tag,
    "model_name": @model_name
  }.to_json
end