google-genai 1.13.0__tar.gz → 1.14.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 (36) hide show
  1. {google_genai-1.13.0/google_genai.egg-info → google_genai-1.14.0}/PKG-INFO +3 -1
  2. {google_genai-1.13.0 → google_genai-1.14.0}/README.md +2 -0
  3. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_api_client.py +59 -17
  4. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_live_converters.py +228 -2
  5. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/caches.py +250 -0
  6. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/models.py +250 -0
  7. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/types.py +340 -0
  8. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/version.py +1 -1
  9. {google_genai-1.13.0 → google_genai-1.14.0/google_genai.egg-info}/PKG-INFO +3 -1
  10. {google_genai-1.13.0 → google_genai-1.14.0}/pyproject.toml +1 -1
  11. {google_genai-1.13.0 → google_genai-1.14.0}/LICENSE +0 -0
  12. {google_genai-1.13.0 → google_genai-1.14.0}/MANIFEST.in +0 -0
  13. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/__init__.py +0 -0
  14. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_api_module.py +0 -0
  15. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_automatic_function_calling_util.py +0 -0
  16. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_base_url.py +0 -0
  17. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_common.py +0 -0
  18. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_extra_utils.py +0 -0
  19. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_replay_api_client.py +0 -0
  20. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_test_api_client.py +0 -0
  21. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/_transformers.py +0 -0
  22. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/batches.py +0 -0
  23. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/chats.py +0 -0
  24. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/client.py +0 -0
  25. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/errors.py +0 -0
  26. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/files.py +0 -0
  27. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/live.py +0 -0
  28. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/operations.py +0 -0
  29. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/pagers.py +0 -0
  30. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/py.typed +0 -0
  31. {google_genai-1.13.0 → google_genai-1.14.0}/google/genai/tunings.py +0 -0
  32. {google_genai-1.13.0 → google_genai-1.14.0}/google_genai.egg-info/SOURCES.txt +0 -0
  33. {google_genai-1.13.0 → google_genai-1.14.0}/google_genai.egg-info/dependency_links.txt +0 -0
  34. {google_genai-1.13.0 → google_genai-1.14.0}/google_genai.egg-info/requires.txt +0 -0
  35. {google_genai-1.13.0 → google_genai-1.14.0}/google_genai.egg-info/top_level.txt +0 -0
  36. {google_genai-1.13.0 → google_genai-1.14.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.13.0
3
+ Version: 1.14.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -32,6 +32,8 @@ Dynamic: license-file
32
32
  # Google Gen AI SDK
33
33
 
34
34
  [![PyPI version](https://img.shields.io/pypi/v/google-genai.svg)](https://pypi.org/project/google-genai/)
35
+ ![Python support](https://img.shields.io/pypi/pyversions/google-genai)
36
+ [![PyPI - Downloads](https://img.shields.io/pypi/dw/google-genai)](https://pypistats.org/packages/google-genai)
35
37
 
36
38
  --------
37
39
  **Documentation:** https://googleapis.github.io/python-genai/
@@ -1,6 +1,8 @@
1
1
  # Google Gen AI SDK
2
2
 
3
3
  [![PyPI version](https://img.shields.io/pypi/v/google-genai.svg)](https://pypi.org/project/google-genai/)
4
+ ![Python support](https://img.shields.io/pypi/pyversions/google-genai)
5
+ [![PyPI - Downloads](https://img.shields.io/pypi/dw/google-genai)](https://pypistats.org/packages/google-genai)
4
6
 
5
7
  --------
6
8
  **Documentation:** https://googleapis.github.io/python-genai/
@@ -58,7 +58,9 @@ from .types import HttpOptionsOrDict
58
58
 
59
59
  logger = logging.getLogger('google_genai._api_client')
60
60
  CHUNK_SIZE = 8 * 1024 * 1024 # 8 MB chunk size
61
-
61
+ MAX_RETRY_COUNT = 3
62
+ INITIAL_RETRY_DELAY = 1 # second
63
+ DELAY_MULTIPLIER = 2
62
64
 
63
65
  def _append_library_version_headers(headers: dict[str, str]) -> None:
64
66
  """Appends the telemetry header to the headers dict."""
@@ -283,6 +285,18 @@ class SyncHttpxClient(httpx.Client):
283
285
  kwargs.setdefault('follow_redirects', True)
284
286
  super().__init__(**kwargs)
285
287
 
288
+ def __del__(self) -> None:
289
+ """Closes the httpx client."""
290
+ try:
291
+ if self.is_closed:
292
+ return
293
+ except Exception:
294
+ pass
295
+ try:
296
+ self.close()
297
+ except Exception:
298
+ pass
299
+
286
300
 
287
301
  class AsyncHttpxClient(httpx.AsyncClient):
288
302
  """Async httpx client."""
@@ -292,6 +306,17 @@ class AsyncHttpxClient(httpx.AsyncClient):
292
306
  kwargs.setdefault('follow_redirects', True)
293
307
  super().__init__(**kwargs)
294
308
 
309
+ def __del__(self) -> None:
310
+ try:
311
+ if self.is_closed:
312
+ return
313
+ except Exception:
314
+ pass
315
+ try:
316
+ asyncio.get_running_loop().create_task(self.aclose())
317
+ except Exception:
318
+ pass
319
+
295
320
 
296
321
  class BaseApiClient:
297
322
  """Client for calling HTTP APIs sending and receiving JSON."""
@@ -865,15 +890,23 @@ class BaseApiClient:
865
890
  'Content-Length': str(chunk_size),
866
891
  }
867
892
  _populate_server_timeout_header(upload_headers, timeout_in_seconds)
868
- response = self._httpx_client.request(
869
- method='POST',
870
- url=upload_url,
871
- headers=upload_headers,
872
- content=file_chunk,
873
- timeout=timeout_in_seconds,
874
- )
893
+ retry_count = 0
894
+ while retry_count < MAX_RETRY_COUNT:
895
+ response = self._httpx_client.request(
896
+ method='POST',
897
+ url=upload_url,
898
+ headers=upload_headers,
899
+ content=file_chunk,
900
+ timeout=timeout_in_seconds,
901
+ )
902
+ if response.headers.get('x-goog-upload-status'):
903
+ break
904
+ delay_seconds = INITIAL_RETRY_DELAY * (DELAY_MULTIPLIER**retry_count)
905
+ retry_count += 1
906
+ time.sleep(delay_seconds)
907
+
875
908
  offset += chunk_size
876
- if response.headers['x-goog-upload-status'] != 'active':
909
+ if response.headers.get('x-goog-upload-status') != 'active':
877
910
  break # upload is complete or it has been interrupted.
878
911
  if upload_size <= offset: # Status is not finalized.
879
912
  raise ValueError(
@@ -881,7 +914,7 @@ class BaseApiClient:
881
914
  f' finalized.'
882
915
  )
883
916
 
884
- if response.headers['x-goog-upload-status'] != 'final':
917
+ if response.headers.get('x-goog-upload-status') != 'final':
885
918
  raise ValueError(
886
919
  'Failed to upload file: Upload status is not finalized.'
887
920
  )
@@ -1013,13 +1046,22 @@ class BaseApiClient:
1013
1046
  'Content-Length': str(chunk_size),
1014
1047
  }
1015
1048
  _populate_server_timeout_header(upload_headers, timeout_in_seconds)
1016
- response = await self._async_httpx_client.request(
1017
- method='POST',
1018
- url=upload_url,
1019
- content=file_chunk,
1020
- headers=upload_headers,
1021
- timeout=timeout_in_seconds,
1022
- )
1049
+
1050
+ retry_count = 0
1051
+ while retry_count < MAX_RETRY_COUNT:
1052
+ response = await self._async_httpx_client.request(
1053
+ method='POST',
1054
+ url=upload_url,
1055
+ content=file_chunk,
1056
+ headers=upload_headers,
1057
+ timeout=timeout_in_seconds,
1058
+ )
1059
+ if response.headers.get('x-goog-upload-status'):
1060
+ break
1061
+ delay_seconds = INITIAL_RETRY_DELAY * (DELAY_MULTIPLIER**retry_count)
1062
+ retry_count += 1
1063
+ time.sleep(delay_seconds)
1064
+
1023
1065
  offset += chunk_size
1024
1066
  if response.headers.get('x-goog-upload-status') != 'active':
1025
1067
  break # upload is complete or it has been interrupted.
@@ -252,6 +252,156 @@ def _GoogleSearchRetrieval_to_vertex(
252
252
  return to_object
253
253
 
254
254
 
255
+ def _EnterpriseWebSearch_to_mldev(
256
+ api_client: BaseApiClient,
257
+ from_object: Union[dict[str, Any], object],
258
+ parent_object: Optional[dict[str, Any]] = None,
259
+ ) -> dict[str, Any]:
260
+ to_object: dict[str, Any] = {}
261
+
262
+ return to_object
263
+
264
+
265
+ def _EnterpriseWebSearch_to_vertex(
266
+ api_client: BaseApiClient,
267
+ from_object: Union[dict[str, Any], object],
268
+ parent_object: Optional[dict[str, Any]] = None,
269
+ ) -> dict[str, Any]:
270
+ to_object: dict[str, Any] = {}
271
+
272
+ return to_object
273
+
274
+
275
+ def _ApiKeyConfig_to_mldev(
276
+ api_client: BaseApiClient,
277
+ from_object: Union[dict[str, Any], object],
278
+ parent_object: Optional[dict[str, Any]] = None,
279
+ ) -> dict[str, Any]:
280
+ to_object: dict[str, Any] = {}
281
+ if getv(from_object, ['api_key_string']) is not None:
282
+ raise ValueError('api_key_string parameter is not supported in Gemini API.')
283
+
284
+ return to_object
285
+
286
+
287
+ def _ApiKeyConfig_to_vertex(
288
+ api_client: BaseApiClient,
289
+ from_object: Union[dict[str, Any], object],
290
+ parent_object: Optional[dict[str, Any]] = None,
291
+ ) -> dict[str, Any]:
292
+ to_object: dict[str, Any] = {}
293
+ if getv(from_object, ['api_key_string']) is not None:
294
+ setv(to_object, ['apiKeyString'], getv(from_object, ['api_key_string']))
295
+
296
+ return to_object
297
+
298
+
299
+ def _AuthConfig_to_mldev(
300
+ api_client: BaseApiClient,
301
+ from_object: Union[dict[str, Any], object],
302
+ parent_object: Optional[dict[str, Any]] = None,
303
+ ) -> dict[str, Any]:
304
+ to_object: dict[str, Any] = {}
305
+ if getv(from_object, ['api_key_config']) is not None:
306
+ raise ValueError('api_key_config parameter is not supported in Gemini API.')
307
+
308
+ if getv(from_object, ['auth_type']) is not None:
309
+ setv(to_object, ['authType'], getv(from_object, ['auth_type']))
310
+
311
+ if getv(from_object, ['google_service_account_config']) is not None:
312
+ setv(
313
+ to_object,
314
+ ['googleServiceAccountConfig'],
315
+ getv(from_object, ['google_service_account_config']),
316
+ )
317
+
318
+ if getv(from_object, ['http_basic_auth_config']) is not None:
319
+ setv(
320
+ to_object,
321
+ ['httpBasicAuthConfig'],
322
+ getv(from_object, ['http_basic_auth_config']),
323
+ )
324
+
325
+ if getv(from_object, ['oauth_config']) is not None:
326
+ setv(to_object, ['oauthConfig'], getv(from_object, ['oauth_config']))
327
+
328
+ if getv(from_object, ['oidc_config']) is not None:
329
+ setv(to_object, ['oidcConfig'], getv(from_object, ['oidc_config']))
330
+
331
+ return to_object
332
+
333
+
334
+ def _AuthConfig_to_vertex(
335
+ api_client: BaseApiClient,
336
+ from_object: Union[dict[str, Any], object],
337
+ parent_object: Optional[dict[str, Any]] = None,
338
+ ) -> dict[str, Any]:
339
+ to_object: dict[str, Any] = {}
340
+ if getv(from_object, ['api_key_config']) is not None:
341
+ setv(
342
+ to_object,
343
+ ['apiKeyConfig'],
344
+ _ApiKeyConfig_to_vertex(
345
+ api_client, getv(from_object, ['api_key_config']), to_object
346
+ ),
347
+ )
348
+
349
+ if getv(from_object, ['auth_type']) is not None:
350
+ setv(to_object, ['authType'], getv(from_object, ['auth_type']))
351
+
352
+ if getv(from_object, ['google_service_account_config']) is not None:
353
+ setv(
354
+ to_object,
355
+ ['googleServiceAccountConfig'],
356
+ getv(from_object, ['google_service_account_config']),
357
+ )
358
+
359
+ if getv(from_object, ['http_basic_auth_config']) is not None:
360
+ setv(
361
+ to_object,
362
+ ['httpBasicAuthConfig'],
363
+ getv(from_object, ['http_basic_auth_config']),
364
+ )
365
+
366
+ if getv(from_object, ['oauth_config']) is not None:
367
+ setv(to_object, ['oauthConfig'], getv(from_object, ['oauth_config']))
368
+
369
+ if getv(from_object, ['oidc_config']) is not None:
370
+ setv(to_object, ['oidcConfig'], getv(from_object, ['oidc_config']))
371
+
372
+ return to_object
373
+
374
+
375
+ def _GoogleMaps_to_mldev(
376
+ api_client: BaseApiClient,
377
+ from_object: Union[dict[str, Any], object],
378
+ parent_object: Optional[dict[str, Any]] = None,
379
+ ) -> dict[str, Any]:
380
+ to_object: dict[str, Any] = {}
381
+ if getv(from_object, ['auth_config']) is not None:
382
+ raise ValueError('auth_config parameter is not supported in Gemini API.')
383
+
384
+ return to_object
385
+
386
+
387
+ def _GoogleMaps_to_vertex(
388
+ api_client: BaseApiClient,
389
+ from_object: Union[dict[str, Any], object],
390
+ parent_object: Optional[dict[str, Any]] = None,
391
+ ) -> dict[str, Any]:
392
+ to_object: dict[str, Any] = {}
393
+ if getv(from_object, ['auth_config']) is not None:
394
+ setv(
395
+ to_object,
396
+ ['authConfig'],
397
+ _AuthConfig_to_vertex(
398
+ api_client, getv(from_object, ['auth_config']), to_object
399
+ ),
400
+ )
401
+
402
+ return to_object
403
+
404
+
255
405
  def _Tool_to_mldev(
256
406
  api_client: BaseApiClient,
257
407
  from_object: Union[dict[str, Any], object],
@@ -281,6 +431,14 @@ def _Tool_to_mldev(
281
431
  ),
282
432
  )
283
433
 
434
+ if getv(from_object, ['enterprise_web_search']) is not None:
435
+ raise ValueError(
436
+ 'enterprise_web_search parameter is not supported in Gemini API.'
437
+ )
438
+
439
+ if getv(from_object, ['google_maps']) is not None:
440
+ raise ValueError('google_maps parameter is not supported in Gemini API.')
441
+
284
442
  if getv(from_object, ['code_execution']) is not None:
285
443
  setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
286
444
 
@@ -323,6 +481,24 @@ def _Tool_to_vertex(
323
481
  ),
324
482
  )
325
483
 
484
+ if getv(from_object, ['enterprise_web_search']) is not None:
485
+ setv(
486
+ to_object,
487
+ ['enterpriseWebSearch'],
488
+ _EnterpriseWebSearch_to_vertex(
489
+ api_client, getv(from_object, ['enterprise_web_search']), to_object
490
+ ),
491
+ )
492
+
493
+ if getv(from_object, ['google_maps']) is not None:
494
+ setv(
495
+ to_object,
496
+ ['googleMaps'],
497
+ _GoogleMaps_to_vertex(
498
+ api_client, getv(from_object, ['google_maps']), to_object
499
+ ),
500
+ )
501
+
326
502
  if getv(from_object, ['code_execution']) is not None:
327
503
  setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
328
504
 
@@ -688,8 +864,14 @@ def _LiveConnectConfig_to_mldev(
688
864
  )
689
865
 
690
866
  if getv(from_object, ['input_audio_transcription']) is not None:
691
- raise ValueError(
692
- 'input_audio_transcription parameter is not supported in Gemini API.'
867
+ setv(
868
+ parent_object,
869
+ ['setup', 'inputAudioTranscription'],
870
+ _AudioTranscriptionConfig_to_mldev(
871
+ api_client,
872
+ getv(from_object, ['input_audio_transcription']),
873
+ to_object,
874
+ ),
693
875
  )
694
876
 
695
877
  if getv(from_object, ['output_audio_transcription']) is not None:
@@ -1117,6 +1299,28 @@ def _LiveClientSetup_to_mldev(
1117
1299
  ),
1118
1300
  )
1119
1301
 
1302
+ if getv(from_object, ['input_audio_transcription']) is not None:
1303
+ setv(
1304
+ to_object,
1305
+ ['inputAudioTranscription'],
1306
+ _AudioTranscriptionConfig_to_mldev(
1307
+ api_client,
1308
+ getv(from_object, ['input_audio_transcription']),
1309
+ to_object,
1310
+ ),
1311
+ )
1312
+
1313
+ if getv(from_object, ['output_audio_transcription']) is not None:
1314
+ setv(
1315
+ to_object,
1316
+ ['outputAudioTranscription'],
1317
+ _AudioTranscriptionConfig_to_mldev(
1318
+ api_client,
1319
+ getv(from_object, ['output_audio_transcription']),
1320
+ to_object,
1321
+ ),
1322
+ )
1323
+
1120
1324
  return to_object
1121
1325
 
1122
1326
 
@@ -1177,6 +1381,28 @@ def _LiveClientSetup_to_vertex(
1177
1381
  ),
1178
1382
  )
1179
1383
 
1384
+ if getv(from_object, ['input_audio_transcription']) is not None:
1385
+ setv(
1386
+ to_object,
1387
+ ['inputAudioTranscription'],
1388
+ _AudioTranscriptionConfig_to_vertex(
1389
+ api_client,
1390
+ getv(from_object, ['input_audio_transcription']),
1391
+ to_object,
1392
+ ),
1393
+ )
1394
+
1395
+ if getv(from_object, ['output_audio_transcription']) is not None:
1396
+ setv(
1397
+ to_object,
1398
+ ['outputAudioTranscription'],
1399
+ _AudioTranscriptionConfig_to_vertex(
1400
+ api_client,
1401
+ getv(from_object, ['output_audio_transcription']),
1402
+ to_object,
1403
+ ),
1404
+ )
1405
+
1180
1406
  return to_object
1181
1407
 
1182
1408