gemini-ai 4.1.0 → 4.2.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: 7fa034b81983b8925267cdc2bb4cbf6170b7d5ecccfb26a705d70a1643f1e7ad
4
+ data.tar.gz: 077eec4e066836c80d8e0d6e26940086588876548f8d0e38b01a0a89aaf74646
5
5
  SHA512:
6
- metadata.gz: ee6e3a097d57d1a4f81d74bcec541a03aa23e1829d36b0296817345da6503fc1a198baad7e333e68996654f586ddc822704572159c297afe05e41ba687e2bba3
7
- data.tar.gz: 55eae644861d7c4a45ab2551357e17c44b4490f0d73b706adeb26b12a1931f65db77a5ca64b589b2447367404fea7951cc15710ba12ce2b4561a7b12f84fc05e
6
+ metadata.gz: e2be4160caa66645c8baa9519f69059caa36e4c699098e2138e713736d1f7a1aaba27d6ca9a62ba64ee350e313cea5c0bee27eaf9685f576a33527c0f837d563
7
+ data.tar.gz: f4561c6e6cef7cfc3daa6e2c8c534d03624993cfbce3f9a75ae4eff55b081de694aa30d261c891eaf0acf463b3fd883b48317d142856131fc8253957d0ef9ef5
data/Gemfile CHANGED
@@ -8,6 +8,6 @@ group :test, :development do
8
8
  gem 'dotenv', '~> 3.1', '>= 3.1.2'
9
9
  gem 'pry-byebug', '~> 3.10', '>= 3.10.1'
10
10
  gem 'rspec', '~> 3.13'
11
- gem 'rubocop', '~> 1.64', '>= 1.64.1'
12
- gem 'rubocop-rspec', '~> 3.0', '>= 3.0.1'
11
+ gem 'rubocop', '~> 1.65'
12
+ gem 'rubocop-rspec', '~> 3.0', '>= 3.0.3'
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.2.0)
5
5
  event_stream_parser (~> 1.0)
6
- faraday (~> 2.9, >= 2.9.2)
6
+ faraday (~> 2.10)
7
7
  faraday-typhoeus (~> 1.1)
8
8
  googleauth (~> 1.8)
9
9
  typhoeus (~> 1.4, >= 1.4.1)
@@ -22,8 +22,9 @@ GEM
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)
25
+ faraday (2.10.0)
26
26
  faraday-net_http (>= 2.0, < 3.2)
27
+ logger
27
28
  faraday-net_http (3.1.0)
28
29
  net-http
29
30
  faraday-typhoeus (1.1.0)
@@ -43,13 +44,14 @@ GEM
43
44
  jwt (2.8.2)
44
45
  base64
45
46
  language_server-protocol (3.17.0.3)
47
+ logger (1.6.0)
46
48
  method_source (1.1.0)
47
49
  multi_json (1.15.0)
48
50
  net-http (0.4.1)
49
51
  uri
50
52
  os (1.1.4)
51
53
  parallel (1.25.1)
52
- parser (3.3.3.0)
54
+ parser (3.3.4.0)
53
55
  ast (~> 2.4.1)
54
56
  racc
55
57
  pry (0.14.2)
@@ -62,7 +64,7 @@ GEM
62
64
  racc (1.8.0)
63
65
  rainbow (3.1.1)
64
66
  regexp_parser (2.9.2)
65
- rexml (3.3.0)
67
+ rexml (3.3.2)
66
68
  strscan
67
69
  rspec (3.13.0)
68
70
  rspec-core (~> 3.13.0)
@@ -77,20 +79,20 @@ GEM
77
79
  diff-lcs (>= 1.2.0, < 2.0)
78
80
  rspec-support (~> 3.13.0)
79
81
  rspec-support (3.13.1)
80
- rubocop (1.64.1)
82
+ rubocop (1.65.0)
81
83
  json (~> 2.3)
82
84
  language_server-protocol (>= 3.17.0)
83
85
  parallel (~> 1.10)
84
86
  parser (>= 3.3.0.2)
85
87
  rainbow (>= 2.2.2, < 4.0)
86
- regexp_parser (>= 1.8, < 3.0)
88
+ regexp_parser (>= 2.4, < 3.0)
87
89
  rexml (>= 3.2.5, < 4.0)
88
90
  rubocop-ast (>= 1.31.1, < 2.0)
89
91
  ruby-progressbar (~> 1.7)
90
92
  unicode-display_width (>= 2.4.0, < 3.0)
91
93
  rubocop-ast (1.31.3)
92
94
  parser (>= 3.3.1.0)
93
- rubocop-rspec (3.0.1)
95
+ rubocop-rspec (3.0.3)
94
96
  rubocop (~> 1.61)
95
97
  ruby-progressbar (1.13.0)
96
98
  signet (0.19.0)
@@ -112,8 +114,8 @@ DEPENDENCIES
112
114
  gemini-ai!
113
115
  pry-byebug (~> 3.10, >= 3.10.1)
114
116
  rspec (~> 3.13)
115
- rubocop (~> 1.64, >= 1.64.1)
116
- rubocop-rspec (~> 3.0, >= 3.0.1)
117
+ rubocop (~> 1.65)
118
+ rubocop-rspec (~> 3.0, >= 3.0.3)
117
119
 
118
120
  BUNDLED WITH
119
121
  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.2.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -113,6 +113,7 @@ Result:
113
113
  - [Back-and-Forth Conversations](#back-and-forth-conversations)
114
114
  - [Safety Settings](#safety-settings)
115
115
  - [System Instructions](#system-instructions)
116
+ - [Counting Tokens](#counting-tokens)
116
117
  - [JSON Format Responses](#json-format-responses)
117
118
  - [JSON Schema](#json-schema)
118
119
  - [Models That Support JSON](#models-that-support-json)
@@ -137,11 +138,11 @@ Result:
137
138
  ### Installing
138
139
 
139
140
  ```sh
140
- gem install gemini-ai -v 4.1.0
141
+ gem install gemini-ai -v 4.2.0
141
142
  ```
142
143
 
143
144
  ```sh
144
- gem 'gemini-ai', '~> 4.1.0'
145
+ gem 'gemini-ai', '~> 4.2.0'
145
146
  ```
146
147
 
147
148
  ### Credentials
@@ -991,6 +992,27 @@ Output:
991
992
  Meow! I'm Neko, a fluffy and playful cat. :3
992
993
  ```
993
994
 
995
+ ### Counting Tokens
996
+
997
+ 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:
998
+
999
+ ```ruby
1000
+ client.count_tokens(
1001
+ { contents: { role: 'user', parts: { text: 'hi!' } } }
1002
+ )
1003
+ ```
1004
+
1005
+ Output for Generative Language API:
1006
+ ```ruby
1007
+ { 'totalTokens' => 3 }
1008
+ ```
1009
+
1010
+ Output for Vertex AI API:
1011
+
1012
+ ```ruby
1013
+ { 'totalTokens' => 2, 'totalBillableCharacters' => 3 }
1014
+ ```
1015
+
994
1016
  ### JSON Format Responses
995
1017
 
996
1018
  > _As of the writing of this README, only the `vertex-ai-api` service and `gemini` models version `1.5` support this feature._
@@ -1418,7 +1440,7 @@ gem build gemini-ai.gemspec
1418
1440
 
1419
1441
  gem signin
1420
1442
 
1421
- gem push gemini-ai-4.1.0.gem
1443
+ gem push gemini-ai-4.2.0.gem
1422
1444
  ```
1423
1445
 
1424
1446
  ### Updating the README
@@ -109,6 +109,17 @@ module Gemini
109
109
  result
110
110
  end
111
111
 
112
+ def count_tokens(payload, server_sent_events: nil, &callback)
113
+ result = request(
114
+ "#{@model_address}:countTokens", payload,
115
+ server_sent_events:, &callback
116
+ )
117
+
118
+ return result.first if result.is_a?(Array) && result.size == 1
119
+
120
+ result
121
+ end
122
+
112
123
  def embed_content(payload, server_sent_events: nil, &callback)
113
124
  result = request(
114
125
  "#{@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.10'
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.2.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.2.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -88,11 +88,11 @@ Result:
88
88
  ### Installing
89
89
 
90
90
  ```sh
91
- gem install gemini-ai -v 4.1.0
91
+ gem install gemini-ai -v 4.2.0
92
92
  ```
93
93
 
94
94
  ```sh
95
- gem 'gemini-ai', '~> 4.1.0'
95
+ gem 'gemini-ai', '~> 4.2.0'
96
96
  ```
97
97
 
98
98
  ### Credentials
@@ -942,6 +942,27 @@ Output:
942
942
  Meow! I'm Neko, a fluffy and playful cat. :3
943
943
  ```
944
944
 
945
+ ### Counting Tokens
946
+
947
+ 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:
948
+
949
+ ```ruby
950
+ client.count_tokens(
951
+ { contents: { role: 'user', parts: { text: 'hi!' } } }
952
+ )
953
+ ```
954
+
955
+ Output for Generative Language API:
956
+ ```ruby
957
+ { 'totalTokens' => 3 }
958
+ ```
959
+
960
+ Output for Vertex AI API:
961
+
962
+ ```ruby
963
+ { 'totalTokens' => 2, 'totalBillableCharacters' => 3 }
964
+ ```
965
+
945
966
  ### JSON Format Responses
946
967
 
947
968
  > _As of the writing of this README, only the `vertex-ai-api` service and `gemini` models version `1.5` support this feature._
@@ -1369,7 +1390,7 @@ gem build gemini-ai.gemspec
1369
1390
 
1370
1391
  gem signin
1371
1392
 
1372
- gem push gemini-ai-4.1.0.gem
1393
+ gem push gemini-ai-4.2.0.gem
1373
1394
  ```
1374
1395
 
1375
1396
  ### 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.2.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: 2024-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.9'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.9.2
33
+ version: '2.10'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '2.9'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.9.2
40
+ version: '2.10'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: faraday-typhoeus
49
43
  requirement: !ruby/object:Gem::Requirement