Class: Vellum::GenerateResult
- Inherits:
-
Object
- Object
- Vellum::GenerateResult
- Defined in:
- lib/vellum_ai/types/generate_result.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ GenerateResult
Deserialize a JSON object to an instance of GenerateResult.
-
.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(data: nil, error: nil, additional_properties: nil) ⇒ GenerateResult constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of GenerateResult to a JSON object.
Constructor Details
#initialize(data: nil, error: nil, additional_properties: nil) ⇒ GenerateResult
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_properties ⇒ Object (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 |
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/vellum_ai/types/generate_result.rb', line 9 def data @data end |
#error ⇒ Object (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
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.
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
49 50 51 |
# File 'lib/vellum_ai/types/generate_result.rb', line 49 def to_json(*_args) { "data": @data, "error": @error }.to_json end |