Class: Vellum::GenerateRequest
- Inherits:
-
Object
- Object
- Vellum::GenerateRequest
- Defined in:
- lib/vellum_ai/types/generate_request.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#chat_history ⇒ Object
readonly
Returns the value of attribute chat_history.
-
#external_ids ⇒ Object
readonly
Returns the value of attribute external_ids.
-
#input_values ⇒ Object
readonly
Returns the value of attribute input_values.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ GenerateRequest
Deserialize a JSON object to an instance of GenerateRequest.
-
.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(input_values:, chat_history: nil, external_ids: nil, additional_properties: nil) ⇒ GenerateRequest constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of GenerateRequest to a JSON object.
Constructor Details
#initialize(input_values:, chat_history: nil, external_ids: nil, additional_properties: nil) ⇒ GenerateRequest
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vellum_ai/types/generate_request.rb', line 15 def initialize(input_values:, chat_history: nil, external_ids: nil, additional_properties: nil) # @type [Hash{String => String}] Key/value pairs for each template variable defined in the deployment's prompt. @input_values = input_values # @type [Array<ChatMessageRequest>] Optionally provide a list of chat messages that'll be used in place of the special chat_history variable, if included in the prompt. @chat_history = chat_history # @type [Array<String>] Optionally include a unique identifier for each generation, as represented outside of Vellum. Note that this should generally be a list of length one. @external_ids = external_ids # @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.
8 9 10 |
# File 'lib/vellum_ai/types/generate_request.rb', line 8 def additional_properties @additional_properties end |
#chat_history ⇒ Object (readonly)
Returns the value of attribute chat_history.
8 9 10 |
# File 'lib/vellum_ai/types/generate_request.rb', line 8 def chat_history @chat_history end |
#external_ids ⇒ Object (readonly)
Returns the value of attribute external_ids.
8 9 10 |
# File 'lib/vellum_ai/types/generate_request.rb', line 8 def external_ids @external_ids end |
#input_values ⇒ Object (readonly)
Returns the value of attribute input_values.
8 9 10 |
# File 'lib/vellum_ai/types/generate_request.rb', line 8 def input_values @input_values end |
Class Method Details
.from_json(json_object:) ⇒ GenerateRequest
Deserialize a JSON object to an instance of GenerateRequest
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vellum_ai/types/generate_request.rb', line 30 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) input_values = struct.input_values chat_history = parsed_json["chat_history"].map do |v| v = v.to_json ChatMessageRequest.from_json(json_object: v) end external_ids = struct.external_ids new(input_values: input_values, chat_history: chat_history, external_ids: external_ids, 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.
54 55 56 57 58 |
# File 'lib/vellum_ai/types/generate_request.rb', line 54 def self.validate_raw(obj:) obj.input_values.is_a?(Hash) != false || raise("Passed value for field obj.input_values is not the expected type, validation failed.") obj.chat_history&.is_a?(Array) != false || raise("Passed value for field obj.chat_history is not the expected type, validation failed.") obj.external_ids&.is_a?(Array) != false || raise("Passed value for field obj.external_ids is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of GenerateRequest to a JSON object
46 47 48 |
# File 'lib/vellum_ai/types/generate_request.rb', line 46 def to_json(*_args) { "input_values": @input_values, "chat_history": @chat_history, "external_ids": @external_ids }.to_json end |