google-genai 1.4.0__tar.gz → 1.6.0__tar.gz

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.
Files changed (34) hide show
  1. {google_genai-1.4.0 → google_genai-1.6.0}/PKG-INFO +194 -24
  2. google_genai-1.4.0/google_genai.egg-info/PKG-INFO → google_genai-1.6.0/README.md +186 -46
  3. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_api_client.py +207 -111
  4. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_automatic_function_calling_util.py +6 -16
  5. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_common.py +5 -2
  6. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_extra_utils.py +62 -47
  7. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_replay_api_client.py +70 -2
  8. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_transformers.py +98 -57
  9. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/batches.py +14 -10
  10. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/caches.py +30 -36
  11. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/client.py +3 -2
  12. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/errors.py +11 -19
  13. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/files.py +28 -15
  14. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/live.py +276 -93
  15. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/models.py +201 -112
  16. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/operations.py +40 -12
  17. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/pagers.py +17 -10
  18. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/tunings.py +40 -30
  19. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/types.py +146 -58
  20. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/version.py +1 -1
  21. google_genai-1.4.0/README.md → google_genai-1.6.0/google_genai.egg-info/PKG-INFO +216 -17
  22. google_genai-1.6.0/google_genai.egg-info/requires.txt +7 -0
  23. {google_genai-1.4.0 → google_genai-1.6.0}/pyproject.toml +8 -7
  24. google_genai-1.4.0/google_genai.egg-info/requires.txt +0 -6
  25. {google_genai-1.4.0 → google_genai-1.6.0}/LICENSE +0 -0
  26. {google_genai-1.4.0 → google_genai-1.6.0}/MANIFEST.in +0 -0
  27. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/__init__.py +0 -0
  28. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_api_module.py +0 -0
  29. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/_test_api_client.py +0 -0
  30. {google_genai-1.4.0 → google_genai-1.6.0}/google/genai/chats.py +0 -0
  31. {google_genai-1.4.0 → google_genai-1.6.0}/google_genai.egg-info/SOURCES.txt +0 -0
  32. {google_genai-1.4.0 → google_genai-1.6.0}/google_genai.egg-info/dependency_links.txt +0 -0
  33. {google_genai-1.4.0 → google_genai-1.6.0}/google_genai.egg-info/top_level.txt +0 -0
  34. {google_genai-1.4.0 → google_genai-1.6.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: google-genai
3
- Version: 1.4.0
3
+ Version: 1.6.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -20,12 +20,13 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
20
  Requires-Python: >=3.9
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: google-auth<3.0.0dev,>=2.14.1
24
- Requires-Dist: httpx<1.0.0dev,>=0.28.1
25
- Requires-Dist: pydantic<3.0.0dev,>=2.0.0
26
- Requires-Dist: requests<3.0.0dev,>=2.28.1
27
- Requires-Dist: websockets<15.0dev,>=13.0
28
- Requires-Dist: typing-extensions<5.0.0dev,>=4.11.0
23
+ Requires-Dist: anyio<5.0.0,>=4.8.0
24
+ Requires-Dist: google-auth<3.0.0,>=2.14.1
25
+ Requires-Dist: httpx<1.0.0,>=0.28.1
26
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
27
+ Requires-Dist: requests<3.0.0,>=2.28.1
28
+ Requires-Dist: websockets<15.0.0,>=13.0.0
29
+ Requires-Dist: typing-extensions<5.0.0,>=4.11.0
29
30
 
30
31
  # Google Gen AI SDK
31
32
 
@@ -159,37 +160,202 @@ response = client.models.generate_content(
159
160
  print(response.text)
160
161
  ```
161
162
 
162
- #### How to structure `contents`
163
- There are several ways to structure the `contents` in your request.
163
+ #### How to structure `contents` argument for `generate_content`
164
+ The SDK always converts the inputs to the `contents` argument into
165
+ `list[types.Content]`.
166
+ The following shows some common ways to provide your inputs.
164
167
 
165
- Provide a single string as shown in the text example above:
168
+ ##### Provide a `list[types.Content]`
169
+ This is the canonical way to provide contents, SDK will not do any conversion.
170
+
171
+ ##### Provide a `types.Content` instance
172
+
173
+ ```python
174
+ contents = types.Content(
175
+ role='user',
176
+ parts=[types.Part.from_text(text='Why is the sky blue?')]
177
+ )
178
+ ```
179
+
180
+ SDK converts this to
181
+
182
+ ```python
183
+ [
184
+ types.Content(
185
+ role='user',
186
+ parts=[types.Part.from_text(text='Why is the sky blue?')]
187
+ )
188
+ ]
189
+ ```
190
+
191
+ ##### Provide a string
192
+
193
+ ```python
194
+ contents='Why is the sky blue?'
195
+ ```
196
+
197
+ The SDK will assume this is a text part, and it converts this into the following:
198
+
199
+ ```python
200
+ [
201
+ types.UserContent(
202
+ parts=[
203
+ types.Part.from_text(text='Why is the sky blue?')
204
+ ]
205
+ )
206
+ ]
207
+ ```
208
+
209
+ Where a `types.UserContent` is a subclass of `types.Content`, it sets the
210
+ `role` field to be `user`.
211
+
212
+ ##### Provide a list of string
213
+
214
+ ```python
215
+ contents=['Why is the sky blue?', 'Why is the cloud white?']
216
+ ```
217
+
218
+ The SDK assumes these are 2 text parts, it converts this into a single content,
219
+ like the following:
220
+
221
+ ```python
222
+ [
223
+ types.UserContent(
224
+ parts=[
225
+ types.Part.from_text(text='Why is the sky blue?'),
226
+ types.Part.from_text(text='Why is the cloud white?'),
227
+ ]
228
+ )
229
+ ]
230
+ ```
231
+
232
+ Where a `types.UserContent` is a subclass of `types.Content`, the
233
+ `role` field in `types.UserContent` is fixed to be `user`.
234
+
235
+ ##### Provide a function call part
236
+
237
+ ```python
238
+ contents = types.Part.from_function_call(
239
+ name='get_weather_by_location',
240
+ args={'location': 'Boston'}
241
+ )
242
+ ```
243
+
244
+ The SDK converts a function call part to a content with a `model` role:
245
+
246
+ ```python
247
+ [
248
+ types.ModelContent(
249
+ parts=[
250
+ types.Part.from_function_call(
251
+ name='get_weather_by_location',
252
+ args={'location': 'Boston'}
253
+ )
254
+ ]
255
+ )
256
+ ]
257
+ ```
258
+
259
+ Where a `types.ModelContent` is a subclass of `types.Content`, the
260
+ `role` field in `types.ModelContent` is fixed to be `model`.
261
+
262
+ ##### Provide a list of function call parts
166
263
 
167
264
  ```python
168
- contents='Can you recommend some things to do in Boston and New York in the winter?'
265
+ contents = [
266
+ types.Part.from_function_call(
267
+ name='get_weather_by_location',
268
+ args={'location': 'Boston'}
269
+ ),
270
+ types.Part.from_function_call(
271
+ name='get_weather_by_location',
272
+ args={'location': 'New York'}
273
+ ),
274
+ ]
275
+ ```
276
+
277
+ The SDK converts a list of function call parts to the a content with a `model` role:
278
+
279
+ ```python
280
+ [
281
+ types.ModelContent(
282
+ parts=[
283
+ types.Part.from_function_call(
284
+ name='get_weather_by_location',
285
+ args={'location': 'Boston'}
286
+ ),
287
+ types.Part.from_function_call(
288
+ name='get_weather_by_location',
289
+ args={'location': 'New York'}
290
+ )
291
+ ]
292
+ )
293
+ ]
169
294
  ```
170
295
 
171
- Provide a single `Content` instance with multiple `Part` instances:
296
+ Where a `types.ModelContent` is a subclass of `types.Content`, the
297
+ `role` field in `types.ModelContent` is fixed to be `model`.
298
+
299
+ ##### Provide a non function call part
172
300
 
173
301
  ```python
174
- contents=types.Content(parts=[
175
- types.Part.from_text(text='Can you recommend some things to do in Boston in the winter?'),
176
- types.Part.from_text(text='Can you recommend some things to do in New York in the winter?')
177
- ], role='user')
302
+ contents = types.Part.from_uri(
303
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
304
+ mime_type: 'image/jpeg',
305
+ )
178
306
  ```
179
307
 
180
- When sending more than one input type, provide a list with multiple `Content`
181
- instances:
308
+ The SDK converts all non function call parts into a content with a `user` role.
182
309
 
183
310
  ```python
184
- contents=[
185
- 'What is this a picture of?',
311
+ [
312
+ types.UserContent(parts=[
186
313
  types.Part.from_uri(
187
- file_uri='gs://generativeai-downloads/images/scones.jpg',
188
- mime_type='image/jpeg',
189
- ),
190
- ],
314
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
315
+ mime_type: 'image/jpeg',
316
+ )
317
+ ])
318
+ ]
319
+ ```
320
+
321
+ ##### Provide a list of non function call parts
322
+
323
+ ```python
324
+ contents = [
325
+ types.Part.from_text('What is this image about?'),
326
+ types.Part.from_uri(
327
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
328
+ mime_type: 'image/jpeg',
329
+ )
330
+ ]
191
331
  ```
192
332
 
333
+ The SDK will convert the list of parts into a content with a `user` role
334
+
335
+ ```python
336
+ [
337
+ types.UserContent(
338
+ parts=[
339
+ types.Part.from_text('What is this image about?'),
340
+ types.Part.from_uri(
341
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
342
+ mime_type: 'image/jpeg',
343
+ )
344
+ ]
345
+ )
346
+ ]
347
+ ```
348
+
349
+ ##### Mix types in contents
350
+ You can also provide a list of `types.ContentUnion`. The SDK leaves items of
351
+ `types.Content` as is, it groups consecutive non function call parts into a
352
+ single `types.UserContent`, and it groups consecutive function call parts into
353
+ a single `types.ModelContent`.
354
+
355
+ If you put a list within a list, the inner list can only contain
356
+ `types.PartUnion` items. The SDK will convert the inner list into a single
357
+ `types.UserContent`.
358
+
193
359
  ### System Instructions and Other Configs
194
360
 
195
361
  The output of the model can be influenced by several optional settings
@@ -480,6 +646,10 @@ response = client.models.generate_content(
480
646
  ```
481
647
  ### JSON Response Schema
482
648
 
649
+ However you define your schema, don't duplicate it in your input prompt,
650
+ including by giving examples of expected JSON output. If you do, the generated
651
+ output might be lower in quality.
652
+
483
653
  #### Pydantic Model Schema support
484
654
 
485
655
  Schemas can be provided as Pydantic Models.
@@ -1,32 +1,3 @@
1
- Metadata-Version: 2.2
2
- Name: google-genai
3
- Version: 1.4.0
4
- Summary: GenAI Python SDK
5
- Author-email: Google LLC <googleapis-packages@google.com>
6
- License: Apache-2.0
7
- Project-URL: Homepage, https://github.com/googleapis/python-genai
8
- Classifier: Intended Audience :: Developers
9
- Classifier: License :: OSI Approved :: Apache Software License
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Programming Language :: Python
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Programming Language :: Python :: 3.13
18
- Classifier: Topic :: Internet
19
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
- Requires-Python: >=3.9
21
- Description-Content-Type: text/markdown
22
- License-File: LICENSE
23
- Requires-Dist: google-auth<3.0.0dev,>=2.14.1
24
- Requires-Dist: httpx<1.0.0dev,>=0.28.1
25
- Requires-Dist: pydantic<3.0.0dev,>=2.0.0
26
- Requires-Dist: requests<3.0.0dev,>=2.28.1
27
- Requires-Dist: websockets<15.0dev,>=13.0
28
- Requires-Dist: typing-extensions<5.0.0dev,>=4.11.0
29
-
30
1
  # Google Gen AI SDK
31
2
 
32
3
  [![PyPI version](https://img.shields.io/pypi/v/google-genai.svg)](https://pypi.org/project/google-genai/)
@@ -159,37 +130,202 @@ response = client.models.generate_content(
159
130
  print(response.text)
160
131
  ```
161
132
 
162
- #### How to structure `contents`
163
- There are several ways to structure the `contents` in your request.
133
+ #### How to structure `contents` argument for `generate_content`
134
+ The SDK always converts the inputs to the `contents` argument into
135
+ `list[types.Content]`.
136
+ The following shows some common ways to provide your inputs.
137
+
138
+ ##### Provide a `list[types.Content]`
139
+ This is the canonical way to provide contents, SDK will not do any conversion.
140
+
141
+ ##### Provide a `types.Content` instance
142
+
143
+ ```python
144
+ contents = types.Content(
145
+ role='user',
146
+ parts=[types.Part.from_text(text='Why is the sky blue?')]
147
+ )
148
+ ```
164
149
 
165
- Provide a single string as shown in the text example above:
150
+ SDK converts this to
166
151
 
167
152
  ```python
168
- contents='Can you recommend some things to do in Boston and New York in the winter?'
153
+ [
154
+ types.Content(
155
+ role='user',
156
+ parts=[types.Part.from_text(text='Why is the sky blue?')]
157
+ )
158
+ ]
169
159
  ```
170
160
 
171
- Provide a single `Content` instance with multiple `Part` instances:
161
+ ##### Provide a string
172
162
 
173
163
  ```python
174
- contents=types.Content(parts=[
175
- types.Part.from_text(text='Can you recommend some things to do in Boston in the winter?'),
176
- types.Part.from_text(text='Can you recommend some things to do in New York in the winter?')
177
- ], role='user')
164
+ contents='Why is the sky blue?'
178
165
  ```
179
166
 
180
- When sending more than one input type, provide a list with multiple `Content`
181
- instances:
167
+ The SDK will assume this is a text part, and it converts this into the following:
182
168
 
183
169
  ```python
184
- contents=[
185
- 'What is this a picture of?',
170
+ [
171
+ types.UserContent(
172
+ parts=[
173
+ types.Part.from_text(text='Why is the sky blue?')
174
+ ]
175
+ )
176
+ ]
177
+ ```
178
+
179
+ Where a `types.UserContent` is a subclass of `types.Content`, it sets the
180
+ `role` field to be `user`.
181
+
182
+ ##### Provide a list of string
183
+
184
+ ```python
185
+ contents=['Why is the sky blue?', 'Why is the cloud white?']
186
+ ```
187
+
188
+ The SDK assumes these are 2 text parts, it converts this into a single content,
189
+ like the following:
190
+
191
+ ```python
192
+ [
193
+ types.UserContent(
194
+ parts=[
195
+ types.Part.from_text(text='Why is the sky blue?'),
196
+ types.Part.from_text(text='Why is the cloud white?'),
197
+ ]
198
+ )
199
+ ]
200
+ ```
201
+
202
+ Where a `types.UserContent` is a subclass of `types.Content`, the
203
+ `role` field in `types.UserContent` is fixed to be `user`.
204
+
205
+ ##### Provide a function call part
206
+
207
+ ```python
208
+ contents = types.Part.from_function_call(
209
+ name='get_weather_by_location',
210
+ args={'location': 'Boston'}
211
+ )
212
+ ```
213
+
214
+ The SDK converts a function call part to a content with a `model` role:
215
+
216
+ ```python
217
+ [
218
+ types.ModelContent(
219
+ parts=[
220
+ types.Part.from_function_call(
221
+ name='get_weather_by_location',
222
+ args={'location': 'Boston'}
223
+ )
224
+ ]
225
+ )
226
+ ]
227
+ ```
228
+
229
+ Where a `types.ModelContent` is a subclass of `types.Content`, the
230
+ `role` field in `types.ModelContent` is fixed to be `model`.
231
+
232
+ ##### Provide a list of function call parts
233
+
234
+ ```python
235
+ contents = [
236
+ types.Part.from_function_call(
237
+ name='get_weather_by_location',
238
+ args={'location': 'Boston'}
239
+ ),
240
+ types.Part.from_function_call(
241
+ name='get_weather_by_location',
242
+ args={'location': 'New York'}
243
+ ),
244
+ ]
245
+ ```
246
+
247
+ The SDK converts a list of function call parts to the a content with a `model` role:
248
+
249
+ ```python
250
+ [
251
+ types.ModelContent(
252
+ parts=[
253
+ types.Part.from_function_call(
254
+ name='get_weather_by_location',
255
+ args={'location': 'Boston'}
256
+ ),
257
+ types.Part.from_function_call(
258
+ name='get_weather_by_location',
259
+ args={'location': 'New York'}
260
+ )
261
+ ]
262
+ )
263
+ ]
264
+ ```
265
+
266
+ Where a `types.ModelContent` is a subclass of `types.Content`, the
267
+ `role` field in `types.ModelContent` is fixed to be `model`.
268
+
269
+ ##### Provide a non function call part
270
+
271
+ ```python
272
+ contents = types.Part.from_uri(
273
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
274
+ mime_type: 'image/jpeg',
275
+ )
276
+ ```
277
+
278
+ The SDK converts all non function call parts into a content with a `user` role.
279
+
280
+ ```python
281
+ [
282
+ types.UserContent(parts=[
186
283
  types.Part.from_uri(
187
- file_uri='gs://generativeai-downloads/images/scones.jpg',
188
- mime_type='image/jpeg',
189
- ),
190
- ],
284
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
285
+ mime_type: 'image/jpeg',
286
+ )
287
+ ])
288
+ ]
289
+ ```
290
+
291
+ ##### Provide a list of non function call parts
292
+
293
+ ```python
294
+ contents = [
295
+ types.Part.from_text('What is this image about?'),
296
+ types.Part.from_uri(
297
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
298
+ mime_type: 'image/jpeg',
299
+ )
300
+ ]
191
301
  ```
192
302
 
303
+ The SDK will convert the list of parts into a content with a `user` role
304
+
305
+ ```python
306
+ [
307
+ types.UserContent(
308
+ parts=[
309
+ types.Part.from_text('What is this image about?'),
310
+ types.Part.from_uri(
311
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
312
+ mime_type: 'image/jpeg',
313
+ )
314
+ ]
315
+ )
316
+ ]
317
+ ```
318
+
319
+ ##### Mix types in contents
320
+ You can also provide a list of `types.ContentUnion`. The SDK leaves items of
321
+ `types.Content` as is, it groups consecutive non function call parts into a
322
+ single `types.UserContent`, and it groups consecutive function call parts into
323
+ a single `types.ModelContent`.
324
+
325
+ If you put a list within a list, the inner list can only contain
326
+ `types.PartUnion` items. The SDK will convert the inner list into a single
327
+ `types.UserContent`.
328
+
193
329
  ### System Instructions and Other Configs
194
330
 
195
331
  The output of the model can be influenced by several optional settings
@@ -480,6 +616,10 @@ response = client.models.generate_content(
480
616
  ```
481
617
  ### JSON Response Schema
482
618
 
619
+ However you define your schema, don't duplicate it in your input prompt,
620
+ including by giving examples of expected JSON output. If you do, the generated
621
+ output might be lower in quality.
622
+
483
623
  #### Pydantic Model Schema support
484
624
 
485
625
  Schemas can be provided as Pydantic Models.