omniai 1.0.4 → 1.0.6

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: 172ad18b8fbe97f2e8d23bf8624efea92591910f6d05eed5295789555f60e6d7
4
+ data.tar.gz: dc415cd3f63f293bc2d64cff39c3ee3c094f734d7a0fb330a1b25adf772f7016
5
5
  SHA512:
6
- metadata.gz: 9f2d2fa897c94b741435df368ca0952fe00e4dafd0f199756008749a1267ac2d4ea325338b1da359c7c84944b76ec3a875d678039b9bd88ee819cacb470a6fdd
7
- data.tar.gz: 698f4ec0159ac6a359f5bd93c02db3e4acd0cde6cfd42c17a30c341d6ad674720aa442040c0890cd3c600068c52717b011b28601335721fbdd7a55c1d74ae61d
6
+ metadata.gz: 1dc885877d697bf3c2053e8facbdc1a7329a8b3ae0804753e0e1daefcc9f37bcc7dd19de11c748fccdf4cc9be032cbbb1128558a8d437a125ab41ca44402d7ce
7
+ data.tar.gz: cb96cde1ff5203f08646217bfae1c0032a25f492cbb6b1565f34ea9a5a905c0626b6bfab5e651793cd853b34eaf0a95130ad8a41e2f8a77429c9faf0feb58cc5
@@ -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]
data/lib/omniai/chat.rb CHANGED
@@ -55,7 +55,7 @@ module OmniAI
55
55
  # @raise [ExecutionError]
56
56
  def process!
57
57
  response = request!
58
- raise HTTPError, response unless response.status.ok?
58
+ raise HTTPError, response.flush unless response.status.ok?
59
59
 
60
60
  parse!(response:)
61
61
  end
@@ -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.6'
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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre