Class: OmniAI::Chat::Delta

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

Overview

A delta returned by the API.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, role: nil) ⇒ Delta

Returns a new instance of Delta.

Parameters:

  • content (String)
  • role (String) (defaults to: nil)


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

def initialize(content:, role: nil)
  @content = content
  @role = role
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#roleObject

Returns the value of attribute role.



7
8
9
# File 'lib/omniai/chat/delta.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/delta.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/delta.rb', line 26

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