Class: Vellum::PromptTemplateBlock
- Inherits:
-
Object
- Object
- Vellum::PromptTemplateBlock
- Defined in:
- lib/vellum_ai/types/prompt_template_block.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#block_type ⇒ Object
readonly
Returns the value of attribute block_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ PromptTemplateBlock
Deserialize a JSON object to an instance of PromptTemplateBlock.
-
.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(id:, block_type:, properties:, additional_properties: nil) ⇒ PromptTemplateBlock constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of PromptTemplateBlock to a JSON object.
Constructor Details
#initialize(id:, block_type:, properties:, additional_properties: nil) ⇒ PromptTemplateBlock
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vellum_ai/types/prompt_template_block.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 [PromptTemplateBlockProperties] @properties = properties # @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/prompt_template_block.rb', line 9 def additional_properties @additional_properties end |
#block_type ⇒ Object (readonly)
Returns the value of attribute block_type.
9 10 11 |
# File 'lib/vellum_ai/types/prompt_template_block.rb', line 9 def block_type @block_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/vellum_ai/types/prompt_template_block.rb', line 9 def id @id end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
9 10 11 |
# File 'lib/vellum_ai/types/prompt_template_block.rb', line 9 def properties @properties end |
Class Method Details
.from_json(json_object:) ⇒ PromptTemplateBlock
Deserialize a JSON object to an instance of PromptTemplateBlock
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vellum_ai/types/prompt_template_block.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 = PromptTemplateBlockProperties.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.
56 57 58 59 60 |
# File 'lib/vellum_ai/types/prompt_template_block.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.") PromptTemplateBlockProperties.validate_raw(obj: obj.properties) end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of PromptTemplateBlock to a JSON object
48 49 50 |
# File 'lib/vellum_ai/types/prompt_template_block.rb', line 48 def to_json(*_args) { "id": @id, "block_type": BLOCK_TYPE_ENUM[@block_type] || @block_type, "properties": @properties }.to_json end |