Class: OmniAI::Chat::Completion
- Inherits:
-
Object
- Object
- OmniAI::Chat::Completion
- Defined in:
- lib/omniai/chat/completion.rb
Overview
A completion returned by the API.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #choice(index: 0) ⇒ OmniAI::Chat::Choice
- #choices ⇒ Array<OmniAI::Chat::Choice>
- #created ⇒ Time
- #id ⇒ String
-
#initialize(data:) ⇒ Completion
constructor
A new instance of Completion.
- #model ⇒ String
- #updated ⇒ Time
- #usage ⇒ OmniAI::Chat::Usage
Constructor Details
#initialize(data:) ⇒ Completion
Returns a new instance of Completion.
10 11 12 |
# File 'lib/omniai/chat/completion.rb', line 10 def initialize(data:) @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/omniai/chat/completion.rb', line 7 def data @data end |
Instance Method Details
#choice(index: 0) ⇒ OmniAI::Chat::Choice
48 49 50 |
# File 'lib/omniai/chat/completion.rb', line 48 def choice(index: 0) choices[index] end |
#choices ⇒ Array<OmniAI::Chat::Choice>
42 43 44 |
# File 'lib/omniai/chat/completion.rb', line 42 def choices @choices ||= @data['choices'].map { |data| Choice.for(data:) } end |
#created ⇒ Time
20 21 22 |
# File 'lib/omniai/chat/completion.rb', line 20 def created Time.at(@data['created']) if @data['created'] end |
#id ⇒ String
15 16 17 |
# File 'lib/omniai/chat/completion.rb', line 15 def id @data['id'] end |
#model ⇒ String
30 31 32 |
# File 'lib/omniai/chat/completion.rb', line 30 def model @data['model'] end |
#updated ⇒ Time
25 26 27 |
# File 'lib/omniai/chat/completion.rb', line 25 def updated Time.at(@data['updated']) if @data['updated'] end |
#usage ⇒ OmniAI::Chat::Usage
35 36 37 38 39 |
# File 'lib/omniai/chat/completion.rb', line 35 def usage return unless @data['usage'] @usage ||= Usage.for(data: @data['usage']) end |