Class: OmniAI::Chat::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/chat/message.rb

Overview

A message returned by the API.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, role: OmniAI::Chat::Role::USER) ⇒ Message

Returns a new instance of Message.

Parameters:

  • content (String)
  • role (String) (defaults to: OmniAI::Chat::Role::USER)

    optional (default to “user”) e.g. “assistant” / “user” / “system”



20
21
22
23
# File 'lib/omniai/chat/message.rb', line 20

def initialize(content:, role: OmniAI::Chat::Role::USER)
  @role = role
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/omniai/chat/message.rb', line 7

def content
  @content
end

#roleObject

Returns the value of attribute role.



7
8
9
# File 'lib/omniai/chat/message.rb', line 7

def role
  @role
end

Class Method Details

.for(data:) ⇒ OmniAI::Chat::Message

Parameters:

  • data (Hash)

Returns:



11
12
13
14
15
16
# File 'lib/omniai/chat/message.rb', line 11

def self.for(data:)
  content = data['content'] || data[:content]
  role = data['role'] || data[:role]

  new(content:, role: role || Role::USER)
end

Instance Method Details

#inspectString

Returns:

  • (String)


26
27
28
# File 'lib/omniai/chat/message.rb', line 26

def inspect
  "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
end