Class: Vellum::ChatMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/chat_message.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, metadata: OMIT, additional_properties: nil) ⇒ Vellum::ChatMessage

Parameters:

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

    An optional identifier representing who or what generated this message.

  • metadata (Hash{String => Object}) (defaults to: OMIT)
  • additional_properties (OpenStruct) (defaults to: nil) —

    Additional properties unmapped to the current class definition



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

def initialize(text: OMIT, role:, content: OMIT, source: OMIT, metadata: OMIT, additional_properties: nil)
  @text = text if text != OMIT
  @role = role
  @content = content if content != OMIT
  @source = source if source != OMIT
  @metadata =  if  != OMIT
  @additional_properties = additional_properties
  @_field_set = { "text": text, "role": role, "content": content, "source": source, "metadata":  }.reject do | _k, v |
  v == OMIT
end
end

Instance Attribute Details

#additional_properties ⇒ OpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct) —

    Additional properties unmapped to the current class definition



20
21
22
# File 'lib/vellum_ai/types/chat_message.rb', line 20

def additional_properties
  @additional_properties
end

#content ⇒ Vellum::ChatMessageContent (readonly)



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

def content
  @content
end

#metadata ⇒ Hash{String => Object} (readonly)

Returns:

  • (Hash{String => Object})


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

def 
  @metadata
end

#role ⇒ Vellum::ChatMessageRole (readonly)



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

def role
  @role
end

#source ⇒ String (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.rb', line 16

def source
  @source
end

#text ⇒ String (readonly)

Returns:

  • (String)


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

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ Vellum::ChatMessage

Parameters:

  • json_object (String)

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vellum_ai/types/chat_message.rb', line 49

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::ChatMessageContent.from_json(json_object: content)
  else
    content = nil
  end
  source = parsed_json["source"]
   = parsed_json["metadata"]
  new(
    text: text,
    role: role,
    content: content,
    source: source,
    metadata: ,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


83
84
85
86
87
88
89
# File 'lib/vellum_ai/types/chat_message.rb', line 83

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::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.")
  obj.&.is_a?(Hash) != false || raise("Passed value for field obj.metadata is not the expected type, validation failed.")
end

Instance Method Details

#to_json ⇒ String

Returns:

  • (String)


74
75
76
# File 'lib/vellum_ai/types/chat_message.rb', line 74

def to_json
  @_field_set&.to_json
end