omniai 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d821530b3b40043754c26a175c2b5d9c70fe3f04bd62bf61c5506963e56dae3
4
- data.tar.gz: 6f0cf3e3292b11492bd25526391ec3a396d5a9262050dcf4d5aba35726c2ed04
3
+ metadata.gz: dddfc4d4ac08e936e1b2443e37ff93b4256428579aa1280b6ede769a01365f04
4
+ data.tar.gz: 235c5f109e0e3526d2abfa2cf7d6c3a3d1e00749da70beaf884a2a1bcb9ba8c6
5
5
  SHA512:
6
- metadata.gz: 9f2d2fa897c94b741435df368ca0952fe00e4dafd0f199756008749a1267ac2d4ea325338b1da359c7c84944b76ec3a875d678039b9bd88ee819cacb470a6fdd
7
- data.tar.gz: 698f4ec0159ac6a359f5bd93c02db3e4acd0cde6cfd42c17a30c341d6ad674720aa442040c0890cd3c600068c52717b011b28601335721fbdd7a55c1d74ae61d
6
+ metadata.gz: fae66992c4f0a399ecbe795a39901e73caea1554861e23894fd005daab9b26e23cd6a110cca9cde9b9c9ce73af174037626b3505074bb4bd23477677a286b3ef
7
+ data.tar.gz: 5f604bcdc4ca4b748e523eff6cb4b383cd9211188673c768d2295a7f9e43c1f043ac9c8b14ff86b9dabb85a99b50a005ce40b920cdbcdf19f9f1ef05b4f33ca5
@@ -35,15 +35,7 @@ module OmniAI
35
35
  def usage
36
36
  return unless @data['usage']
37
37
 
38
- input_tokens = @data['usage']['input_tokens'] || @data['usage']['prompt_tokens']
39
- output_tokens = @data['usage']['output_tokens'] || @data['usage']['completion_tokens']
40
- total_tokens = @data['usage']['total_tokens'] || (input_tokens + output_tokens)
41
-
42
- @usage ||= Usage.new(
43
- input_tokens:,
44
- output_tokens:,
45
- total_tokens:
46
- )
38
+ @usage ||= Usage.for(data: @data['usage'])
47
39
  end
48
40
 
49
41
  # @return [Array<OmniAI::Chat::Choice>]
@@ -6,6 +6,20 @@ module OmniAI
6
6
  class Usage
7
7
  attr_accessor :input_tokens, :output_tokens, :total_tokens
8
8
 
9
+ # @param data [Hash]
10
+ # @return [OmniAI::Chat::Usage]
11
+ def self.for(data:)
12
+ input_tokens = data['input_tokens'] || data['prompt_tokens']
13
+ output_tokens = data['output_tokens'] || data['completion_tokens']
14
+ total_tokens = data['total_tokens'] || (input_tokens + output_tokens)
15
+
16
+ new(
17
+ input_tokens:,
18
+ output_tokens:,
19
+ total_tokens:
20
+ )
21
+ end
22
+
9
23
  # @param input_tokens [Integer]
10
24
  # @param output_tokens [Integer]
11
25
  # @param total_tokens [Integer]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre