Class: Vellum::NormalizedTokenLogProbs

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, text_offset:, logprob: nil, top_logprobs: nil, additional_properties: nil) ⇒ NormalizedTokenLogProbs

Parameters:

  • token (String)
  • logprob (Float) (defaults to: nil)
  • top_logprobs (Hash{String => String}) (defaults to: nil)
  • text_offset (Integer)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 15

def initialize(token:, text_offset:, logprob: nil, top_logprobs: nil, additional_properties: nil)
  # @type [String]
  @token = token
  # @type [Float]
  @logprob = logprob
  # @type [Hash{String => String}]
  @top_logprobs = top_logprobs
  # @type [Integer]
  @text_offset = text_offset
  # @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.



7
8
9
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 7

def additional_properties
  @additional_properties
end

#logprobObject (readonly)

Returns the value of attribute logprob.



7
8
9
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 7

def logprob
  @logprob
end

#text_offsetObject (readonly)

Returns the value of attribute text_offset.



7
8
9
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 7

def text_offset
  @text_offset
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 7

def token
  @token
end

#top_logprobsObject (readonly)

Returns the value of attribute top_logprobs.



7
8
9
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 7

def top_logprobs
  @top_logprobs
end

Class Method Details

.from_json(json_object:) ⇒ NormalizedTokenLogProbs

Deserialize a JSON object to an instance of NormalizedTokenLogProbs

Parameters:

  • json_object (JSON)

Returns:



32
33
34
35
36
37
38
39
40
41
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 32

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  token = struct.token
  logprob = struct.logprob
  top_logprobs = struct.top_logprobs
  text_offset = struct.text_offset
  new(token: token, logprob: logprob, top_logprobs: top_logprobs, text_offset: text_offset,
      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)


54
55
56
57
58
59
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 54

def self.validate_raw(obj:)
  obj.token.is_a?(String) != false || raise("Passed value for field obj.token is not the expected type, validation failed.")
  obj.logprob&.is_a?(Float) != false || raise("Passed value for field obj.logprob is not the expected type, validation failed.")
  obj.top_logprobs&.is_a?(Hash) != false || raise("Passed value for field obj.top_logprobs is not the expected type, validation failed.")
  obj.text_offset.is_a?(Integer) != false || raise("Passed value for field obj.text_offset is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of NormalizedTokenLogProbs to a JSON object

Returns:

  • (JSON)


46
47
48
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 46

def to_json(*_args)
  { "token": @token, "logprob": @logprob, "top_logprobs": @top_logprobs, "text_offset": @text_offset }.to_json
end