google-genai 1.5.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.5.0 → google_genai-1.6.0}/PKG-INFO +194 -25
  2. google_genai-1.5.0/google_genai.egg-info/PKG-INFO → google_genai-1.6.0/README.md +186 -47
  3. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_api_client.py +93 -67
  4. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_automatic_function_calling_util.py +4 -14
  5. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_transformers.py +61 -37
  6. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/batches.py +4 -0
  7. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/caches.py +20 -26
  8. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/client.py +3 -2
  9. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/errors.py +11 -19
  10. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/files.py +7 -7
  11. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/live.py +276 -93
  12. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/models.py +131 -66
  13. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/operations.py +30 -2
  14. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/pagers.py +3 -5
  15. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/tunings.py +31 -21
  16. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/types.py +88 -33
  17. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/version.py +1 -1
  18. google_genai-1.5.0/README.md → google_genai-1.6.0/google_genai.egg-info/PKG-INFO +216 -17
  19. google_genai-1.6.0/google_genai.egg-info/requires.txt +7 -0
  20. {google_genai-1.5.0 → google_genai-1.6.0}/pyproject.toml +8 -8
  21. google_genai-1.5.0/google_genai.egg-info/requires.txt +0 -7
  22. {google_genai-1.5.0 → google_genai-1.6.0}/LICENSE +0 -0
  23. {google_genai-1.5.0 → google_genai-1.6.0}/MANIFEST.in +0 -0
  24. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/__init__.py +0 -0
  25. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_api_module.py +0 -0
  26. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_common.py +0 -0
  27. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_extra_utils.py +0 -0
  28. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_replay_api_client.py +0 -0
  29. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/_test_api_client.py +0 -0
  30. {google_genai-1.5.0 → google_genai-1.6.0}/google/genai/chats.py +0 -0
  31. {google_genai-1.5.0 → google_genai-1.6.0}/google_genai.egg-info/SOURCES.txt +0 -0
  32. {google_genai-1.5.0 → google_genai-1.6.0}/google_genai.egg-info/dependency_links.txt +0 -0
  33. {google_genai-1.5.0 → google_genai-1.6.0}/google_genai.egg-info/top_level.txt +0 -0
  34. {google_genai-1.5.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.5.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,13 +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: anyio<5.0.0dev,>=4.8.0
24
- Requires-Dist: google-auth<3.0.0dev,>=2.14.1
25
- Requires-Dist: httpx<1.0.0dev,>=0.28.1
26
- Requires-Dist: pydantic<3.0.0dev,>=2.0.0
27
- Requires-Dist: requests<3.0.0dev,>=2.28.1
28
- Requires-Dist: websockets<15.0dev,>=13.0
29
- 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
30
30
 
31
31
  # Google Gen AI SDK
32
32
 
@@ -160,37 +160,202 @@ response = client.models.generate_content(
160
160
  print(response.text)
161
161
  ```
162
162
 
163
- #### How to structure `contents`
164
- 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.
165
167
 
166
- 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
167
263
 
168
264
  ```python
169
- 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
+ ]
170
294
  ```
171
295
 
172
- 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
173
300
 
174
301
  ```python
175
- contents=types.Content(parts=[
176
- types.Part.from_text(text='Can you recommend some things to do in Boston in the winter?'),
177
- types.Part.from_text(text='Can you recommend some things to do in New York in the winter?')
178
- ], role='user')
302
+ contents = types.Part.from_uri(
303
+ file_uri: 'gs://generativeai-downloads/images/scones.jpg',
304
+ mime_type: 'image/jpeg',
305
+ )
179
306
  ```
180
307
 
181
- When sending more than one input type, provide a list with multiple `Content`
182
- instances:
308
+ The SDK converts all non function call parts into a content with a `user` role.
183
309
 
184
310
  ```python
185
- contents=[
186
- 'What is this a picture of?',
311
+ [
312
+ types.UserContent(parts=[
187
313
  types.Part.from_uri(
188
- file_uri='gs://generativeai-downloads/images/scones.jpg',
189
- mime_type='image/jpeg',
190
- ),
191
- ],
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
+ ]
192
331
  ```
193
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
+
194
359
  ### System Instructions and Other Configs
195
360
 
196
361
  The output of the model can be influenced by several optional settings
@@ -481,6 +646,10 @@ response = client.models.generate_content(
481
646
  ```
482
647
  ### JSON Response Schema
483
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
+
484
653
  #### Pydantic Model Schema support
485
654
 
486
655
  Schemas can be provided as Pydantic Models.
@@ -1,33 +1,3 @@
1
- Metadata-Version: 2.2
2
- Name: google-genai
3
- Version: 1.5.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: anyio<5.0.0dev,>=4.8.0
24
- Requires-Dist: google-auth<3.0.0dev,>=2.14.1
25
- Requires-Dist: httpx<1.0.0dev,>=0.28.1
26
- Requires-Dist: pydantic<3.0.0dev,>=2.0.0
27
- Requires-Dist: requests<3.0.0dev,>=2.28.1
28
- Requires-Dist: websockets<15.0dev,>=13.0
29
- Requires-Dist: typing-extensions<5.0.0dev,>=4.11.0
30
-
31
1
  # Google Gen AI SDK
32
2
 
33
3
  [![PyPI version](https://img.shields.io/pypi/v/google-genai.svg)](https://pypi.org/project/google-genai/)
@@ -160,37 +130,202 @@ response = client.models.generate_content(
160
130
  print(response.text)
161
131
  ```
162
132
 
163
- #### How to structure `contents`
164
- 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
+ ```
165
149
 
166
- Provide a single string as shown in the text example above:
150
+ SDK converts this to
167
151
 
168
152
  ```python
169
- 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
+ ]
170
159
  ```
171
160
 
172
- Provide a single `Content` instance with multiple `Part` instances:
161
+ ##### Provide a string
173
162
 
174
163
  ```python
175
- contents=types.Content(parts=[
176
- types.Part.from_text(text='Can you recommend some things to do in Boston in the winter?'),
177
- types.Part.from_text(text='Can you recommend some things to do in New York in the winter?')
178
- ], role='user')
164
+ contents='Why is the sky blue?'
179
165
  ```
180
166
 
181
- When sending more than one input type, provide a list with multiple `Content`
182
- instances:
167
+ The SDK will assume this is a text part, and it converts this into the following:
183
168
 
184
169
  ```python
185
- contents=[
186
- '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=[
187
283
  types.Part.from_uri(
188
- file_uri='gs://generativeai-downloads/images/scones.jpg',
189
- mime_type='image/jpeg',
190
- ),
191
- ],
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
+ ]
192
301
  ```
193
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
+
194
329
  ### System Instructions and Other Configs
195
330
 
196
331
  The output of the model can be influenced by several optional settings
@@ -481,6 +616,10 @@ response = client.models.generate_content(
481
616
  ```
482
617
  ### JSON Response Schema
483
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
+
484
623
  #### Pydantic Model Schema support
485
624
 
486
625
  Schemas can be provided as Pydantic Models.