Class: Vellum::GenerateStreamResultData

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(completion_index:, completion:, additional_properties: nil) ⇒ GenerateStreamResultData

Parameters:

  • completion_index (Integer)
  • completion (EnrichedNormalizedCompletion)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



14
15
16
17
18
19
20
21
# File 'lib/vellum_ai/types/generate_stream_result_data.rb', line 14

def initialize(completion_index:, completion:, additional_properties: nil)
  # @type [Integer]
  @completion_index = completion_index
  # @type [EnrichedNormalizedCompletion]
  @completion = completion
  # @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.



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

def additional_properties
  @additional_properties
end

#completionObject (readonly)

Returns the value of attribute completion.



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

def completion
  @completion
end

#completion_indexObject (readonly)

Returns the value of attribute completion_index.



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

def completion_index
  @completion_index
end

Class Method Details

.from_json(json_object:) ⇒ GenerateStreamResultData

Deserialize a JSON object to an instance of GenerateStreamResultData

Parameters:

  • json_object (JSON)

Returns:



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

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  completion_index = struct.completion_index
  if parsed_json["completion"].nil?
    completion = nil
  else
    completion = parsed_json["completion"].to_json
    completion = EnrichedNormalizedCompletion.from_json(json_object: completion)
  end
  new(completion_index: completion_index, completion: completion, 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)


51
52
53
54
# File 'lib/vellum_ai/types/generate_stream_result_data.rb', line 51

def self.validate_raw(obj:)
  obj.completion_index.is_a?(Integer) != false || raise("Passed value for field obj.completion_index is not the expected type, validation failed.")
  EnrichedNormalizedCompletion.validate_raw(obj: obj.completion)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of GenerateStreamResultData to a JSON object

Returns:

  • (JSON)


43
44
45
# File 'lib/vellum_ai/types/generate_stream_result_data.rb', line 43

def to_json(*_args)
  { "completion_index": @completion_index, "completion": @completion }.to_json
end