Class: Vellum::NormalizedLogProbs

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens:, likelihood: OMIT, additional_properties: nil) ⇒ Vellum::NormalizedLogProbs

Parameters:

  • tokens (Array<Vellum::NormalizedTokenLogProbs>)
  • likelihood (Float) (defaults to: OMIT)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



24
25
26
27
28
29
30
31
# File 'lib/vellum_ai/types/normalized_log_probs.rb', line 24

def initialize(tokens:, likelihood: OMIT, additional_properties: nil)
  @tokens = tokens
  @likelihood = likelihood if likelihood != OMIT
  @additional_properties = additional_properties
  @_field_set = { "tokens": tokens, "likelihood": likelihood }.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



13
14
15
# File 'lib/vellum_ai/types/normalized_log_probs.rb', line 13

def additional_properties
  @additional_properties
end

#likelihoodFloat (readonly)

Returns:

  • (Float)


11
12
13
# File 'lib/vellum_ai/types/normalized_log_probs.rb', line 11

def likelihood
  @likelihood
end

#tokensArray<Vellum::NormalizedTokenLogProbs> (readonly)



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

def tokens
  @tokens
end

Class Method Details

.from_json(json_object:) ⇒ Vellum::NormalizedLogProbs

Parameters:

  • json_object (String)

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vellum_ai/types/normalized_log_probs.rb', line 36

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  tokens = parsed_json["tokens"]&.map do | item |
  item = item.to_json
  Vellum::NormalizedTokenLogProbs.from_json(json_object: item)
end
  likelihood = parsed_json["likelihood"]
  new(
    tokens: tokens,
    likelihood: likelihood,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


62
63
64
65
# File 'lib/vellum_ai/types/normalized_log_probs.rb', line 62

def self.validate_raw(obj:)
  obj.tokens.is_a?(Array) != false || raise("Passed value for field obj.tokens is not the expected type, validation failed.")
  obj.likelihood&.is_a?(Float) != false || raise("Passed value for field obj.likelihood is not the expected type, validation failed.")
end

Instance Method Details

#to_jsonString

Returns:

  • (String)


53
54
55
# File 'lib/vellum_ai/types/normalized_log_probs.rb', line 53

def to_json
  @_field_set&.to_json
end