Class: Vellum::ChatMessageRequest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, text: nil, content: nil, source: nil, additional_properties: nil) ⇒ ChatMessageRequest

Parameters:

  • text (String) (defaults to: nil)
  • role (CHAT_MESSAGE_ROLE)
  • content (ChatMessageContentRequest) (defaults to: nil)
  • source (String) (defaults to: nil)

    An optional identifier representing who or what generated this message.

  • 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/chat_message_request.rb', line 17

def initialize(role:, text: nil, content: nil, source: nil, additional_properties: nil)
  # @type [String]
  @text = text
  # @type [CHAT_MESSAGE_ROLE]
  @role = role
  # @type [ChatMessageContentRequest]
  @content = content
  # @type [String] An optional identifier representing who or what generated this message.
  @source = source
  # @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/chat_message_request.rb', line 9

def additional_properties
  @additional_properties
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#roleObject (readonly)

Returns the value of attribute role.



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

def role
  @role
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ ChatMessageRequest

Deserialize a JSON object to an instance of ChatMessageRequest

Parameters:

  • json_object (JSON)

Returns:



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

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  text = struct.text
  role = CHAT_MESSAGE_ROLE.key(parsed_json["role"]) || parsed_json["role"]
  if parsed_json["content"].nil?
    content = nil
  else
    content = parsed_json["content"].to_json
    content = ChatMessageContentRequest.from_json(json_object: content)
  end
  source = struct.source
  new(text: text, role: role, content: content, source: source, 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)


60
61
62
63
64
65
# File 'lib/vellum_ai/types/chat_message_request.rb', line 60

def self.validate_raw(obj:)
  obj.text&.is_a?(String) != false || raise("Passed value for field obj.text is not the expected type, validation failed.")
  obj.role.is_a?(CHAT_MESSAGE_ROLE) != false || raise("Passed value for field obj.role is not the expected type, validation failed.")
  obj.content.nil? || ChatMessageContentRequest.validate_raw(obj: obj.content)
  obj.source&.is_a?(String) != false || raise("Passed value for field obj.source is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ChatMessageRequest to a JSON object

Returns:

  • (JSON)


52
53
54
# File 'lib/vellum_ai/types/chat_message_request.rb', line 52

def to_json(*_args)
  { "text": @text, "role": CHAT_MESSAGE_ROLE[@role] || @role, "content": @content, "source": @source }.to_json
end