Class: Vellum::ChatMessagePromptBlock

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

Overview

A block that represents a chat message in a prompt template.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_type:, state: OMIT, cache_config: OMIT, chat_role:, chat_source: OMIT, chat_message_unterminated: OMIT, blocks:, additional_properties: nil) ⇒ Vellum::ChatMessagePromptBlock

Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 43

def initialize(block_type:, state: OMIT, cache_config: OMIT, chat_role:, chat_source: OMIT, chat_message_unterminated: OMIT, blocks:, additional_properties: nil)
  @block_type = block_type
  @state = state if state != OMIT
  @cache_config = cache_config if cache_config != OMIT
  @chat_role = chat_role
  @chat_source = chat_source if chat_source != OMIT
  @chat_message_unterminated = chat_message_unterminated if chat_message_unterminated != OMIT
  @blocks = blocks
  @additional_properties = additional_properties
  @_field_set = { "block_type": block_type, "state": state, "cache_config": cache_config, "chat_role": chat_role, "chat_source": chat_source, "chat_message_unterminated": chat_message_unterminated, "blocks": blocks }.reject do | _k, v |
  v == OMIT
end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



27
28
29
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 27

def additional_properties
  @additional_properties
end

#block_typeString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 13

def block_type
  @block_type
end

#blocksArray<Vellum::PromptBlock> (readonly)

Returns:



25
26
27
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 25

def blocks
  @blocks
end

#cache_configVellum::EphemeralPromptCacheConfig (readonly)



17
18
19
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 17

def cache_config
  @cache_config
end

#chat_message_unterminatedBoolean (readonly)

Returns:

  • (Boolean)


23
24
25
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 23

def chat_message_unterminated
  @chat_message_unterminated
end

#chat_roleVellum::ChatMessageRole (readonly)



19
20
21
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 19

def chat_role
  @chat_role
end

#chat_sourceString (readonly)

Returns:

  • (String)


21
22
23
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 21

def chat_source
  @chat_source
end

#stateVellum::PromptBlockState (readonly)



15
16
17
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 15

def state
  @state
end

Class Method Details

.from_json(json_object:) ⇒ Vellum::ChatMessagePromptBlock

Parameters:

  • json_object (String)

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 60

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  block_type = parsed_json["block_type"]
  state = parsed_json["state"]
  unless parsed_json["cache_config"].nil?
    cache_config = parsed_json["cache_config"].to_json
    cache_config = Vellum::EphemeralPromptCacheConfig.from_json(json_object: cache_config)
  else
    cache_config = nil
  end
  chat_role = parsed_json["chat_role"]
  chat_source = parsed_json["chat_source"]
  chat_message_unterminated = parsed_json["chat_message_unterminated"]
  blocks = parsed_json["blocks"]&.map do | item |
  item = item.to_json
  Vellum::PromptBlock.from_json(json_object: item)
end
  new(
    block_type: block_type,
    state: state,
    cache_config: cache_config,
    chat_role: chat_role,
    chat_source: chat_source,
    chat_message_unterminated: chat_message_unterminated,
    blocks: blocks,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


101
102
103
104
105
106
107
108
109
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 101

def self.validate_raw(obj:)
  obj.block_type.is_a?(String) != false || raise("Passed value for field obj.block_type is not the expected type, validation failed.")
  obj.state&.is_a?(Vellum::PromptBlockState) != false || raise("Passed value for field obj.state is not the expected type, validation failed.")
  obj.cache_config.nil? || Vellum::EphemeralPromptCacheConfig.validate_raw(obj: obj.cache_config)
  obj.chat_role.is_a?(Vellum::ChatMessageRole) != false || raise("Passed value for field obj.chat_role is not the expected type, validation failed.")
  obj.chat_source&.is_a?(String) != false || raise("Passed value for field obj.chat_source is not the expected type, validation failed.")
  obj.chat_message_unterminated&.is_a?(Boolean) != false || raise("Passed value for field obj.chat_message_unterminated is not the expected type, validation failed.")
  obj.blocks.is_a?(Array) != false || raise("Passed value for field obj.blocks is not the expected type, validation failed.")
end

Instance Method Details

#to_jsonString

Returns:

  • (String)


92
93
94
# File 'lib/vellum_ai/types/chat_message_prompt_block.rb', line 92

def to_json
  @_field_set&.to_json
end