Class: OmniAI::Embed::Response
- Inherits:
-
Object
- Object
- OmniAI::Embed::Response
- Defined in:
- lib/omniai/embed/response.rb
Overview
The response returned by the API.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #embedding(index: 0) ⇒ Array<Float>
- #embeddings ⇒ Array<Array<Float>>
-
#initialize(data:, context: nil) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ String
- #usage ⇒ Usage
Constructor Details
#initialize(data:, context: nil) ⇒ Response
Returns a new instance of Response.
12 13 14 15 |
# File 'lib/omniai/embed/response.rb', line 12 def initialize(data:, context: nil) @data = data @context = context end |
Instance Attribute Details
#data ⇒ Hash
8 9 10 |
# File 'lib/omniai/embed/response.rb', line 8 def data @data end |
Instance Method Details
#embedding(index: 0) ⇒ Array<Float>
41 42 43 |
# File 'lib/omniai/embed/response.rb', line 41 def (index: 0) [index] end |
#embeddings ⇒ Array<Array<Float>>
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/omniai/embed/response.rb', line 46 def @embeddings ||= begin deserializer = @context&.deserializer(:embeddings) if deserializer deserializer.call(@data, context: @context) else @data['data'].map { || ['embedding'] } end end end |
#inspect ⇒ String
18 19 20 |
# File 'lib/omniai/embed/response.rb', line 18 def inspect "#<#{self.class.name}>" end |
#usage ⇒ Usage
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/omniai/embed/response.rb', line 23 def usage @usage ||= begin deserializer = @context&.deserializer(:usage) if deserializer deserializer.call(@data, context: @context) else prompt_tokens = @data.dig('usage', 'prompt_tokens') total_tokens = @data.dig('usage', 'total_tokens') Usage.new(prompt_tokens:, total_tokens:) end end end |