gemini-ai 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eda19196e43e0d519127fd3e91c477835d03035115d837849ac398788901d50a
4
- data.tar.gz: dad8ccd200487954be14b3cd2e459848e5e557bb10961bcbfdedc70733191742
3
+ metadata.gz: 5ad19a7cfc87b01f59e5b9eeb11241d63f68a843da3c1f1f8a2784fc20c55cd4
4
+ data.tar.gz: 2527dda3745613f278c1164aa4625ad447564e22853737e3bce69d423a076fcc
5
5
  SHA512:
6
- metadata.gz: ee6e3a097d57d1a4f81d74bcec541a03aa23e1829d36b0296817345da6503fc1a198baad7e333e68996654f586ddc822704572159c297afe05e41ba687e2bba3
7
- data.tar.gz: 55eae644861d7c4a45ab2551357e17c44b4490f0d73b706adeb26b12a1931f65db77a5ca64b589b2447367404fea7951cc15710ba12ce2b4561a7b12f84fc05e
6
+ metadata.gz: 51da36a047e941a324de2ee0d7c110aef52c379c63d8e38af219bdd4bae7b61952648933abf06608c75558cd439168304549d8c6d6e0a347f5f8aa6e190cac95
7
+ data.tar.gz: d967a7c1ec04f3dd6f9959de82fa4c6295c5e79a2d1a8c9f442902a0147bcd0ecd11beec3599e8550247c6d91b7c0b8ef854b29ba638fcb08b6f826f21f9aac8
data/Gemfile CHANGED
@@ -5,9 +5,9 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :test, :development do
8
- gem 'dotenv', '~> 3.1', '>= 3.1.2'
9
- gem 'pry-byebug', '~> 3.10', '>= 3.10.1'
10
- gem 'rspec', '~> 3.13'
11
- gem 'rubocop', '~> 1.64', '>= 1.64.1'
12
- gem 'rubocop-rspec', '~> 3.0', '>= 3.0.1'
8
+ gem 'dotenv', '~> 3.1', '>= 3.1.8'
9
+ gem 'pry-byebug', '~> 3.11'
10
+ gem 'rspec', '~> 3.13', '>= 3.13.1'
11
+ gem 'rubocop', '~> 1.78'
12
+ gem 'rubocop-rspec', '~> 3.6'
13
13
  end
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gemini-ai (4.1.0)
4
+ gemini-ai (4.3.0)
5
5
  event_stream_parser (~> 1.0)
6
- faraday (~> 2.9, >= 2.9.2)
6
+ faraday (~> 2.13, >= 2.13.2)
7
7
  faraday-typhoeus (~> 1.1)
8
8
  googleauth (~> 1.8)
9
9
  typhoeus (~> 1.4, >= 1.4.1)
@@ -13,107 +13,116 @@ GEM
13
13
  specs:
14
14
  addressable (2.8.7)
15
15
  public_suffix (>= 2.0.2, < 7.0)
16
- ast (2.4.2)
17
- base64 (0.2.0)
18
- byebug (11.1.3)
16
+ ast (2.4.3)
17
+ base64 (0.3.0)
18
+ byebug (12.0.0)
19
19
  coderay (1.1.3)
20
- diff-lcs (1.5.1)
21
- dotenv (3.1.2)
20
+ diff-lcs (1.6.2)
21
+ dotenv (3.1.8)
22
22
  ethon (0.16.0)
23
23
  ffi (>= 1.15.0)
24
24
  event_stream_parser (1.0.0)
25
- faraday (2.9.2)
26
- faraday-net_http (>= 2.0, < 3.2)
27
- faraday-net_http (3.1.0)
28
- net-http
25
+ faraday (2.13.2)
26
+ faraday-net_http (>= 2.0, < 3.5)
27
+ json
28
+ logger
29
+ faraday-net_http (3.4.1)
30
+ net-http (>= 0.5.0)
29
31
  faraday-typhoeus (1.1.0)
30
32
  faraday (~> 2.0)
31
33
  typhoeus (~> 1.4)
32
- ffi (1.17.0)
33
- google-cloud-env (2.1.1)
34
+ ffi (1.17.2)
35
+ google-cloud-env (2.3.1)
36
+ base64 (~> 0.2)
34
37
  faraday (>= 1.0, < 3.a)
35
- googleauth (1.11.0)
38
+ google-logging-utils (0.2.0)
39
+ googleauth (1.14.0)
36
40
  faraday (>= 1.0, < 3.a)
37
- google-cloud-env (~> 2.1)
41
+ google-cloud-env (~> 2.2)
42
+ google-logging-utils (~> 0.1)
38
43
  jwt (>= 1.4, < 3.0)
39
44
  multi_json (~> 1.11)
40
45
  os (>= 0.9, < 2.0)
41
46
  signet (>= 0.16, < 2.a)
42
- json (2.7.2)
43
- jwt (2.8.2)
47
+ json (2.12.2)
48
+ jwt (2.10.2)
44
49
  base64
45
- language_server-protocol (3.17.0.3)
50
+ language_server-protocol (3.17.0.5)
51
+ lint_roller (1.1.0)
52
+ logger (1.7.0)
46
53
  method_source (1.1.0)
47
54
  multi_json (1.15.0)
48
- net-http (0.4.1)
55
+ net-http (0.6.0)
49
56
  uri
50
57
  os (1.1.4)
51
- parallel (1.25.1)
52
- parser (3.3.3.0)
58
+ parallel (1.27.0)
59
+ parser (3.3.8.0)
53
60
  ast (~> 2.4.1)
54
61
  racc
55
- pry (0.14.2)
62
+ prism (1.4.0)
63
+ pry (0.15.2)
56
64
  coderay (~> 1.1)
57
65
  method_source (~> 1.0)
58
- pry-byebug (3.10.1)
59
- byebug (~> 11.0)
60
- pry (>= 0.13, < 0.15)
61
- public_suffix (6.0.0)
62
- racc (1.8.0)
66
+ pry-byebug (3.11.0)
67
+ byebug (~> 12.0)
68
+ pry (>= 0.13, < 0.16)
69
+ public_suffix (6.0.2)
70
+ racc (1.8.1)
63
71
  rainbow (3.1.1)
64
- regexp_parser (2.9.2)
65
- rexml (3.3.0)
66
- strscan
67
- rspec (3.13.0)
72
+ regexp_parser (2.10.0)
73
+ rspec (3.13.1)
68
74
  rspec-core (~> 3.13.0)
69
75
  rspec-expectations (~> 3.13.0)
70
76
  rspec-mocks (~> 3.13.0)
71
- rspec-core (3.13.0)
77
+ rspec-core (3.13.5)
72
78
  rspec-support (~> 3.13.0)
73
- rspec-expectations (3.13.1)
79
+ rspec-expectations (3.13.5)
74
80
  diff-lcs (>= 1.2.0, < 2.0)
75
81
  rspec-support (~> 3.13.0)
76
- rspec-mocks (3.13.1)
82
+ rspec-mocks (3.13.5)
77
83
  diff-lcs (>= 1.2.0, < 2.0)
78
84
  rspec-support (~> 3.13.0)
79
- rspec-support (3.13.1)
80
- rubocop (1.64.1)
85
+ rspec-support (3.13.4)
86
+ rubocop (1.78.0)
81
87
  json (~> 2.3)
82
- language_server-protocol (>= 3.17.0)
88
+ language_server-protocol (~> 3.17.0.2)
89
+ lint_roller (~> 1.1.0)
83
90
  parallel (~> 1.10)
84
91
  parser (>= 3.3.0.2)
85
92
  rainbow (>= 2.2.2, < 4.0)
86
- regexp_parser (>= 1.8, < 3.0)
87
- rexml (>= 3.2.5, < 4.0)
88
- rubocop-ast (>= 1.31.1, < 2.0)
93
+ regexp_parser (>= 2.9.3, < 3.0)
94
+ rubocop-ast (>= 1.45.1, < 2.0)
89
95
  ruby-progressbar (~> 1.7)
90
- unicode-display_width (>= 2.4.0, < 3.0)
91
- rubocop-ast (1.31.3)
92
- parser (>= 3.3.1.0)
93
- rubocop-rspec (3.0.1)
94
- rubocop (~> 1.61)
96
+ unicode-display_width (>= 2.4.0, < 4.0)
97
+ rubocop-ast (1.45.1)
98
+ parser (>= 3.3.7.2)
99
+ prism (~> 1.4)
100
+ rubocop-rspec (3.6.0)
101
+ lint_roller (~> 1.1)
102
+ rubocop (~> 1.72, >= 1.72.1)
95
103
  ruby-progressbar (1.13.0)
96
- signet (0.19.0)
104
+ signet (0.20.0)
97
105
  addressable (~> 2.8)
98
106
  faraday (>= 0.17.5, < 3.a)
99
107
  jwt (>= 1.5, < 3.0)
100
108
  multi_json (~> 1.10)
101
- strscan (3.1.0)
102
109
  typhoeus (1.4.1)
103
110
  ethon (>= 0.9.0)
104
- unicode-display_width (2.5.0)
105
- uri (0.13.0)
111
+ unicode-display_width (3.1.4)
112
+ unicode-emoji (~> 4.0, >= 4.0.4)
113
+ unicode-emoji (4.0.4)
114
+ uri (1.0.3)
106
115
 
107
116
  PLATFORMS
108
117
  x86_64-linux
109
118
 
110
119
  DEPENDENCIES
111
- dotenv (~> 3.1, >= 3.1.2)
120
+ dotenv (~> 3.1, >= 3.1.8)
112
121
  gemini-ai!
113
- pry-byebug (~> 3.10, >= 3.10.1)
114
- rspec (~> 3.13)
115
- rubocop (~> 1.64, >= 1.64.1)
116
- rubocop-rspec (~> 3.0, >= 3.0.1)
122
+ pry-byebug (~> 3.11)
123
+ rspec (~> 3.13, >= 3.13.1)
124
+ rubocop (~> 1.78)
125
+ rubocop-rspec (~> 3.6)
117
126
 
118
127
  BUNDLED WITH
119
128
  2.4.22
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', '~> 4.1.0'
12
+ gem 'gemini-ai', '~> 4.3.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -59,6 +59,12 @@ result = client.stream_generate_content({
59
59
  })
60
60
  ```
61
61
 
62
+ Google now supports a [global endpoint](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#global-endpoint):
63
+
64
+ ```ruby
65
+ Gemini.new(credentials: { region: 'global' })
66
+ ```
67
+
62
68
  Result:
63
69
  ```ruby
64
70
  [{ 'candidates' =>
@@ -91,6 +97,7 @@ Result:
91
97
  - [Option 3: Application Default Credentials (Vertex AI API)](#option-3-application-default-credentials-vertex-ai-api)
92
98
  - [Required Data](#required-data)
93
99
  - [Custom Version](#custom-version)
100
+ - [Global Endpoint](#global-endpoint)
94
101
  - [Available Models](#available-models)
95
102
  - [Usage](#usage)
96
103
  - [Client](#client)
@@ -113,6 +120,7 @@ Result:
113
120
  - [Back-and-Forth Conversations](#back-and-forth-conversations)
114
121
  - [Safety Settings](#safety-settings)
115
122
  - [System Instructions](#system-instructions)
123
+ - [Counting Tokens](#counting-tokens)
116
124
  - [JSON Format Responses](#json-format-responses)
117
125
  - [JSON Schema](#json-schema)
118
126
  - [Models That Support JSON](#models-that-support-json)
@@ -137,11 +145,11 @@ Result:
137
145
  ### Installing
138
146
 
139
147
  ```sh
140
- gem install gemini-ai -v 4.1.0
148
+ gem install gemini-ai -v 4.3.0
141
149
  ```
142
150
 
143
151
  ```sh
144
- gem 'gemini-ai', '~> 4.1.0'
152
+ gem 'gemini-ai', '~> 4.3.0'
145
153
  ```
146
154
 
147
155
  ### Credentials
@@ -358,6 +366,14 @@ client = Gemini.new(
358
366
  )
359
367
  ```
360
368
 
369
+ ### Global Endpoint
370
+
371
+ Google now supports a [global endpoint](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#global-endpoint):
372
+
373
+ ```ruby
374
+ Gemini.new(credentials: { region: 'global' })
375
+ ```
376
+
361
377
  ## Available Models
362
378
 
363
379
  These models are accessible to the repository **author** as of June 2025 in the `us-east4` region. Access to models may vary by region, user, and account. All models here are expected to work, if you can access them. This is just a reference of what a "typical" user may expect to have access to right away:
@@ -991,6 +1007,27 @@ Output:
991
1007
  Meow! I'm Neko, a fluffy and playful cat. :3
992
1008
  ```
993
1009
 
1010
+ ### Counting Tokens
1011
+
1012
+ You can [count tokens](https://ai.google.dev/gemini-api/docs/tokens#count-tokens) and preview how many tokens a request is expected to consume:
1013
+
1014
+ ```ruby
1015
+ client.count_tokens(
1016
+ { contents: { role: 'user', parts: { text: 'hi!' } } }
1017
+ )
1018
+ ```
1019
+
1020
+ Output for Generative Language API:
1021
+ ```ruby
1022
+ { 'totalTokens' => 3 }
1023
+ ```
1024
+
1025
+ Output for Vertex AI API:
1026
+
1027
+ ```ruby
1028
+ { 'totalTokens' => 2, 'totalBillableCharacters' => 3 }
1029
+ ```
1030
+
994
1031
  ### JSON Format Responses
995
1032
 
996
1033
  > _As of the writing of this README, only the `vertex-ai-api` service and `gemini` models version `1.5` support this feature._
@@ -1418,7 +1455,7 @@ gem build gemini-ai.gemspec
1418
1455
 
1419
1456
  gem signin
1420
1457
 
1421
- gem push gemini-ai-4.1.0.gem
1458
+ gem push gemini-ai-4.3.0.gem
1422
1459
  ```
1423
1460
 
1424
1461
  ### Updating the README
@@ -56,7 +56,11 @@ module Gemini
56
56
 
57
57
  @base_address = case @service
58
58
  when 'vertex-ai-api'
59
- "https://#{config[:credentials][:region]}-aiplatform.googleapis.com/#{@service_version}/projects/#{@project_id}/locations/#{config[:credentials][:region]}"
59
+ if config[:credentials][:region] == 'global'
60
+ "https://aiplatform.googleapis.com/#{@service_version}/projects/#{@project_id}/locations/#{config[:credentials][:region]}"
61
+ else
62
+ "https://#{config[:credentials][:region]}-aiplatform.googleapis.com/#{@service_version}/projects/#{@project_id}/locations/#{config[:credentials][:region]}"
63
+ end
60
64
  when 'generative-language-api'
61
65
  "https://generativelanguage.googleapis.com/#{@service_version}"
62
66
  end
@@ -75,9 +79,7 @@ module Gemini
75
79
  @faraday_adapter = config.dig(:options, :connection, :adapter) || DEFAULT_FARADAY_ADAPTER
76
80
 
77
81
  @request_options = if @request_options.is_a?(Hash)
78
- @request_options.select do |key, _|
79
- ALLOWED_REQUEST_OPTIONS.include?(key)
80
- end
82
+ @request_options.slice(*ALLOWED_REQUEST_OPTIONS)
81
83
  else
82
84
  {}
83
85
  end
@@ -109,6 +111,17 @@ module Gemini
109
111
  result
110
112
  end
111
113
 
114
+ def count_tokens(payload, server_sent_events: nil, &callback)
115
+ result = request(
116
+ "#{@model_address}:countTokens", payload,
117
+ server_sent_events:, &callback
118
+ )
119
+
120
+ return result.first if result.is_a?(Array) && result.size == 1
121
+
122
+ result
123
+ end
124
+
112
125
  def embed_content(payload, server_sent_events: nil, &callback)
113
126
  result = request(
114
127
  "#{@model_address}:embedContent", payload,
data/gemini-ai.gemspec CHANGED
@@ -30,7 +30,7 @@ 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.9', '>= 2.9.2'
33
+ spec.add_dependency 'faraday', '~> 2.13', '>= 2.13.2'
34
34
  spec.add_dependency 'faraday-typhoeus', '~> 1.1'
35
35
 
36
36
  # Before upgrading, check this:
data/static/gem.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Gemini
4
4
  GEM = {
5
5
  name: 'gemini-ai',
6
- version: '4.1.0',
6
+ version: '4.3.0',
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', '~> 4.1.0'
12
+ gem 'gemini-ai', '~> 4.3.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -59,6 +59,12 @@ result = client.stream_generate_content({
59
59
  })
60
60
  ```
61
61
 
62
+ Google now supports a [global endpoint](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#global-endpoint):
63
+
64
+ ```ruby
65
+ Gemini.new(credentials: { region: 'global' })
66
+ ```
67
+
62
68
  Result:
63
69
  ```ruby
64
70
  [{ 'candidates' =>
@@ -88,11 +94,11 @@ Result:
88
94
  ### Installing
89
95
 
90
96
  ```sh
91
- gem install gemini-ai -v 4.1.0
97
+ gem install gemini-ai -v 4.3.0
92
98
  ```
93
99
 
94
100
  ```sh
95
- gem 'gemini-ai', '~> 4.1.0'
101
+ gem 'gemini-ai', '~> 4.3.0'
96
102
  ```
97
103
 
98
104
  ### Credentials
@@ -309,6 +315,14 @@ client = Gemini.new(
309
315
  )
310
316
  ```
311
317
 
318
+ ### Global Endpoint
319
+
320
+ Google now supports a [global endpoint](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#global-endpoint):
321
+
322
+ ```ruby
323
+ Gemini.new(credentials: { region: 'global' })
324
+ ```
325
+
312
326
  ## Available Models
313
327
 
314
328
  These models are accessible to the repository **author** as of June 2025 in the `us-east4` region. Access to models may vary by region, user, and account. All models here are expected to work, if you can access them. This is just a reference of what a "typical" user may expect to have access to right away:
@@ -942,6 +956,27 @@ Output:
942
956
  Meow! I'm Neko, a fluffy and playful cat. :3
943
957
  ```
944
958
 
959
+ ### Counting Tokens
960
+
961
+ You can [count tokens](https://ai.google.dev/gemini-api/docs/tokens#count-tokens) and preview how many tokens a request is expected to consume:
962
+
963
+ ```ruby
964
+ client.count_tokens(
965
+ { contents: { role: 'user', parts: { text: 'hi!' } } }
966
+ )
967
+ ```
968
+
969
+ Output for Generative Language API:
970
+ ```ruby
971
+ { 'totalTokens' => 3 }
972
+ ```
973
+
974
+ Output for Vertex AI API:
975
+
976
+ ```ruby
977
+ { 'totalTokens' => 2, 'totalBillableCharacters' => 3 }
978
+ ```
979
+
945
980
  ### JSON Format Responses
946
981
 
947
982
  > _As of the writing of this README, only the `vertex-ai-api` service and `gemini` models version `1.5` support this feature._
@@ -1369,7 +1404,7 @@ gem build gemini-ai.gemspec
1369
1404
 
1370
1405
  gem signin
1371
1406
 
1372
- gem push gemini-ai-4.1.0.gem
1407
+ gem push gemini-ai-4.3.0.gem
1373
1408
  ```
1374
1409
 
1375
1410
  ### 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: 4.1.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gbaptista
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-23 00:00:00.000000000 Z
11
+ date: 2025-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -30,20 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.9'
33
+ version: '2.13'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 2.9.2
36
+ version: 2.13.2
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.9'
43
+ version: '2.13'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 2.9.2
46
+ version: 2.13.2
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday-typhoeus
49
49
  requirement: !ruby/object:Gem::Requirement