omniai-google 1.2.0 → 1.3.0

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: 160ee5b0f488ea6fc30c0439f1e6d813ee5aedf89c0174a3e241d4c6ea68b9d7
4
- data.tar.gz: 20f52dfc6dc50cccbb1224eaf8c61403e7e523ef13f475da7bc2ada3c024a32f
3
+ metadata.gz: 211c1f9d1640953f0494852010f90e347763fc2c5ded1430506c07118d31452d
4
+ data.tar.gz: b768a2e8d92ee643168b61fbeaff90fe1cd5efa385e0aedbb29015e6c85ceb92
5
5
  SHA512:
6
- metadata.gz: ba9c0537a440707d32a94ccbfdec106836c4e43b21bd9310b6d55d2ca431b96943a4a5c320c1182e4c2fc13d0bd214a5f5c7e10ab4a9f62b1fb0953dda8f3d14
7
- data.tar.gz: 83a30a54a45daf71b0ebfbb5e53862cddec04f94c6cfddd20fb2dbb37a66d34148a66fb23ac44e9f3eba50884802ce5f4e87c94522ecd82fcb27f82fd5833a67
6
+ metadata.gz: a36130f6939632b59138d12c9d96d8ba59b6c5f0b17c5adc868bc1df482ac2a04020dd516a778ed7857ed84d5fa01bbf4a5c12d9ad07d3697edc8dbc4a234f4a
7
+ data.tar.gz: 34e61e6506e4d99185253e7aaf70c41e5fc2f802ce28321b5483fa417fa52bc9edfb505c45bbfb312f3f1a545814aac0b7c09d989149231a9dcfdcfc7f9830cd
@@ -10,7 +10,7 @@ module OmniAI
10
10
  @choices ||= [].tap do |choices|
11
11
  @data['candidates'].each do |candidate|
12
12
  candidate['content']['parts'].each do |part|
13
- choices << OmniAI::Chat::Choice.for(data: {
13
+ choices << OmniAI::Chat::DeltaChoice.for(data: {
14
14
  'index' => candidate['index'],
15
15
  'delta' => { 'role' => candidate['content']['role'], 'content' => part['text'] },
16
16
  })
@@ -10,7 +10,7 @@ module OmniAI
10
10
  @choices ||= [].tap do |entries|
11
11
  @data['candidates'].each do |candidate|
12
12
  candidate['content']['parts'].each do |part|
13
- entries << OmniAI::Chat::Choice.for(data: {
13
+ entries << OmniAI::Chat::MessageChoice.for(data: {
14
14
  'index' => candidate['index'],
15
15
  'message' => { 'role' => candidate['content']['role'], 'content' => part['text'] },
16
16
  })
@@ -20,31 +20,29 @@ module OmniAI
20
20
  #
21
21
  # client = OmniAI::Google::Client.new
22
22
  class Client < OmniAI::Client
23
+ # @!attribute [rw] version
24
+ # @return [String, nil]
23
25
  attr_accessor :version
24
26
 
25
27
  # @param api_key [String] optional - defaults to `OmniAI::Google.config.api_key`
26
28
  # @param host [String] optional - defaults to `OmniAI::Google.config.host`
27
29
  # @param version [String] optional - defaults to `OmniAI::Google.config.version`
28
30
  # @param logger [Logger] optional - defaults to `OmniAI::Google.config.logger`
31
+ # @param timeout [Integer] optional - defaults to `OmniAI::Google.config.timeout`
29
32
  def initialize(
30
33
  api_key: OmniAI::Google.config.api_key,
31
34
  logger: OmniAI::Google.config.logger,
32
35
  host: OmniAI::Google.config.host,
33
- version: OmniAI::Google.config.version
36
+ version: OmniAI::Google.config.version,
37
+ timeout: OmniAI::Google.config.timeout
34
38
  )
35
39
  raise(ArgumentError, %(ENV['GOOGLE_API_KEY'] must be defined or `api_key` must be passed)) if api_key.nil?
36
40
 
37
- super(api_key:, logger:)
41
+ super(api_key:, host:, logger:, timeout:)
38
42
 
39
- @host = host
40
43
  @version = version
41
44
  end
42
45
 
43
- # @return [HTTP::Client]
44
- def connection
45
- HTTP.persistent(@host)
46
- end
47
-
48
46
  # @raise [OmniAI::Error]
49
47
  #
50
48
  # @param messages [String, Array, Hash]
@@ -2,16 +2,29 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- # Config for the Google `api_key` / `host` / `logger` / `version`, `chat_options`.
5
+ # Configuration for Google.
6
6
  class Config < OmniAI::Config
7
- attr_accessor :chat_options, :version
7
+ DEFAULT_HOST = 'https://generativelanguage.googleapis.com'
8
+ DEFAULT_VERSION = 'v1'
8
9
 
9
- def initialize
10
- super
11
- @api_key = ENV.fetch('GOOGLE_API_KEY', nil)
12
- @host = ENV.fetch('GOOGLE_HOST', 'https://generativelanguage.googleapis.com')
13
- @version = ENV.fetch('GOOGLE_VERSION', 'v1')
14
- @chat_options = {}
10
+ # @!attribute [rw] version
11
+ # @return [String, nil]
12
+ attr_accessor :version
13
+
14
+ # @param api_key [String, nil] optional - defaults to `ENV['GOOGLE_API_KEY']`
15
+ # @param host [String, nil] optional - defaults to `ENV['GOOGLE_HOST'] w/ fallback to `DEFAULT_HOST`
16
+ # @param version [String, nil] optional - defaults to `ENV['GOOGLE_VERSION'] w/ fallback to `DEFAULT_VERSION`
17
+ # @param logger [Logger, nil] optional - defaults to
18
+ # @param timeout [Integer, Hash, nil] optional
19
+ def initialize(
20
+ api_key: ENV.fetch('GOOGLE_API_KEY', nil),
21
+ host: ENV.fetch('GOOGLE_HOST', DEFAULT_HOST),
22
+ version: ENV.fetch('GOOGLE_VERSION', DEFAULT_VERSION),
23
+ logger: nil,
24
+ timeout: nil
25
+ )
26
+ super(api_key:, host:, logger:, timeout:)
27
+ @version = version
15
28
  end
16
29
  end
17
30
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-20 00:00:00.000000000 Z
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser