google-genai 1.45.0__py3-none-any.whl → 1.47.0__py3-none-any.whl

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.
google/genai/models.py CHANGED
@@ -59,12 +59,12 @@ def _Blob_to_mldev(
59
59
  parent_object: Optional[dict[str, Any]] = None,
60
60
  ) -> dict[str, Any]:
61
61
  to_object: dict[str, Any] = {}
62
- if getv(from_object, ['display_name']) is not None:
63
- raise ValueError('display_name parameter is not supported in Gemini API.')
64
-
65
62
  if getv(from_object, ['data']) is not None:
66
63
  setv(to_object, ['data'], getv(from_object, ['data']))
67
64
 
65
+ if getv(from_object, ['display_name']) is not None:
66
+ raise ValueError('display_name parameter is not supported in Gemini API.')
67
+
68
68
  if getv(from_object, ['mime_type']) is not None:
69
69
  setv(to_object, ['mimeType'], getv(from_object, ['mime_type']))
70
70
 
@@ -94,13 +94,6 @@ def _Candidate_from_mldev(
94
94
  if getv(from_object, ['finishReason']) is not None:
95
95
  setv(to_object, ['finish_reason'], getv(from_object, ['finishReason']))
96
96
 
97
- if getv(from_object, ['urlContextMetadata']) is not None:
98
- setv(
99
- to_object,
100
- ['url_context_metadata'],
101
- getv(from_object, ['urlContextMetadata']),
102
- )
103
-
104
97
  if getv(from_object, ['avgLogprobs']) is not None:
105
98
  setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
106
99
 
@@ -124,6 +117,13 @@ def _Candidate_from_mldev(
124
117
  [item for item in getv(from_object, ['safetyRatings'])],
125
118
  )
126
119
 
120
+ if getv(from_object, ['urlContextMetadata']) is not None:
121
+ setv(
122
+ to_object,
123
+ ['url_context_metadata'],
124
+ getv(from_object, ['urlContextMetadata']),
125
+ )
126
+
127
127
  return to_object
128
128
 
129
129
 
@@ -2398,6 +2398,11 @@ def _GenerationConfig_to_vertex(
2398
2398
  if getv(from_object, ['top_p']) is not None:
2399
2399
  setv(to_object, ['topP'], getv(from_object, ['top_p']))
2400
2400
 
2401
+ if getv(from_object, ['enable_enhanced_civic_answers']) is not None:
2402
+ raise ValueError(
2403
+ 'enable_enhanced_civic_answers parameter is not supported in Vertex AI.'
2404
+ )
2405
+
2401
2406
  return to_object
2402
2407
 
2403
2408
 
@@ -2452,16 +2457,16 @@ def _GoogleSearch_to_mldev(
2452
2457
  parent_object: Optional[dict[str, Any]] = None,
2453
2458
  ) -> dict[str, Any]:
2454
2459
  to_object: dict[str, Any] = {}
2455
- if getv(from_object, ['time_range_filter']) is not None:
2456
- setv(
2457
- to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
2458
- )
2459
-
2460
2460
  if getv(from_object, ['exclude_domains']) is not None:
2461
2461
  raise ValueError(
2462
2462
  'exclude_domains parameter is not supported in Gemini API.'
2463
2463
  )
2464
2464
 
2465
+ if getv(from_object, ['time_range_filter']) is not None:
2466
+ setv(
2467
+ to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
2468
+ )
2469
+
2465
2470
  return to_object
2466
2471
 
2467
2472
 
@@ -2811,19 +2816,19 @@ def _Part_to_mldev(
2811
2816
  parent_object: Optional[dict[str, Any]] = None,
2812
2817
  ) -> dict[str, Any]:
2813
2818
  to_object: dict[str, Any] = {}
2814
- if getv(from_object, ['video_metadata']) is not None:
2815
- setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
2816
-
2817
- if getv(from_object, ['thought']) is not None:
2818
- setv(to_object, ['thought'], getv(from_object, ['thought']))
2819
+ if getv(from_object, ['function_call']) is not None:
2820
+ setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
2819
2821
 
2820
- if getv(from_object, ['inline_data']) is not None:
2822
+ if getv(from_object, ['code_execution_result']) is not None:
2821
2823
  setv(
2822
2824
  to_object,
2823
- ['inlineData'],
2824
- _Blob_to_mldev(getv(from_object, ['inline_data']), to_object),
2825
+ ['codeExecutionResult'],
2826
+ getv(from_object, ['code_execution_result']),
2825
2827
  )
2826
2828
 
2829
+ if getv(from_object, ['executable_code']) is not None:
2830
+ setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
2831
+
2827
2832
  if getv(from_object, ['file_data']) is not None:
2828
2833
  setv(
2829
2834
  to_object,
@@ -2831,35 +2836,35 @@ def _Part_to_mldev(
2831
2836
  _FileData_to_mldev(getv(from_object, ['file_data']), to_object),
2832
2837
  )
2833
2838
 
2834
- if getv(from_object, ['thought_signature']) is not None:
2839
+ if getv(from_object, ['function_response']) is not None:
2835
2840
  setv(
2836
2841
  to_object,
2837
- ['thoughtSignature'],
2838
- getv(from_object, ['thought_signature']),
2842
+ ['functionResponse'],
2843
+ getv(from_object, ['function_response']),
2839
2844
  )
2840
2845
 
2841
- if getv(from_object, ['function_call']) is not None:
2842
- setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
2843
-
2844
- if getv(from_object, ['code_execution_result']) is not None:
2846
+ if getv(from_object, ['inline_data']) is not None:
2845
2847
  setv(
2846
2848
  to_object,
2847
- ['codeExecutionResult'],
2848
- getv(from_object, ['code_execution_result']),
2849
+ ['inlineData'],
2850
+ _Blob_to_mldev(getv(from_object, ['inline_data']), to_object),
2849
2851
  )
2850
2852
 
2851
- if getv(from_object, ['executable_code']) is not None:
2852
- setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
2853
+ if getv(from_object, ['text']) is not None:
2854
+ setv(to_object, ['text'], getv(from_object, ['text']))
2853
2855
 
2854
- if getv(from_object, ['function_response']) is not None:
2856
+ if getv(from_object, ['thought']) is not None:
2857
+ setv(to_object, ['thought'], getv(from_object, ['thought']))
2858
+
2859
+ if getv(from_object, ['thought_signature']) is not None:
2855
2860
  setv(
2856
2861
  to_object,
2857
- ['functionResponse'],
2858
- getv(from_object, ['function_response']),
2862
+ ['thoughtSignature'],
2863
+ getv(from_object, ['thought_signature']),
2859
2864
  )
2860
2865
 
2861
- if getv(from_object, ['text']) is not None:
2862
- setv(to_object, ['text'], getv(from_object, ['text']))
2866
+ if getv(from_object, ['video_metadata']) is not None:
2867
+ setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
2863
2868
 
2864
2869
  return to_object
2865
2870
 
@@ -3131,12 +3136,12 @@ def _SafetySetting_to_mldev(
3131
3136
  parent_object: Optional[dict[str, Any]] = None,
3132
3137
  ) -> dict[str, Any]:
3133
3138
  to_object: dict[str, Any] = {}
3134
- if getv(from_object, ['method']) is not None:
3135
- raise ValueError('method parameter is not supported in Gemini API.')
3136
-
3137
3139
  if getv(from_object, ['category']) is not None:
3138
3140
  setv(to_object, ['category'], getv(from_object, ['category']))
3139
3141
 
3142
+ if getv(from_object, ['method']) is not None:
3143
+ raise ValueError('method parameter is not supported in Gemini API.')
3144
+
3140
3145
  if getv(from_object, ['threshold']) is not None:
3141
3146
  setv(to_object, ['threshold'], getv(from_object, ['threshold']))
3142
3147
 
@@ -3275,6 +3280,9 @@ def _SpeechConfig_to_vertex(
3275
3280
  parent_object: Optional[dict[str, Any]] = None,
3276
3281
  ) -> dict[str, Any]:
3277
3282
  to_object: dict[str, Any] = {}
3283
+ if getv(from_object, ['language_code']) is not None:
3284
+ setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
3285
+
3278
3286
  if getv(from_object, ['voice_config']) is not None:
3279
3287
  setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
3280
3288
 
@@ -3283,9 +3291,6 @@ def _SpeechConfig_to_vertex(
3283
3291
  'multi_speaker_voice_config parameter is not supported in Vertex AI.'
3284
3292
  )
3285
3293
 
3286
- if getv(from_object, ['language_code']) is not None:
3287
- setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
3288
-
3289
3294
  return to_object
3290
3295
 
3291
3296
 
@@ -3304,13 +3309,6 @@ def _Tool_to_mldev(
3304
3309
  if getv(from_object, ['retrieval']) is not None:
3305
3310
  raise ValueError('retrieval parameter is not supported in Gemini API.')
3306
3311
 
3307
- if getv(from_object, ['google_search']) is not None:
3308
- setv(
3309
- to_object,
3310
- ['googleSearch'],
3311
- _GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
3312
- )
3313
-
3314
3312
  if getv(from_object, ['google_search_retrieval']) is not None:
3315
3313
  setv(
3316
3314
  to_object,
@@ -3318,11 +3316,6 @@ def _Tool_to_mldev(
3318
3316
  getv(from_object, ['google_search_retrieval']),
3319
3317
  )
3320
3318
 
3321
- if getv(from_object, ['enterprise_web_search']) is not None:
3322
- raise ValueError(
3323
- 'enterprise_web_search parameter is not supported in Gemini API.'
3324
- )
3325
-
3326
3319
  if getv(from_object, ['google_maps']) is not None:
3327
3320
  setv(
3328
3321
  to_object,
@@ -3330,15 +3323,27 @@ def _Tool_to_mldev(
3330
3323
  _GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
3331
3324
  )
3332
3325
 
3333
- if getv(from_object, ['url_context']) is not None:
3334
- setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
3335
-
3336
3326
  if getv(from_object, ['computer_use']) is not None:
3337
3327
  setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
3338
3328
 
3339
3329
  if getv(from_object, ['code_execution']) is not None:
3340
3330
  setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
3341
3331
 
3332
+ if getv(from_object, ['enterprise_web_search']) is not None:
3333
+ raise ValueError(
3334
+ 'enterprise_web_search parameter is not supported in Gemini API.'
3335
+ )
3336
+
3337
+ if getv(from_object, ['google_search']) is not None:
3338
+ setv(
3339
+ to_object,
3340
+ ['googleSearch'],
3341
+ _GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
3342
+ )
3343
+
3344
+ if getv(from_object, ['url_context']) is not None:
3345
+ setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
3346
+
3342
3347
  return to_object
3343
3348
 
3344
3349
 
@@ -3360,9 +3365,6 @@ def _Tool_to_vertex(
3360
3365
  if getv(from_object, ['retrieval']) is not None:
3361
3366
  setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
3362
3367
 
3363
- if getv(from_object, ['google_search']) is not None:
3364
- setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
3365
-
3366
3368
  if getv(from_object, ['google_search_retrieval']) is not None:
3367
3369
  setv(
3368
3370
  to_object,
@@ -3370,6 +3372,15 @@ def _Tool_to_vertex(
3370
3372
  getv(from_object, ['google_search_retrieval']),
3371
3373
  )
3372
3374
 
3375
+ if getv(from_object, ['google_maps']) is not None:
3376
+ setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
3377
+
3378
+ if getv(from_object, ['computer_use']) is not None:
3379
+ setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
3380
+
3381
+ if getv(from_object, ['code_execution']) is not None:
3382
+ setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
3383
+
3373
3384
  if getv(from_object, ['enterprise_web_search']) is not None:
3374
3385
  setv(
3375
3386
  to_object,
@@ -3377,18 +3388,12 @@ def _Tool_to_vertex(
3377
3388
  getv(from_object, ['enterprise_web_search']),
3378
3389
  )
3379
3390
 
3380
- if getv(from_object, ['google_maps']) is not None:
3381
- setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
3391
+ if getv(from_object, ['google_search']) is not None:
3392
+ setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
3382
3393
 
3383
3394
  if getv(from_object, ['url_context']) is not None:
3384
3395
  setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
3385
3396
 
3386
- if getv(from_object, ['computer_use']) is not None:
3387
- setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
3388
-
3389
- if getv(from_object, ['code_execution']) is not None:
3390
- setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
3391
-
3392
3397
  return to_object
3393
3398
 
3394
3399
 
@@ -3511,6 +3516,20 @@ def _UpscaleImageAPIConfig_to_vertex(
3511
3516
  getv(from_object, ['output_gcs_uri']),
3512
3517
  )
3513
3518
 
3519
+ if getv(from_object, ['safety_filter_level']) is not None:
3520
+ setv(
3521
+ parent_object,
3522
+ ['parameters', 'safetySetting'],
3523
+ getv(from_object, ['safety_filter_level']),
3524
+ )
3525
+
3526
+ if getv(from_object, ['person_generation']) is not None:
3527
+ setv(
3528
+ parent_object,
3529
+ ['parameters', 'personGeneration'],
3530
+ getv(from_object, ['person_generation']),
3531
+ )
3532
+
3514
3533
  if getv(from_object, ['include_rai_reason']) is not None:
3515
3534
  setv(
3516
3535
  parent_object,
@@ -5371,6 +5390,8 @@ class Models(_api_module.BaseModule):
5371
5390
  api_config = types._UpscaleImageAPIConfigDict(
5372
5391
  http_options=config_dct.get('http_options', None),
5373
5392
  output_gcs_uri=config_dct.get('output_gcs_uri', None),
5393
+ safety_filter_level=config_dct.get('safety_filter_level', None),
5394
+ person_generation=config_dct.get('person_generation', None),
5374
5395
  include_rai_reason=config_dct.get('include_rai_reason', None),
5375
5396
  output_mime_type=config_dct.get('output_mime_type', None),
5376
5397
  output_compression_quality=config_dct.get(
@@ -6856,7 +6877,7 @@ class AsyncModels(_api_module.BaseModule):
6856
6877
  # * Everlasting Florals
6857
6878
  # * Timeless Petals
6858
6879
 
6859
- async for chunk in awiat client.aio.models.generate_content_stream(
6880
+ async for chunk in await client.aio.models.generate_content_stream(
6860
6881
  model='gemini-2.0-flash',
6861
6882
  contents=[
6862
6883
  types.Part.from_text('What is shown in this image?'),
@@ -6898,9 +6919,11 @@ class AsyncModels(_api_module.BaseModule):
6898
6919
  response = await self._generate_content_stream(
6899
6920
  model=model, contents=contents, config=config
6900
6921
  )
6901
- logger.info(f'AFC remote call {i} is done.')
6922
+ # TODO: b/453739108 - make AFC logic more robust like the other 3 methods.
6923
+ if i > 1:
6924
+ logger.info(f'AFC remote call {i} is done.')
6902
6925
  remaining_remote_calls_afc -= 1
6903
- if remaining_remote_calls_afc == 0:
6926
+ if i > 1 and remaining_remote_calls_afc == 0:
6904
6927
  logger.info(
6905
6928
  'Reached max remote calls for automatic function calling.'
6906
6929
  )
@@ -7193,6 +7216,8 @@ class AsyncModels(_api_module.BaseModule):
7193
7216
  api_config = types._UpscaleImageAPIConfigDict(
7194
7217
  http_options=config_dct.get('http_options', None),
7195
7218
  output_gcs_uri=config_dct.get('output_gcs_uri', None),
7219
+ safety_filter_level=config_dct.get('safety_filter_level', None),
7220
+ person_generation=config_dct.get('person_generation', None),
7196
7221
  include_rai_reason=config_dct.get('include_rai_reason', None),
7197
7222
  output_mime_type=config_dct.get('output_mime_type', None),
7198
7223
  output_compression_quality=config_dct.get(
@@ -7270,6 +7295,36 @@ class AsyncModels(_api_module.BaseModule):
7270
7295
  'Source and prompt/image/video are mutually exclusive.'
7271
7296
  + ' Please only use source.'
7272
7297
  )
7298
+ # Gemini Developer API does not support video bytes.
7299
+ video_dct: dict[str, Any] = {}
7300
+ if not self._api_client.vertexai and video:
7301
+ if isinstance(video, types.Video):
7302
+ video_dct = video.model_dump()
7303
+ else:
7304
+ video_dct = dict(video)
7305
+
7306
+ if video_dct.get('uri') and video_dct.get('video_bytes'):
7307
+ video = types.Video(
7308
+ uri=video_dct.get('uri'), mime_type=video_dct.get('mime_type')
7309
+ )
7310
+ elif not self._api_client.vertexai and source:
7311
+ if isinstance(source, types.GenerateVideosSource):
7312
+ source_dct = source.model_dump()
7313
+ video_dct = source_dct.get('video', {})
7314
+ else:
7315
+ source_dct = dict(source)
7316
+ if isinstance(source_dct.get('video'), types.Video):
7317
+ video_obj: types.Video = source_dct.get('video', types.Video())
7318
+ video_dct = video_obj.model_dump()
7319
+ if video_dct and video_dct.get('uri') and video_dct.get('video_bytes'):
7320
+ source = types.GenerateVideosSource(
7321
+ prompt=source_dct.get('prompt'),
7322
+ image=source_dct.get('image'),
7323
+ video=types.Video(
7324
+ uri=video_dct.get('uri'),
7325
+ mime_type=video_dct.get('mime_type'),
7326
+ ),
7327
+ )
7273
7328
  return await self._generate_videos(
7274
7329
  model=model,
7275
7330
  prompt=prompt,