Class: Vellum::PromptTemplateBlockRequest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, block_type:, properties:, additional_properties: nil) ⇒ PromptTemplateBlockRequest

Parameters:



16
17
18
19
20
21
22
23
24
25
# File 'lib/vellum_ai/types/prompt_template_block_request.rb', line 16

def initialize(id:, block_type:, properties:, additional_properties: nil)
  # @type [String]
  @id = id
  # @type [BLOCK_TYPE_ENUM]
  @block_type = block_type
  # @type [PromptTemplateBlockPropertiesRequest]
  @properties = properties
  # @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/prompt_template_block_request.rb', line 9

def additional_properties
  @additional_properties
end

#block_typeObject (readonly)

Returns the value of attribute block_type.



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

def block_type
  @block_type
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

Class Method Details

.from_json(json_object:) ⇒ PromptTemplateBlockRequest

Deserialize a JSON object to an instance of PromptTemplateBlockRequest

Parameters:

  • json_object (JSON)

Returns:



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

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  block_type = BLOCK_TYPE_ENUM.key(parsed_json["block_type"]) || parsed_json["block_type"]
  if parsed_json["properties"].nil?
    properties = nil
  else
    properties = parsed_json["properties"].to_json
    properties = PromptTemplateBlockPropertiesRequest.from_json(json_object: properties)
  end
  new(id: id, block_type: block_type, properties: properties, 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)


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

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.block_type.is_a?(BLOCK_TYPE_ENUM) != false || raise("Passed value for field obj.block_type is not the expected type, validation failed.")
  PromptTemplateBlockPropertiesRequest.validate_raw(obj: obj.properties)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of PromptTemplateBlockRequest to a JSON object

Returns:

  • (JSON)


48
49
50
# File 'lib/vellum_ai/types/prompt_template_block_request.rb', line 48

def to_json(*_args)
  { "id": @id, "block_type": BLOCK_TYPE_ENUM[@block_type] || @block_type, "properties": @properties }.to_json
end