omniai 1.0.5 → 1.0.7

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: dddfc4d4ac08e936e1b2443e37ff93b4256428579aa1280b6ede769a01365f04
4
- data.tar.gz: 235c5f109e0e3526d2abfa2cf7d6c3a3d1e00749da70beaf884a2a1bcb9ba8c6
3
+ metadata.gz: 3be83f1587fcdde2ec982dc7220e5c0abd9d9c756b3879b50cb8be2558dad0f7
4
+ data.tar.gz: 6b031c1deaf0d9ef144fdba86a25650671b4492e960fcb633f1558a72922d61e
5
5
  SHA512:
6
- metadata.gz: fae66992c4f0a399ecbe795a39901e73caea1554861e23894fd005daab9b26e23cd6a110cca9cde9b9c9ce73af174037626b3505074bb4bd23477677a286b3ef
7
- data.tar.gz: 5f604bcdc4ca4b748e523eff6cb4b383cd9211188673c768d2295a7f9e43c1f043ac9c8b14ff86b9dabb85a99b50a005ce40b920cdbcdf19f9f1ef05b4f33ca5
6
+ metadata.gz: a07f2c8b25842f73c34fb8ca80bbb3efb1554da4bae6ffaca140167ee4581a198b175252d687dad1ac9dd34c05d4dbd63bfce951ecc5c907119c175d7dd92597
7
+ data.tar.gz: ea95daacea2365aeb68253d1c7168cfbae8cb26323a2e60ffc8212b43ad0c24497f8e8679188dec6a838dc21daf10387e363ad7a55a21def55c22a48968763f0
@@ -4,28 +4,23 @@ module OmniAI
4
4
  class Chat
5
5
  # A choice returned by the API.
6
6
  class Choice
7
- attr_accessor :data
7
+ attr_accessor :index, :delta, :message
8
8
 
9
9
  # @param data [Hash]
10
- def initialize(data:)
11
- @data = data
12
- end
13
-
14
- # @return [Integer]
15
- def index
16
- @data['index']
17
- end
10
+ # @return [OmniAI::Chat::Choice]
11
+ def self.for(data:)
12
+ index = data['index']
13
+ delta = Delta.for(data: data['delta']) if data['delta']
14
+ message = Message.for(data: data['message']) if data['message']
18
15
 
19
- # @return [OmniAI::Chat::Delta]
20
- def delta
21
- Delta.new(data: @data['delta']) if @data['delta']
16
+ new(index:, delta:, message:)
22
17
  end
23
18
 
24
- # @return [OmniAI::Chat::Message]
25
- def message
26
- return unless @data['message']
27
-
28
- @message ||= Message.for(role: @data['message'])
19
+ # @param data [Hash]
20
+ def initialize(index:, delta:, message:)
21
+ @index = index
22
+ @delta = delta
23
+ @message = message
29
24
  end
30
25
  end
31
26
  end
@@ -40,7 +40,7 @@ module OmniAI
40
40
 
41
41
  # @return [Array<OmniAI::Chat::Choice>]
42
42
  def choices
43
- @choices ||= @data['choices'].map { |data| Choice.new(data:) }
43
+ @choices ||= @data['choices'].map { |data| Choice.for(data:) }
44
44
  end
45
45
 
46
46
  # @param [index] [Integer] optional - default is 0
@@ -4,22 +4,27 @@ module OmniAI
4
4
  class Chat
5
5
  # A delta returned by the API.
6
6
  class Delta
7
- attr_accessor :data
7
+ attr_accessor :role, :content
8
8
 
9
- # @param content [Integer]
10
- # @param role [String]
11
- def initialize(data:)
12
- @data = data
9
+ # @param data [Hash]
10
+ # @return [OmniAI::Chat::Message]
11
+ def self.for(data:)
12
+ content = data['content'] || data[:content]
13
+ role = data['role'] || data[:role]
14
+
15
+ new(content:, role: role || Role::USER)
13
16
  end
14
17
 
15
- # @return [String, nil]
16
- def role
17
- @data['role']
18
+ # @param content [String]
19
+ # @param role [String]
20
+ def initialize(content:, role: nil)
21
+ @content = content
22
+ @role = role
18
23
  end
19
24
 
20
- # @return [String, nil]
21
- def content
22
- @data['content']
25
+ # @return [String]
26
+ def inspect
27
+ "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
23
28
  end
24
29
  end
25
30
  end
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.5'
4
+ VERSION = '1.0.7'
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.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre