Class: OmniAI::Chat::Chunk

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

Overview

A chunk returned by the API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:) ⇒ Chunk

Returns a new instance of Chunk.

Parameters:

  • data (Hash)


10
11
12
# File 'lib/omniai/chat/chunk.rb', line 10

def initialize(data:)
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#choice(index: 0) ⇒ OmniAI::Chat::Delta

Parameters:

  • [Integer] (index)

Returns:



41
42
43
# File 'lib/omniai/chat/chunk.rb', line 41

def choice(index: 0)
  choices[index]
end

#choicesArray<OmniAI::Chat::Choice>

Returns:



35
36
37
# File 'lib/omniai/chat/chunk.rb', line 35

def choices
  @choices ||= @data['choices'].map { |data| Choice.for(data:) }
end

#createdTime

Returns:

  • (Time)


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

def created
  Time.at(@data['created']) if @data['created']
end

#idString

Returns:

  • (String)


15
16
17
# File 'lib/omniai/chat/chunk.rb', line 15

def id
  @data['id']
end

#modelString

Returns:

  • (String)


30
31
32
# File 'lib/omniai/chat/chunk.rb', line 30

def model
  @data['model']
end

#updatedTime

Returns:

  • (Time)


25
26
27
# File 'lib/omniai/chat/chunk.rb', line 25

def updated
  Time.at(@data['updated']) if @data['updated']
end