gemini-ai 3.0.0 → 3.1.1

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: 80621f6cd2de526141e994a339d645b53492f6ece960955bc56f2e7430be1d0c
4
- data.tar.gz: b627386a0dacc899112e0b08806f63b571dd980f2fb749df7681d7c70656d707
3
+ metadata.gz: 82d91a5c477a7fc770905d37e1980e1e011ac3b8967d956ff8d6b961b0b7e00c
4
+ data.tar.gz: b1b0ef631d90765e8bd468cbee7c5e390d6b17020748bd9d49c8e4335451c3de
5
5
  SHA512:
6
- metadata.gz: f5425c3239dac6eca23cccdb2483f90bea23500b0830b865e8acc0fe235cf2ad3cb001d110e7a6ec0cbb59ed5c2f65e74f883edef961cb675b76e7d6117d88fc
7
- data.tar.gz: 041122dc5a6d1d596411ea697503aa8d7846b4d2bc6c493b8b7d9102033c9ef3226957340d8caeb443751f9f4f465624a80ef1749e0f5893833e4c72d43ba907
6
+ metadata.gz: 62ad35fe0f262c304944199a37bd042f857966cd794b889ae93a39412cf54340a5caa30a24cdac51ca7cfdba46ac586bab5035725d0ee0be6156d3043d8b10fc
7
+ data.tar.gz: c0b6dc1ead7966c5e7dbb4884a564df0397f3d2e7e9a078a7112159e543e45325b8433e4fa2c70c89b9c13dbd13d94ee4cee411ce16f72aa3238bfe3b3fee86e
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gemini-ai (3.0.0)
4
+ gemini-ai (3.1.1)
5
5
  event_stream_parser (~> 1.0)
6
- faraday (~> 2.7, >= 2.7.12)
7
- googleauth (~> 1.9, >= 1.9.1)
6
+ faraday (~> 2.8, >= 2.8.1)
7
+ googleauth (>= 1.8, < 3)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -16,7 +16,7 @@ GEM
16
16
  byebug (11.1.3)
17
17
  coderay (1.1.3)
18
18
  event_stream_parser (1.0.0)
19
- faraday (2.7.12)
19
+ faraday (2.8.1)
20
20
  base64
21
21
  faraday-net_http (>= 2.0, < 3.1)
22
22
  ruby2_keywords (>= 0.0.4)
@@ -37,7 +37,7 @@ GEM
37
37
  multi_json (1.15.0)
38
38
  os (1.1.4)
39
39
  parallel (1.24.0)
40
- parser (3.2.2.4)
40
+ parser (3.3.0.0)
41
41
  ast (~> 2.4.1)
42
42
  racc
43
43
  pry (0.14.2)
data/README.md CHANGED
@@ -9,7 +9,7 @@ A Ruby Gem for interacting with [Gemini](https://deepmind.google/technologies/ge
9
9
  ## TL;DR and Quick Start
10
10
 
11
11
  ```ruby
12
- gem 'gemini-ai', '~> 3.0.0'
12
+ gem 'gemini-ai', '~> 3.1.1'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -96,6 +96,8 @@ Result:
96
96
  - [Back-and-Forth Conversations](#back-and-forth-conversations)
97
97
  - [Tools (Functions) Calling](#tools-functions-calling)
98
98
  - [New Functionalities and APIs](#new-functionalities-and-apis)
99
+ - [Request Options](#request-options)
100
+ - [Timeout](#timeout)
99
101
  - [Error Handling](#error-handling)
100
102
  - [Rescuing](#rescuing)
101
103
  - [For Short](#for-short)
@@ -112,11 +114,11 @@ Result:
112
114
  ### Installing
113
115
 
114
116
  ```sh
115
- gem install gemini-ai -v 3.0.0
117
+ gem install gemini-ai -v 3.1.1
116
118
  ```
117
119
 
118
120
  ```sh
119
- gem 'gemini-ai', '~> 3.0.0'
121
+ gem 'gemini-ai', '~> 3.1.1'
120
122
  ```
121
123
 
122
124
  ### Credentials
@@ -872,6 +874,42 @@ result = client.request(
872
874
  )
873
875
  ```
874
876
 
877
+ ### Request Options
878
+
879
+ #### Timeout
880
+
881
+ You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
882
+
883
+ ```ruby
884
+ client = Gemini.new(
885
+ credentials: { service: 'vertex-ai-api', region: 'us-east4' },
886
+ options: {
887
+ model: 'gemini-pro',
888
+ connection: { request: { timeout: 5 } }
889
+ }
890
+ )
891
+ ```
892
+
893
+ You can also have more fine-grained control over [Faraday's Request Options](https://lostisland.github.io/faraday/#/customization/request-options?id=request-options) if you prefer:
894
+
895
+ ```ruby
896
+ client = Gemini.new(
897
+ credentials: { service: 'vertex-ai-api', region: 'us-east4' },
898
+ options: {
899
+ model: 'gemini-pro',
900
+ connection: {
901
+ request: {
902
+ timeout: 5,
903
+ open_timeout: 5,
904
+ read_timeout: 5,
905
+ write_timeout: 5
906
+ }
907
+ }
908
+ }
909
+ )
910
+ ```
911
+
912
+
875
913
  ### Error Handling
876
914
 
877
915
  #### Rescuing
@@ -942,7 +980,7 @@ gem build gemini-ai.gemspec
942
980
 
943
981
  gem signin
944
982
 
945
- gem push gemini-ai-3.0.0.gem
983
+ gem push gemini-ai-3.1.1.gem
946
984
  ```
947
985
 
948
986
  ### Updating the README
@@ -10,6 +10,8 @@ require_relative '../ports/dsl/gemini-ai/errors'
10
10
  module Gemini
11
11
  module Controllers
12
12
  class Client
13
+ ALLOWED_REQUEST_OPTIONS = %i[timeout open_timeout read_timeout write_timeout].freeze
14
+
13
15
  def initialize(config)
14
16
  if config[:credentials][:api_key]
15
17
  @authentication = :api_key
@@ -42,7 +44,17 @@ module Gemini
42
44
  raise UnsupportedServiceError, "Unsupported service: #{@service}"
43
45
  end
44
46
 
45
- @server_sent_events = config[:options][:server_sent_events]
47
+ @server_sent_events = config.dig(:options, :server_sent_events)
48
+
49
+ @request_options = config.dig(:options, :connection, :request)
50
+
51
+ @request_options = if @request_options.is_a?(Hash)
52
+ @request_options.select do |key, _|
53
+ ALLOWED_REQUEST_OPTIONS.include?(key)
54
+ end
55
+ else
56
+ {}
57
+ end
46
58
  end
47
59
 
48
60
  def stream_generate_content(payload, server_sent_events: nil, &callback)
@@ -74,7 +86,7 @@ module Gemini
74
86
 
75
87
  results = []
76
88
 
77
- response = Faraday.new do |faraday|
89
+ response = Faraday.new(request: @request_options) do |faraday|
78
90
  faraday.response :raise_error
79
91
  end.post do |request|
80
92
  request.url url
@@ -106,8 +118,10 @@ module Gemini
106
118
 
107
119
  results << result
108
120
 
109
- parsed_data['candidates'].find do |candidate|
110
- !candidate['finishReason'].nil? && candidate['finishReason'] != ''
121
+ if parsed_data['candidates']
122
+ parsed_data['candidates'].find do |candidate|
123
+ !candidate['finishReason'].nil? && candidate['finishReason'] != ''
124
+ end
111
125
  end
112
126
  end
113
127
  end
data/gemini-ai.gemspec CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ['ports/dsl']
31
31
 
32
32
  spec.add_dependency 'event_stream_parser', '~> 1.0'
33
- spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.12'
34
- spec.add_dependency 'googleauth', '~> 1.9', '>= 1.9.1'
33
+ spec.add_dependency 'faraday', '~> 2.8', '>= 2.8.1'
34
+ spec.add_dependency 'googleauth', '>= 1.8', '< 3'
35
35
 
36
36
  spec.metadata['rubygems_mfa_required'] = 'true'
37
37
  end
data/static/gem.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Gemini
4
4
  GEM = {
5
5
  name: 'gemini-ai',
6
- version: '3.0.0',
6
+ version: '3.1.1',
7
7
  author: 'gbaptista',
8
8
  summary: "Interact with Google's Gemini AI.",
9
9
  description: "A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.",
data/template.md CHANGED
@@ -9,7 +9,7 @@ A Ruby Gem for interacting with [Gemini](https://deepmind.google/technologies/ge
9
9
  ## TL;DR and Quick Start
10
10
 
11
11
  ```ruby
12
- gem 'gemini-ai', '~> 3.0.0'
12
+ gem 'gemini-ai', '~> 3.1.1'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -77,11 +77,11 @@ Result:
77
77
  ### Installing
78
78
 
79
79
  ```sh
80
- gem install gemini-ai -v 3.0.0
80
+ gem install gemini-ai -v 3.1.1
81
81
  ```
82
82
 
83
83
  ```sh
84
- gem 'gemini-ai', '~> 3.0.0'
84
+ gem 'gemini-ai', '~> 3.1.1'
85
85
  ```
86
86
 
87
87
  ### Credentials
@@ -837,6 +837,42 @@ result = client.request(
837
837
  )
838
838
  ```
839
839
 
840
+ ### Request Options
841
+
842
+ #### Timeout
843
+
844
+ You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
845
+
846
+ ```ruby
847
+ client = Gemini.new(
848
+ credentials: { service: 'vertex-ai-api', region: 'us-east4' },
849
+ options: {
850
+ model: 'gemini-pro',
851
+ connection: { request: { timeout: 5 } }
852
+ }
853
+ )
854
+ ```
855
+
856
+ You can also have more fine-grained control over [Faraday's Request Options](https://lostisland.github.io/faraday/#/customization/request-options?id=request-options) if you prefer:
857
+
858
+ ```ruby
859
+ client = Gemini.new(
860
+ credentials: { service: 'vertex-ai-api', region: 'us-east4' },
861
+ options: {
862
+ model: 'gemini-pro',
863
+ connection: {
864
+ request: {
865
+ timeout: 5,
866
+ open_timeout: 5,
867
+ read_timeout: 5,
868
+ write_timeout: 5
869
+ }
870
+ }
871
+ }
872
+ )
873
+ ```
874
+
875
+
840
876
  ### Error Handling
841
877
 
842
878
  #### Rescuing
@@ -907,7 +943,7 @@ gem build gemini-ai.gemspec
907
943
 
908
944
  gem signin
909
945
 
910
- gem push gemini-ai-3.0.0.gem
946
+ gem push gemini-ai-3.1.1.gem
911
947
  ```
912
948
 
913
949
  ### Updating the README
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemini-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gbaptista
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-17 00:00:00.000000000 Z
11
+ date: 2024-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -30,40 +30,40 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.7'
33
+ version: '2.8'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 2.7.12
36
+ version: 2.8.1
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '2.7'
43
+ version: '2.8'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 2.7.12
46
+ version: 2.8.1
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: googleauth
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.9'
54
51
  - - ">="
55
52
  - !ruby/object:Gem::Version
56
- version: 1.9.1
53
+ version: '1.8'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '3'
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '1.9'
64
61
  - - ">="
65
62
  - !ruby/object:Gem::Version
66
- version: 1.9.1
63
+ version: '1.8'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '3'
67
67
  description: A Ruby Gem for interacting with Gemini through Vertex AI, Generative
68
68
  Language API, or AI Studio, Google's generative AI services.
69
69
  email:
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.4.22
112
+ rubygems_version: 3.3.3
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Interact with Google's Gemini AI.