Class: Vellum::GenerateResult

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: nil, error: nil, additional_properties: nil) ⇒ GenerateResult

Parameters:

  • data (GenerateResultData) (defaults to: nil)

    An object containing the resulting generation. This key will be absent if the LLM provider experienced an error.

  • error (GenerateResultError) (defaults to: nil)

    An object containing details about the error that occurred. This key will be absent if the LLM provider did not experience an error.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

def initialize(data: nil, error: nil, additional_properties: nil)
  # @type [GenerateResultData] An object containing the resulting generation. This key will be absent if the LLM provider experienced an error.
  @data = data
  # @type [GenerateResultError] An object containing details about the error that occurred. This key will be absent if the LLM provider did not experience an error.
  @error = error
  # @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.



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

def additional_properties
  @additional_properties
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

Class Method Details

.from_json(json_object:) ⇒ GenerateResult

Deserialize a JSON object to an instance of GenerateResult

Parameters:

  • json_object (JSON)

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vellum_ai/types/generate_result.rb', line 28

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


57
58
59
60
# File 'lib/vellum_ai/types/generate_result.rb', line 57

def self.validate_raw(obj:)
  obj.data.nil? || GenerateResultData.validate_raw(obj: obj.data)
  obj.error.nil? || GenerateResultError.validate_raw(obj: obj.error)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of GenerateResult to a JSON object

Returns:

  • (JSON)


49
50
51
# File 'lib/vellum_ai/types/generate_result.rb', line 49

def to_json(*_args)
  { "data": @data, "error": @error }.to_json
end