class Vellum::ChatMessage

def self.from_json(json_object:)

Returns:
  • (ChatMessage) -

Parameters:
  • json_object (JSON) --
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 = ChatMessageContent.from_json(json_object: content)
  end
  source = struct.source
  new(text: text, role: role, content: content, source: source, additional_properties: struct)
end

def self.validate_raw(obj:)

Returns:
  • (Void) -

Parameters:
  • obj (Object) --
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? || ChatMessageContent.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

def initialize(role:, text: nil, content: nil, source: nil, additional_properties: nil)

Returns:
  • (ChatMessage) -

Parameters:
  • additional_properties (OpenStruct) -- Additional properties unmapped to the current class definition
  • source (String) -- An optional identifier representing who or what generated this message.
  • content (ChatMessageContent) --
  • role (CHAT_MESSAGE_ROLE) --
  • text (String) --
def initialize(role:, text: nil, content: nil, source: nil, additional_properties: nil)
  # @type [String]
  @text = text
  # @type [CHAT_MESSAGE_ROLE]
  @role = role
  # @type [ChatMessageContent]
  @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

def to_json(*_args)

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