Class: Vellum::NormalizedTokenLogProbs

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Parameters:

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

    Additional properties unmapped to the current class definition



29
30
31
32
33
34
35
36
37
38
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 29

def initialize(token:, logprob: OMIT, top_logprobs: OMIT, text_offset:, additional_properties: nil)
  @token = token
  @logprob = logprob if logprob != OMIT
  @top_logprobs = top_logprobs if top_logprobs != OMIT
  @text_offset = text_offset
  @additional_properties = additional_properties
  @_field_set = { "token": token, "logprob": logprob, "top_logprobs": top_logprobs, "text_offset": text_offset }.reject do | _k, v |
  v == OMIT
end
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



16
17
18
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 16

def additional_properties
  @additional_properties
end

#logprobFloat (readonly)

Returns:

  • (Float)


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

def logprob
  @logprob
end

#text_offsetInteger (readonly)

Returns:

  • (Integer)


14
15
16
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 14

def text_offset
  @text_offset
end

#tokenString (readonly)

Returns:

  • (String)


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

def token
  @token
end

#top_logprobsHash{String => Float} (readonly)

Returns:

  • (Hash{String => Float})


12
13
14
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 12

def top_logprobs
  @top_logprobs
end

Class Method Details

.from_json(json_object:) ⇒ Vellum::NormalizedTokenLogProbs

Parameters:

  • json_object (String)

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 43

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  token = parsed_json["token"]
  logprob = parsed_json["logprob"]
  top_logprobs = parsed_json["top_logprobs"]
  text_offset = parsed_json["text_offset"]
  new(
    token: token,
    logprob: logprob,
    top_logprobs: top_logprobs,
    text_offset: text_offset,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


70
71
72
73
74
75
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 70

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_jsonString

Returns:

  • (String)


61
62
63
# File 'lib/vellum_ai/types/normalized_token_log_probs.rb', line 61

def to_json
  @_field_set&.to_json
end