omniai 1.0.1 → 1.0.3

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: b730453eea6e211031174bde7e43485b5402b9f0590bb832924762f8c2f6345c
4
- data.tar.gz: cad17682fc35243454f58b28a9bf0e2d48f9857415bfe3b72012f370b7e9d4ab
3
+ metadata.gz: 9ef66e140869ad45643072513852d7ed06439fb6a7fecda4f552ecb34c14ddb1
4
+ data.tar.gz: 55740c3bdc98c9d83330b1a45b1b83d760b279d388830e83fce8a671f635d26d
5
5
  SHA512:
6
- metadata.gz: 0ebd9716858486dc399504b8caefd3d4186cdc97da05715e8519fcbc2238b38672f6a760e5134b3231bfc4683662f69098edc3eb6bd22808e91658bb4207b1b4
7
- data.tar.gz: b7623a59effdc4714cbf78f8dd950cde0d3746da0dfc39ec7c9a6caf745ffedbd841d0b72097b1fdd30dd73f3f8ba35e7736a4253b32b7d2fcd7367c732172b0
6
+ metadata.gz: f335ee44a2460431d3f7bf83991448569f451930102ba1d3714c79af225db08d22467269c1543434a987de2d0f70bbe33faece99c4f291cc67032e7a5121721b
7
+ data.tar.gz: 33ca9dbf52c1a7af1c60683db4fd31680f4e3230da6c139591c6c62796616767b67109862963d8b1b7b93c6af46143e140471a606b20f0a6457b3f1989c87030
@@ -33,7 +33,17 @@ module OmniAI
33
33
 
34
34
  # @return [OmniAI::Chat::Usage]
35
35
  def usage
36
- @usage ||= Usage.new(data: @data['usage']) if @data['usage']
36
+ return unless @data['usage']
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
+ )
37
47
  end
38
48
 
39
49
  # @return [Array<OmniAI::Chat::Choice>]
@@ -3,37 +3,31 @@
3
3
  module OmniAI
4
4
  class Chat
5
5
  # A usage returned by the API.
6
- class Completion
7
- attr_accessor :data
6
+ class Usage
7
+ attr_accessor :input_tokens, :output_tokens, :total_tokens
8
8
 
9
- # @param data [Hash]
10
- def initialize(data:)
11
- @data = data
9
+ # @param input_tokens [Integer]
10
+ # @param output_tokens [Integer]
11
+ # @param total_tokens [Integer]
12
+ def initialize(input_tokens:, output_tokens:, total_tokens:)
13
+ @input_tokens = input_tokens
14
+ @output_tokens = output_tokens
15
+ @total_tokens = total_tokens
12
16
  end
13
17
 
14
- # @return [Integer, nil]
18
+ # @return [Integer]
15
19
  def completion_tokens
16
- @data['completion_tokens']
20
+ @output_tokens
17
21
  end
18
22
 
19
- # @return [Integer, nil]
23
+ # @return [Integer]
20
24
  def prompt_tokens
21
- @data['prompt_tokens']
25
+ @input_tokens
22
26
  end
23
27
 
24
- # @return [Integer, nil]
25
- def total_tokens
26
- @data['total_tokens']
27
- end
28
-
29
- # @return [Integer, nil]
30
- def input_tokens
31
- @data['input_tokens']
32
- end
33
-
34
- # @return [Integer, nil]
35
- def output_tokens
36
- @data['output_tokens']
28
+ # @return [String]
29
+ def inspect
30
+ "#<#{self.class.name} input_tokens=#{input_tokens} output_tokens=#{output_tokens} total_tokens=#{total_tokens}>"
37
31
  end
38
32
  end
39
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-14 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -83,7 +83,7 @@ metadata:
83
83
  homepage_uri: https://github.com/ksylvest/omniai
84
84
  changelog_uri: https://github.com/ksylvest/omniai/releases
85
85
  rubygems_mfa_required: 'true'
86
- post_install_message:
86
+ post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths:
89
89
  - lib
@@ -98,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.5.11
102
- signing_key:
101
+ rubygems_version: 3.5.3
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: A generalized framework for interacting with many AI services
105
105
  test_files: []