Class: Vellum::ChatMessageRequest

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Parameters:

  • text (String) (defaults to: OMIT)
  • role (Vellum::ChatMessageRole)
  • content (Vellum::ChatMessageContentRequest) (defaults to: OMIT)
  • source (String) (defaults to: OMIT)

    An optional identifier representing who or what generated this message.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

def initialize(text: OMIT, role:, content: OMIT, source: OMIT, additional_properties: nil)
  @text = text if text != OMIT
  @role = role
  @content = content if content != OMIT
  @source = source if source != OMIT
  @additional_properties = additional_properties
  @_field_set = { "text": text, "role": role, "content": content, "source": source }.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



18
19
20
# File 'lib/vellum_ai/types/chat_message_request.rb', line 18

def additional_properties
  @additional_properties
end

#contentVellum::ChatMessageContentRequest (readonly)



14
15
16
# File 'lib/vellum_ai/types/chat_message_request.rb', line 14

def content
  @content
end

#roleVellum::ChatMessageRole (readonly)



12
13
14
# File 'lib/vellum_ai/types/chat_message_request.rb', line 12

def role
  @role
end

#sourceString (readonly)

Returns An optional identifier representing who or what generated this message.

Returns:

  • (String)

    An optional identifier representing who or what generated this message.



16
17
18
# File 'lib/vellum_ai/types/chat_message_request.rb', line 16

def source
  @source
end

#textString (readonly)

Returns:

  • (String)


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

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ Vellum::ChatMessageRequest

Parameters:

  • json_object (String)

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vellum_ai/types/chat_message_request.rb', line 45

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  text = parsed_json["text"]
  role = parsed_json["role"]
  unless parsed_json["content"].nil?
    content = parsed_json["content"].to_json
    content = Vellum::ChatMessageContentRequest.from_json(json_object: content)
  else
    content = nil
  end
  source = parsed_json["source"]
  new(
    text: text,
    role: role,
    content: content,
    source: source,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


77
78
79
80
81
82
# File 'lib/vellum_ai/types/chat_message_request.rb', line 77

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?(Vellum::ChatMessageRole) != false || raise("Passed value for field obj.role is not the expected type, validation failed.")
  obj.content.nil? || Vellum::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_jsonString

Returns:

  • (String)


68
69
70
# File 'lib/vellum_ai/types/chat_message_request.rb', line 68

def to_json
  @_field_set&.to_json
end