Class: OmniAI::Chat::Choice

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

Overview

A choice returned by the API.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, delta:, message:) ⇒ Choice

Returns a new instance of Choice.

Parameters:

  • data (Hash)


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

def initialize(index:, delta:, message:)
  @index = index
  @delta = delta
  @message = message
end

Instance Attribute Details

#deltaObject

Returns the value of attribute delta.



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

def delta
  @delta
end

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

Class Method Details

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

Parameters:

  • data (Hash)

Returns:



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

def self.for(data:)
  index = data['index']
  delta = Delta.for(data: data['delta']) if data['delta']
  message = Message.for(data: data['message']) if data['message']

  new(index:, delta:, message:)
end