gemini-ai 2.0.0 → 2.1.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: 790a1c353ecc9e3122fc096f674d50fbd0ef36b4b0f9ab56ef66d180b0a5d4de
4
- data.tar.gz: 2eac84cb99804362eea89063ea6ed66467af1ffb3a7d4ffd1ab186f7a2842157
3
+ metadata.gz: 3c6743cedf074b42aed890203de2d5db7697b6302c349c66bae9ac538bf2c680
4
+ data.tar.gz: ad0c8dd1ba69f58c0e37ed170bbd758231adea02245a63eb10fffa9a57fa2400
5
5
  SHA512:
6
- metadata.gz: d82d466e8272ab1919c153d3f68ffb3ab4ebd5a750a3822daef4394a814b36c08c0f114e691cb52a5c830a74a0e9d208cd3d4407227592812f0534655dc5afc1
7
- data.tar.gz: 7141a1bff79ea92aac09105b84fd9c2d5b68efe5184bf1ca0588dc420c0180ea65cd2fcca000ab0ea2cd00c1be188877f3f97ec6c7410f61bea4c8acf52b475c
6
+ metadata.gz: 558e2a13c12931f6bfbde1d625cb38b7779e08d8eb5bc0a845861902f50fbcbc43b64c67348220f35316b4a37504daa220c334b0479fb5493973bc49ab34e77c
7
+ data.tar.gz: 2df9f463de540a3d76f86252bd178ca5638caca7e172d59ea244f5f12d04c86d22dcbe2e219049a33ad318ffecc9aaff07c28ffe30aa69ebc109befa08acbcca
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ .devcontainer
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gemini-ai (2.0.0)
4
+ gemini-ai (2.1.0)
5
5
  event_stream_parser (~> 1.0)
6
6
  faraday (~> 2.7, >= 2.7.12)
7
7
  googleauth (~> 1.9, >= 1.9.1)
@@ -36,7 +36,7 @@ GEM
36
36
  method_source (1.0.0)
37
37
  multi_json (1.15.0)
38
38
  os (1.1.4)
39
- parallel (1.23.0)
39
+ parallel (1.24.0)
40
40
  parser (3.2.2.4)
41
41
  ast (~> 2.4.1)
42
42
  racc
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gemini AI
2
2
 
3
- A Ruby Gem for interacting with [Gemini](https://deepmind.google/technologies/gemini/) through [Vertex AI](https://cloud.google.com/vertex-ai) or [AI Studio](https://makersuite.google.com), Google's generative AI services.
3
+ A Ruby Gem for interacting with [Gemini](https://deepmind.google/technologies/gemini/) through [Vertex AI](https://cloud.google.com/vertex-ai), [Generative Language API](https://ai.google.dev/api/rest), or [AI Studio](https://makersuite.google.com), Google's generative AI services.
4
4
 
5
5
  ![The logo shows a gemstone split into red and blue halves, symbolizing Ruby programming and Gemini AI. It's surrounded by a circuit-like design on a dark blue backdrop.](https://raw.githubusercontent.com/gbaptista/assets/main/gemini-ai/ruby-gemini-ai.png)
6
6
 
@@ -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', '~> 2.0'
12
+ gem 'gemini-ai', '~> 2.1.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -24,12 +24,20 @@ client = Gemini.new(
24
24
  options: { model: 'gemini-pro', stream: false }
25
25
  )
26
26
 
27
- # With a Service Account
27
+ # With a Service Account Credentials File
28
28
  client = Gemini.new(
29
29
  credentials: {
30
30
  service: 'vertex-ai-api',
31
31
  file_path: 'google-credentials.json',
32
- project_id: 'PROJECT_ID',
32
+ region: 'us-east4'
33
+ },
34
+ options: { model: 'gemini-pro', stream: false }
35
+ )
36
+
37
+ # With Application Default Credentials
38
+ client = Gemini.new(
39
+ credentials: {
40
+ service: 'vertex-ai-api',
33
41
  region: 'us-east4'
34
42
  },
35
43
  options: { model: 'gemini-pro', stream: false }
@@ -67,8 +75,9 @@ Result:
67
75
  - [Setup](#setup)
68
76
  - [Installing](#installing)
69
77
  - [Credentials](#credentials)
70
- - [Option 1: API Key](#option-1-api-key)
71
- - [Option 2: Service Account](#option-2-service-account)
78
+ - [Option 1: API Key (Generative Language API)](#option-1-api-key-generative-language-api)
79
+ - [Option 2: Service Account Credentials File (Vertex AI API)](#option-2-service-account-credentials-file-vertex-ai-api)
80
+ - [Option 3: Application Default Credentials (Vertex AI API)](#option-3-application-default-credentials-vertex-ai-api)
72
81
  - [Required Data](#required-data)
73
82
  - [Usage](#usage)
74
83
  - [Client](#client)
@@ -91,18 +100,18 @@ Result:
91
100
  ### Installing
92
101
 
93
102
  ```sh
94
- gem install gemini-ai -v 2.0.0
103
+ gem install gemini-ai -v 2.1.0
95
104
  ```
96
105
 
97
106
  ```sh
98
- gem 'gemini-ai', '~> 2.0'
107
+ gem 'gemini-ai', '~> 2.1.0'
99
108
  ```
100
109
 
101
110
  ### Credentials
102
111
 
103
112
  > ⚠️ DISCLAIMER: Be careful with what you are doing, and never trust others' code related to this. These commands and instructions alter the level of access to your Google Cloud Account, and running them naively can lead to security risks as well as financial risks. People with access to your account can use it to steal data or incur charges. Run these commands at your own responsibility and due diligence; expect no warranties from the contributors of this project.
104
113
 
105
- #### Option 1: API Key
114
+ #### Option 1: API Key (Generative Language API)
106
115
 
107
116
  You need a [Google Cloud](https://console.cloud.google.com) [_Project_](https://cloud.google.com/resource-manager/docs/creating-managing-projects), and then you can generate an API Key through the Google Cloud Console [here](https://console.cloud.google.com/apis/credentials).
108
117
 
@@ -111,7 +120,7 @@ You also need to enable the _Generative Language API_ service in your Google Clo
111
120
 
112
121
  Alternatively, you can generate an API Key through _Google AI Studio_ [here](https://makersuite.google.com/app/apikey). However, this approach will automatically create a project for you in your Google Cloud Account.
113
122
 
114
- #### Option 2: Service Account
123
+ #### Option 2: Service Account Credentials File (Vertex AI API)
115
124
 
116
125
  You need a [Google Cloud](https://console.cloud.google.com) [_Project_](https://cloud.google.com/resource-manager/docs/creating-managing-projects) and a [_Service Account_](https://cloud.google.com/iam/docs/service-account-overview) to use [Vertex AI](https://cloud.google.com/vertex-ai) API.
117
126
 
@@ -165,11 +174,24 @@ gcloud projects add-iam-policy-binding PROJECT_ID \
165
174
  --role='roles/ml.admin'
166
175
  ```
167
176
 
177
+ #### Option 3: Application Default Credentials (Vertex AI API)
178
+
179
+ Similar to [Option 2](#option-2-service-account-credentials-file-vertex-ai-api), but you don't need to download a `google-credentials.json`. [_Application Default Credentials_](https://cloud.google.com/docs/authentication/application-default-credentials) automatically find credentials based on the application environment.
180
+
181
+ For local development, you can generate your default credentials using the [gcloud CLI](https://cloud.google.com/sdk/gcloud) as follows:
182
+
183
+ ```sh
184
+ gcloud auth application-default login
185
+ ```
186
+
187
+ For more details about alternative methods and different environments, check the official documentation:
188
+ [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc)
189
+
168
190
  #### Required Data
169
191
 
170
192
  After choosing an option, you should have all the necessary data and access to use Gemini.
171
193
 
172
- For API Key:
194
+ **Option 1**, for API Key:
173
195
 
174
196
  ```ruby
175
197
  {
@@ -187,13 +209,21 @@ Remember that hardcoding your API key in code is unsafe; it's preferable to use
187
209
  }
188
210
  ```
189
211
 
190
- Alternativelly, for Service Account, a `google-credentials.json` file, a `PROJECT_ID`, and a `REGION`:
212
+ **Option 2**: For the Service Account, provide a `google-credentials.json` file and a `REGION`:
191
213
 
192
214
  ```ruby
193
215
  {
194
216
  service: 'vertex-ai-api',
195
217
  file_path: 'google-credentials.json',
196
- project_id: 'PROJECT_ID',
218
+ region: 'us-east4'
219
+ }
220
+ ```
221
+
222
+ **Option 3**: For _Application Default Credentials_, omit both the `api_key` and the `file_path`:
223
+
224
+ ```ruby
225
+ {
226
+ service: 'vertex-ai-api',
197
227
  region: 'us-east4'
198
228
  }
199
229
  ```
@@ -212,6 +242,15 @@ Tokyo, Japan (asia-northeast1)
212
242
 
213
243
  You can follow here if new regions are available: [Gemini API](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini)
214
244
 
245
+ You might want to explicitly set a Google Cloud Project ID, which you can do as follows:
246
+
247
+ ```ruby
248
+ {
249
+ service: 'vertex-ai-api',
250
+ project_id: 'PROJECT_ID'
251
+ }
252
+ ```
253
+
215
254
  ## Usage
216
255
 
217
256
  ### Client
@@ -230,12 +269,20 @@ client = Gemini.new(
230
269
  options: { model: 'gemini-pro', stream: false }
231
270
  )
232
271
 
233
- # With a Service Account
272
+ # With a Service Account Credentials File
234
273
  client = Gemini.new(
235
274
  credentials: {
236
275
  service: 'vertex-ai-api',
237
276
  file_path: 'google-credentials.json',
238
- project_id: 'PROJECT_ID',
277
+ region: 'us-east4'
278
+ },
279
+ options: { model: 'gemini-pro', stream: false }
280
+ )
281
+
282
+ # With Application Default Credentials
283
+ client = Gemini.new(
284
+ credentials: {
285
+ service: 'vertex-ai-api',
239
286
  region: 'us-east4'
240
287
  },
241
288
  options: { model: 'gemini-pro', stream: false }
@@ -395,7 +442,7 @@ Result:
395
442
 
396
443
  ### Tools (Functions) Calling
397
444
 
398
- > As of the writing of this README, only the `gemini-pro` model [supports](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling#supported_models) tools (functions) calls.
445
+ > As of the writing of this README, only the `vertex-ai-api` service and the `gemini-pro` model [supports](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling#supported_models) tools (functions) calls.
399
446
 
400
447
  You can provide specifications for [tools (functions)](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling) using [JSON Schema](https://json-schema.org) to generate potential calls to them:
401
448
 
@@ -567,7 +614,7 @@ gem build gemini-ai.gemspec
567
614
 
568
615
  gem signin
569
616
 
570
- gem push gemini-ai-2.0.0.gem
617
+ gem push gemini-ai-2.1.0.gem
571
618
  ```
572
619
 
573
620
  ### Updating the README
@@ -12,17 +12,30 @@ module Gemini
12
12
  if config[:credentials][:api_key]
13
13
  @authentication = :api_key
14
14
  @api_key = config[:credentials][:api_key]
15
- else
15
+ elsif config[:credentials][:file_path]
16
16
  @authentication = :service_account
17
17
  @authorizer = ::Google::Auth::ServiceAccountCredentials.make_creds(
18
18
  json_key_io: File.open(config[:credentials][:file_path]),
19
19
  scope: 'https://www.googleapis.com/auth/cloud-platform'
20
20
  )
21
+ else
22
+ @authentication = :default_credentials
23
+ @authorizer = ::Google::Auth.get_application_default
24
+ end
25
+
26
+ if @authentication == :service_account || @authentication == :default_credentials
27
+ @project_id = if config[:credentials][:project_id].nil?
28
+ @authorizer.project_id || @authorizer.quota_project_id
29
+ else
30
+ config[:credentials][:project_id]
31
+ end
32
+
33
+ raise StandardError, 'Could not determine project_id, which is required.' if @project_id.nil?
21
34
  end
22
35
 
23
36
  @address = case config[:credentials][:service]
24
37
  when 'vertex-ai-api'
25
- "https://#{config[:credentials][:region]}-aiplatform.googleapis.com/v1/projects/#{config[:credentials][:project_id]}/locations/#{config[:credentials][:region]}/publishers/google/models/#{config[:options][:model]}"
38
+ "https://#{config[:credentials][:region]}-aiplatform.googleapis.com/v1/projects/#{@project_id}/locations/#{config[:credentials][:region]}/publishers/google/models/#{config[:options][:model]}"
26
39
  when 'generative-language-api'
27
40
  "https://generativelanguage.googleapis.com/v1/models/#{config[:options][:model]}"
28
41
  else
@@ -55,7 +68,7 @@ module Gemini
55
68
  response = Faraday.new.post do |request|
56
69
  request.url url
57
70
  request.headers['Content-Type'] = 'application/json'
58
- if @authentication == :service_account
71
+ if @authentication == :service_account || @authentication == :default_credentials
59
72
  request.headers['Authorization'] = "Bearer #{@authorizer.fetch_access_token!['access_token']}"
60
73
  end
61
74
 
data/static/gem.rb CHANGED
@@ -3,10 +3,10 @@
3
3
  module Gemini
4
4
  GEM = {
5
5
  name: 'gemini-ai',
6
- version: '2.0.0',
6
+ version: '2.1.0',
7
7
  author: 'gbaptista',
8
8
  summary: "Interact with Google's Gemini AI.",
9
- description: "A Ruby Gem for interacting with Gemini through Vertex AI or AI Studio, Google's generative AI services.",
9
+ description: "A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.",
10
10
  github: 'https://github.com/gbaptista/gemini-ai',
11
11
  gem_server: 'https://rubygems.org',
12
12
  license: 'MIT',
data/template.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gemini AI
2
2
 
3
- A Ruby Gem for interacting with [Gemini](https://deepmind.google/technologies/gemini/) through [Vertex AI](https://cloud.google.com/vertex-ai) or [AI Studio](https://makersuite.google.com), Google's generative AI services.
3
+ A Ruby Gem for interacting with [Gemini](https://deepmind.google/technologies/gemini/) through [Vertex AI](https://cloud.google.com/vertex-ai), [Generative Language API](https://ai.google.dev/api/rest), or [AI Studio](https://makersuite.google.com), Google's generative AI services.
4
4
 
5
5
  ![The logo shows a gemstone split into red and blue halves, symbolizing Ruby programming and Gemini AI. It's surrounded by a circuit-like design on a dark blue backdrop.](https://raw.githubusercontent.com/gbaptista/assets/main/gemini-ai/ruby-gemini-ai.png)
6
6
 
@@ -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', '~> 2.0'
12
+ gem 'gemini-ai', '~> 2.1.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -24,12 +24,20 @@ client = Gemini.new(
24
24
  options: { model: 'gemini-pro', stream: false }
25
25
  )
26
26
 
27
- # With a Service Account
27
+ # With a Service Account Credentials File
28
28
  client = Gemini.new(
29
29
  credentials: {
30
30
  service: 'vertex-ai-api',
31
31
  file_path: 'google-credentials.json',
32
- project_id: 'PROJECT_ID',
32
+ region: 'us-east4'
33
+ },
34
+ options: { model: 'gemini-pro', stream: false }
35
+ )
36
+
37
+ # With Application Default Credentials
38
+ client = Gemini.new(
39
+ credentials: {
40
+ service: 'vertex-ai-api',
33
41
  region: 'us-east4'
34
42
  },
35
43
  options: { model: 'gemini-pro', stream: false }
@@ -69,18 +77,18 @@ Result:
69
77
  ### Installing
70
78
 
71
79
  ```sh
72
- gem install gemini-ai -v 2.0.0
80
+ gem install gemini-ai -v 2.1.0
73
81
  ```
74
82
 
75
83
  ```sh
76
- gem 'gemini-ai', '~> 2.0'
84
+ gem 'gemini-ai', '~> 2.1.0'
77
85
  ```
78
86
 
79
87
  ### Credentials
80
88
 
81
89
  > ⚠️ DISCLAIMER: Be careful with what you are doing, and never trust others' code related to this. These commands and instructions alter the level of access to your Google Cloud Account, and running them naively can lead to security risks as well as financial risks. People with access to your account can use it to steal data or incur charges. Run these commands at your own responsibility and due diligence; expect no warranties from the contributors of this project.
82
90
 
83
- #### Option 1: API Key
91
+ #### Option 1: API Key (Generative Language API)
84
92
 
85
93
  You need a [Google Cloud](https://console.cloud.google.com) [_Project_](https://cloud.google.com/resource-manager/docs/creating-managing-projects), and then you can generate an API Key through the Google Cloud Console [here](https://console.cloud.google.com/apis/credentials).
86
94
 
@@ -89,7 +97,7 @@ You also need to enable the _Generative Language API_ service in your Google Clo
89
97
 
90
98
  Alternatively, you can generate an API Key through _Google AI Studio_ [here](https://makersuite.google.com/app/apikey). However, this approach will automatically create a project for you in your Google Cloud Account.
91
99
 
92
- #### Option 2: Service Account
100
+ #### Option 2: Service Account Credentials File (Vertex AI API)
93
101
 
94
102
  You need a [Google Cloud](https://console.cloud.google.com) [_Project_](https://cloud.google.com/resource-manager/docs/creating-managing-projects) and a [_Service Account_](https://cloud.google.com/iam/docs/service-account-overview) to use [Vertex AI](https://cloud.google.com/vertex-ai) API.
95
103
 
@@ -143,11 +151,24 @@ gcloud projects add-iam-policy-binding PROJECT_ID \
143
151
  --role='roles/ml.admin'
144
152
  ```
145
153
 
154
+ #### Option 3: Application Default Credentials (Vertex AI API)
155
+
156
+ Similar to [Option 2](#option-2-service-account-credentials-file-vertex-ai-api), but you don't need to download a `google-credentials.json`. [_Application Default Credentials_](https://cloud.google.com/docs/authentication/application-default-credentials) automatically find credentials based on the application environment.
157
+
158
+ For local development, you can generate your default credentials using the [gcloud CLI](https://cloud.google.com/sdk/gcloud) as follows:
159
+
160
+ ```sh
161
+ gcloud auth application-default login
162
+ ```
163
+
164
+ For more details about alternative methods and different environments, check the official documentation:
165
+ [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc)
166
+
146
167
  #### Required Data
147
168
 
148
169
  After choosing an option, you should have all the necessary data and access to use Gemini.
149
170
 
150
- For API Key:
171
+ **Option 1**, for API Key:
151
172
 
152
173
  ```ruby
153
174
  {
@@ -165,13 +186,21 @@ Remember that hardcoding your API key in code is unsafe; it's preferable to use
165
186
  }
166
187
  ```
167
188
 
168
- Alternativelly, for Service Account, a `google-credentials.json` file, a `PROJECT_ID`, and a `REGION`:
189
+ **Option 2**: For the Service Account, provide a `google-credentials.json` file and a `REGION`:
169
190
 
170
191
  ```ruby
171
192
  {
172
193
  service: 'vertex-ai-api',
173
194
  file_path: 'google-credentials.json',
174
- project_id: 'PROJECT_ID',
195
+ region: 'us-east4'
196
+ }
197
+ ```
198
+
199
+ **Option 3**: For _Application Default Credentials_, omit both the `api_key` and the `file_path`:
200
+
201
+ ```ruby
202
+ {
203
+ service: 'vertex-ai-api',
175
204
  region: 'us-east4'
176
205
  }
177
206
  ```
@@ -190,6 +219,15 @@ Tokyo, Japan (asia-northeast1)
190
219
 
191
220
  You can follow here if new regions are available: [Gemini API](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini)
192
221
 
222
+ You might want to explicitly set a Google Cloud Project ID, which you can do as follows:
223
+
224
+ ```ruby
225
+ {
226
+ service: 'vertex-ai-api',
227
+ project_id: 'PROJECT_ID'
228
+ }
229
+ ```
230
+
193
231
  ## Usage
194
232
 
195
233
  ### Client
@@ -208,12 +246,20 @@ client = Gemini.new(
208
246
  options: { model: 'gemini-pro', stream: false }
209
247
  )
210
248
 
211
- # With a Service Account
249
+ # With a Service Account Credentials File
212
250
  client = Gemini.new(
213
251
  credentials: {
214
252
  service: 'vertex-ai-api',
215
253
  file_path: 'google-credentials.json',
216
- project_id: 'PROJECT_ID',
254
+ region: 'us-east4'
255
+ },
256
+ options: { model: 'gemini-pro', stream: false }
257
+ )
258
+
259
+ # With Application Default Credentials
260
+ client = Gemini.new(
261
+ credentials: {
262
+ service: 'vertex-ai-api',
217
263
  region: 'us-east4'
218
264
  },
219
265
  options: { model: 'gemini-pro', stream: false }
@@ -373,7 +419,7 @@ Result:
373
419
 
374
420
  ### Tools (Functions) Calling
375
421
 
376
- > As of the writing of this README, only the `gemini-pro` model [supports](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling#supported_models) tools (functions) calls.
422
+ > As of the writing of this README, only the `vertex-ai-api` service and the `gemini-pro` model [supports](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling#supported_models) tools (functions) calls.
377
423
 
378
424
  You can provide specifications for [tools (functions)](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling) using [JSON Schema](https://json-schema.org) to generate potential calls to them:
379
425
 
@@ -545,7 +591,7 @@ gem build gemini-ai.gemspec
545
591
 
546
592
  gem signin
547
593
 
548
- gem push gemini-ai-2.0.0.gem
594
+ gem push gemini-ai-2.1.0.gem
549
595
  ```
550
596
 
551
597
  ### 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: 2.0.0
4
+ version: 2.1.0
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-15 00:00:00.000000000 Z
11
+ date: 2023-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -64,8 +64,8 @@ dependencies:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: 1.9.1
67
- description: A Ruby Gem for interacting with Gemini through Vertex AI or AI Studio,
68
- Google's generative AI services.
67
+ description: A Ruby Gem for interacting with Gemini through Vertex AI, Generative
68
+ Language API, or AI Studio, Google's generative AI services.
69
69
  email:
70
70
  executables: []
71
71
  extensions: []