Class: Vellum::GenerateRequest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_values:, chat_history: nil, external_ids: nil, additional_properties: nil) ⇒ GenerateRequest

Parameters:

  • input_values (Hash{String => String})

    Key/value pairs for each template variable defined in the deployment’s prompt.

  • chat_history (Array<ChatMessageRequest>) (defaults to: nil)

    Optionally provide a list of chat messages that’ll be used in place of the special chat_history variable, if included in the prompt.

  • external_ids (Array<String>) (defaults to: nil)

    Optionally include a unique identifier for each generation, as represented outside of Vellum. Note that this should generally be a list of length one.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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_propertiesObject (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_historyObject (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_idsObject (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_valuesObject (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

Parameters:

  • json_object (JSON)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (JSON)


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