Class: Vellum::ScenarioInput

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, type: nil, value: nil, chat_history: nil, additional_properties: nil) ⇒ ScenarioInput

Parameters:

  • key (String)
  • type (SCENARIO_INPUT_TYPE_ENUM) (defaults to: nil)
  • value (String) (defaults to: nil)
  • chat_history (Array<ChatMessage>) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vellum_ai/types/scenario_input.rb', line 17

def initialize(key:, type: nil, value: nil, chat_history: nil, additional_properties: nil)
  # @type [String]
  @key = key
  # @type [SCENARIO_INPUT_TYPE_ENUM]
  @type = type
  # @type [String]
  @value = value
  # @type [Array<ChatMessage>]
  @chat_history = chat_history
  # @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/scenario_input.rb', line 9

def additional_properties
  @additional_properties
end

#chat_historyObject (readonly)

Returns the value of attribute chat_history.



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

def chat_history
  @chat_history
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.from_json(json_object:) ⇒ ScenarioInput

Deserialize a JSON object to an instance of ScenarioInput

Parameters:

  • json_object (JSON)

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vellum_ai/types/scenario_input.rb', line 34

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  key = struct.key
  type = SCENARIO_INPUT_TYPE_ENUM.key(parsed_json["type"]) || parsed_json["type"]
  value = struct.value
  chat_history = parsed_json["chat_history"].map do |v|
    v = v.to_json
    ChatMessage.from_json(json_object: v)
  end
  new(key: key, type: type, value: value, chat_history: chat_history, 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)


63
64
65
66
67
68
# File 'lib/vellum_ai/types/scenario_input.rb', line 63

def self.validate_raw(obj:)
  obj.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
  obj.type&.is_a?(SCENARIO_INPUT_TYPE_ENUM) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.value&.is_a?(String) != false || raise("Passed value for field obj.value 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.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ScenarioInput to a JSON object

Returns:

  • (JSON)


50
51
52
53
54
55
56
57
# File 'lib/vellum_ai/types/scenario_input.rb', line 50

def to_json(*_args)
  {
    "key": @key,
    "type": SCENARIO_INPUT_TYPE_ENUM[@type] || @type,
    "value": @value,
    "chat_history": @chat_history
  }.to_json
end