Class: Vellum::NormalizedTokenLogProbs
- Inherits:
-
Object
- Object
- Vellum::NormalizedTokenLogProbs
- Defined in:
- lib/vellum_ai/types/normalized_token_log_probs.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#logprob ⇒ Object
readonly
Returns the value of attribute logprob.
-
#text_offset ⇒ Object
readonly
Returns the value of attribute text_offset.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#top_logprobs ⇒ Object
readonly
Returns the value of attribute top_logprobs.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ NormalizedTokenLogProbs
Deserialize a JSON object to an instance of NormalizedTokenLogProbs.
-
.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.
Instance Method Summary collapse
- #initialize(token:, text_offset:, logprob: nil, top_logprobs: nil, additional_properties: nil) ⇒ NormalizedTokenLogProbs constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of NormalizedTokenLogProbs to a JSON object.
Constructor Details
#initialize(token:, text_offset:, logprob: nil, top_logprobs: nil, additional_properties: nil) ⇒ NormalizedTokenLogProbs
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_properties ⇒ Object (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 |
#logprob ⇒ Object (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_offset ⇒ Object (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 |
#token ⇒ Object (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_logprobs ⇒ Object (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
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.
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
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 |