google-genai 1.46.0__py3-none-any.whl → 1.48.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/_api_client.py +38 -15
- google/genai/_extra_utils.py +40 -3
- google/genai/_live_converters.py +66 -61
- google/genai/_tokens_converters.py +52 -47
- google/genai/_transformers.py +10 -1
- google/genai/batches.py +62 -57
- google/genai/caches.py +63 -58
- google/genai/client.py +4 -1
- google/genai/live.py +28 -18
- google/genai/models.py +205 -77
- google/genai/tunings.py +269 -94
- google/genai/types.py +1441 -1012
- google/genai/version.py +1 -1
- {google_genai-1.46.0.dist-info → google_genai-1.48.0.dist-info}/METADATA +152 -163
- {google_genai-1.46.0.dist-info → google_genai-1.48.0.dist-info}/RECORD +18 -18
- {google_genai-1.46.0.dist-info → google_genai-1.48.0.dist-info}/WHEEL +0 -0
- {google_genai-1.46.0.dist-info → google_genai-1.48.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.46.0.dist-info → google_genai-1.48.0.dist-info}/top_level.txt +0 -0
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
|
|
|
@@ -2457,16 +2457,21 @@ def _GoogleSearch_to_mldev(
|
|
|
2457
2457
|
parent_object: Optional[dict[str, Any]] = None,
|
|
2458
2458
|
) -> dict[str, Any]:
|
|
2459
2459
|
to_object: dict[str, Any] = {}
|
|
2460
|
-
if getv(from_object, ['time_range_filter']) is not None:
|
|
2461
|
-
setv(
|
|
2462
|
-
to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
|
|
2463
|
-
)
|
|
2464
|
-
|
|
2465
2460
|
if getv(from_object, ['exclude_domains']) is not None:
|
|
2466
2461
|
raise ValueError(
|
|
2467
2462
|
'exclude_domains parameter is not supported in Gemini API.'
|
|
2468
2463
|
)
|
|
2469
2464
|
|
|
2465
|
+
if getv(from_object, ['blocking_confidence']) is not None:
|
|
2466
|
+
raise ValueError(
|
|
2467
|
+
'blocking_confidence parameter is not supported in Gemini API.'
|
|
2468
|
+
)
|
|
2469
|
+
|
|
2470
|
+
if getv(from_object, ['time_range_filter']) is not None:
|
|
2471
|
+
setv(
|
|
2472
|
+
to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
|
|
2473
|
+
)
|
|
2474
|
+
|
|
2470
2475
|
return to_object
|
|
2471
2476
|
|
|
2472
2477
|
|
|
@@ -2816,19 +2821,19 @@ def _Part_to_mldev(
|
|
|
2816
2821
|
parent_object: Optional[dict[str, Any]] = None,
|
|
2817
2822
|
) -> dict[str, Any]:
|
|
2818
2823
|
to_object: dict[str, Any] = {}
|
|
2819
|
-
if getv(from_object, ['
|
|
2820
|
-
setv(to_object, ['
|
|
2821
|
-
|
|
2822
|
-
if getv(from_object, ['thought']) is not None:
|
|
2823
|
-
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
|
2824
|
+
if getv(from_object, ['function_call']) is not None:
|
|
2825
|
+
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
|
2824
2826
|
|
|
2825
|
-
if getv(from_object, ['
|
|
2827
|
+
if getv(from_object, ['code_execution_result']) is not None:
|
|
2826
2828
|
setv(
|
|
2827
2829
|
to_object,
|
|
2828
|
-
['
|
|
2829
|
-
|
|
2830
|
+
['codeExecutionResult'],
|
|
2831
|
+
getv(from_object, ['code_execution_result']),
|
|
2830
2832
|
)
|
|
2831
2833
|
|
|
2834
|
+
if getv(from_object, ['executable_code']) is not None:
|
|
2835
|
+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
|
|
2836
|
+
|
|
2832
2837
|
if getv(from_object, ['file_data']) is not None:
|
|
2833
2838
|
setv(
|
|
2834
2839
|
to_object,
|
|
@@ -2836,35 +2841,35 @@ def _Part_to_mldev(
|
|
|
2836
2841
|
_FileData_to_mldev(getv(from_object, ['file_data']), to_object),
|
|
2837
2842
|
)
|
|
2838
2843
|
|
|
2839
|
-
if getv(from_object, ['
|
|
2844
|
+
if getv(from_object, ['function_response']) is not None:
|
|
2840
2845
|
setv(
|
|
2841
2846
|
to_object,
|
|
2842
|
-
['
|
|
2843
|
-
getv(from_object, ['
|
|
2847
|
+
['functionResponse'],
|
|
2848
|
+
getv(from_object, ['function_response']),
|
|
2844
2849
|
)
|
|
2845
2850
|
|
|
2846
|
-
if getv(from_object, ['
|
|
2847
|
-
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
|
2848
|
-
|
|
2849
|
-
if getv(from_object, ['code_execution_result']) is not None:
|
|
2851
|
+
if getv(from_object, ['inline_data']) is not None:
|
|
2850
2852
|
setv(
|
|
2851
2853
|
to_object,
|
|
2852
|
-
['
|
|
2853
|
-
getv(from_object, ['
|
|
2854
|
+
['inlineData'],
|
|
2855
|
+
_Blob_to_mldev(getv(from_object, ['inline_data']), to_object),
|
|
2854
2856
|
)
|
|
2855
2857
|
|
|
2856
|
-
if getv(from_object, ['
|
|
2857
|
-
setv(to_object, ['
|
|
2858
|
+
if getv(from_object, ['text']) is not None:
|
|
2859
|
+
setv(to_object, ['text'], getv(from_object, ['text']))
|
|
2858
2860
|
|
|
2859
|
-
if getv(from_object, ['
|
|
2861
|
+
if getv(from_object, ['thought']) is not None:
|
|
2862
|
+
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
|
2863
|
+
|
|
2864
|
+
if getv(from_object, ['thought_signature']) is not None:
|
|
2860
2865
|
setv(
|
|
2861
2866
|
to_object,
|
|
2862
|
-
['
|
|
2863
|
-
getv(from_object, ['
|
|
2867
|
+
['thoughtSignature'],
|
|
2868
|
+
getv(from_object, ['thought_signature']),
|
|
2864
2869
|
)
|
|
2865
2870
|
|
|
2866
|
-
if getv(from_object, ['
|
|
2867
|
-
setv(to_object, ['
|
|
2871
|
+
if getv(from_object, ['video_metadata']) is not None:
|
|
2872
|
+
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
|
|
2868
2873
|
|
|
2869
2874
|
return to_object
|
|
2870
2875
|
|
|
@@ -3136,12 +3141,12 @@ def _SafetySetting_to_mldev(
|
|
|
3136
3141
|
parent_object: Optional[dict[str, Any]] = None,
|
|
3137
3142
|
) -> dict[str, Any]:
|
|
3138
3143
|
to_object: dict[str, Any] = {}
|
|
3139
|
-
if getv(from_object, ['method']) is not None:
|
|
3140
|
-
raise ValueError('method parameter is not supported in Gemini API.')
|
|
3141
|
-
|
|
3142
3144
|
if getv(from_object, ['category']) is not None:
|
|
3143
3145
|
setv(to_object, ['category'], getv(from_object, ['category']))
|
|
3144
3146
|
|
|
3147
|
+
if getv(from_object, ['method']) is not None:
|
|
3148
|
+
raise ValueError('method parameter is not supported in Gemini API.')
|
|
3149
|
+
|
|
3145
3150
|
if getv(from_object, ['threshold']) is not None:
|
|
3146
3151
|
setv(to_object, ['threshold'], getv(from_object, ['threshold']))
|
|
3147
3152
|
|
|
@@ -3280,6 +3285,9 @@ def _SpeechConfig_to_vertex(
|
|
|
3280
3285
|
parent_object: Optional[dict[str, Any]] = None,
|
|
3281
3286
|
) -> dict[str, Any]:
|
|
3282
3287
|
to_object: dict[str, Any] = {}
|
|
3288
|
+
if getv(from_object, ['language_code']) is not None:
|
|
3289
|
+
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
|
|
3290
|
+
|
|
3283
3291
|
if getv(from_object, ['voice_config']) is not None:
|
|
3284
3292
|
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
|
|
3285
3293
|
|
|
@@ -3288,9 +3296,6 @@ def _SpeechConfig_to_vertex(
|
|
|
3288
3296
|
'multi_speaker_voice_config parameter is not supported in Vertex AI.'
|
|
3289
3297
|
)
|
|
3290
3298
|
|
|
3291
|
-
if getv(from_object, ['language_code']) is not None:
|
|
3292
|
-
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
|
|
3293
|
-
|
|
3294
3299
|
return to_object
|
|
3295
3300
|
|
|
3296
3301
|
|
|
@@ -3309,13 +3314,6 @@ def _Tool_to_mldev(
|
|
|
3309
3314
|
if getv(from_object, ['retrieval']) is not None:
|
|
3310
3315
|
raise ValueError('retrieval parameter is not supported in Gemini API.')
|
|
3311
3316
|
|
|
3312
|
-
if getv(from_object, ['google_search']) is not None:
|
|
3313
|
-
setv(
|
|
3314
|
-
to_object,
|
|
3315
|
-
['googleSearch'],
|
|
3316
|
-
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
|
|
3317
|
-
)
|
|
3318
|
-
|
|
3319
3317
|
if getv(from_object, ['google_search_retrieval']) is not None:
|
|
3320
3318
|
setv(
|
|
3321
3319
|
to_object,
|
|
@@ -3323,11 +3321,6 @@ def _Tool_to_mldev(
|
|
|
3323
3321
|
getv(from_object, ['google_search_retrieval']),
|
|
3324
3322
|
)
|
|
3325
3323
|
|
|
3326
|
-
if getv(from_object, ['enterprise_web_search']) is not None:
|
|
3327
|
-
raise ValueError(
|
|
3328
|
-
'enterprise_web_search parameter is not supported in Gemini API.'
|
|
3329
|
-
)
|
|
3330
|
-
|
|
3331
3324
|
if getv(from_object, ['google_maps']) is not None:
|
|
3332
3325
|
setv(
|
|
3333
3326
|
to_object,
|
|
@@ -3335,15 +3328,27 @@ def _Tool_to_mldev(
|
|
|
3335
3328
|
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
3336
3329
|
)
|
|
3337
3330
|
|
|
3338
|
-
if getv(from_object, ['url_context']) is not None:
|
|
3339
|
-
setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
|
|
3340
|
-
|
|
3341
3331
|
if getv(from_object, ['computer_use']) is not None:
|
|
3342
3332
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
3343
3333
|
|
|
3344
3334
|
if getv(from_object, ['code_execution']) is not None:
|
|
3345
3335
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
3346
3336
|
|
|
3337
|
+
if getv(from_object, ['enterprise_web_search']) is not None:
|
|
3338
|
+
raise ValueError(
|
|
3339
|
+
'enterprise_web_search parameter is not supported in Gemini API.'
|
|
3340
|
+
)
|
|
3341
|
+
|
|
3342
|
+
if getv(from_object, ['google_search']) is not None:
|
|
3343
|
+
setv(
|
|
3344
|
+
to_object,
|
|
3345
|
+
['googleSearch'],
|
|
3346
|
+
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
|
|
3347
|
+
)
|
|
3348
|
+
|
|
3349
|
+
if getv(from_object, ['url_context']) is not None:
|
|
3350
|
+
setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
|
|
3351
|
+
|
|
3347
3352
|
return to_object
|
|
3348
3353
|
|
|
3349
3354
|
|
|
@@ -3365,9 +3370,6 @@ def _Tool_to_vertex(
|
|
|
3365
3370
|
if getv(from_object, ['retrieval']) is not None:
|
|
3366
3371
|
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
|
|
3367
3372
|
|
|
3368
|
-
if getv(from_object, ['google_search']) is not None:
|
|
3369
|
-
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
|
|
3370
|
-
|
|
3371
3373
|
if getv(from_object, ['google_search_retrieval']) is not None:
|
|
3372
3374
|
setv(
|
|
3373
3375
|
to_object,
|
|
@@ -3375,6 +3377,15 @@ def _Tool_to_vertex(
|
|
|
3375
3377
|
getv(from_object, ['google_search_retrieval']),
|
|
3376
3378
|
)
|
|
3377
3379
|
|
|
3380
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
3381
|
+
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
|
|
3382
|
+
|
|
3383
|
+
if getv(from_object, ['computer_use']) is not None:
|
|
3384
|
+
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
3385
|
+
|
|
3386
|
+
if getv(from_object, ['code_execution']) is not None:
|
|
3387
|
+
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
3388
|
+
|
|
3378
3389
|
if getv(from_object, ['enterprise_web_search']) is not None:
|
|
3379
3390
|
setv(
|
|
3380
3391
|
to_object,
|
|
@@ -3382,18 +3393,12 @@ def _Tool_to_vertex(
|
|
|
3382
3393
|
getv(from_object, ['enterprise_web_search']),
|
|
3383
3394
|
)
|
|
3384
3395
|
|
|
3385
|
-
if getv(from_object, ['
|
|
3386
|
-
setv(to_object, ['
|
|
3396
|
+
if getv(from_object, ['google_search']) is not None:
|
|
3397
|
+
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
|
|
3387
3398
|
|
|
3388
3399
|
if getv(from_object, ['url_context']) is not None:
|
|
3389
3400
|
setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
|
|
3390
3401
|
|
|
3391
|
-
if getv(from_object, ['computer_use']) is not None:
|
|
3392
|
-
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
3393
|
-
|
|
3394
|
-
if getv(from_object, ['code_execution']) is not None:
|
|
3395
|
-
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
3396
|
-
|
|
3397
3402
|
return to_object
|
|
3398
3403
|
|
|
3399
3404
|
|
|
@@ -3516,6 +3521,20 @@ def _UpscaleImageAPIConfig_to_vertex(
|
|
|
3516
3521
|
getv(from_object, ['output_gcs_uri']),
|
|
3517
3522
|
)
|
|
3518
3523
|
|
|
3524
|
+
if getv(from_object, ['safety_filter_level']) is not None:
|
|
3525
|
+
setv(
|
|
3526
|
+
parent_object,
|
|
3527
|
+
['parameters', 'safetySetting'],
|
|
3528
|
+
getv(from_object, ['safety_filter_level']),
|
|
3529
|
+
)
|
|
3530
|
+
|
|
3531
|
+
if getv(from_object, ['person_generation']) is not None:
|
|
3532
|
+
setv(
|
|
3533
|
+
parent_object,
|
|
3534
|
+
['parameters', 'personGeneration'],
|
|
3535
|
+
getv(from_object, ['person_generation']),
|
|
3536
|
+
)
|
|
3537
|
+
|
|
3519
3538
|
if getv(from_object, ['include_rai_reason']) is not None:
|
|
3520
3539
|
setv(
|
|
3521
3540
|
parent_object,
|
|
@@ -4979,6 +4998,9 @@ class Models(_api_module.BaseModule):
|
|
|
4979
4998
|
# scones.
|
|
4980
4999
|
"""
|
|
4981
5000
|
|
|
5001
|
+
incompatible_tools_indexes = (
|
|
5002
|
+
_extra_utils.find_afc_incompatible_tool_indexes(config)
|
|
5003
|
+
)
|
|
4982
5004
|
parsed_config = _extra_utils.parse_config_for_mcp_usage(config)
|
|
4983
5005
|
if (
|
|
4984
5006
|
parsed_config
|
|
@@ -4992,6 +5014,28 @@ class Models(_api_module.BaseModule):
|
|
|
4992
5014
|
return self._generate_content(
|
|
4993
5015
|
model=model, contents=contents, config=parsed_config
|
|
4994
5016
|
)
|
|
5017
|
+
if incompatible_tools_indexes:
|
|
5018
|
+
original_tools_length = 0
|
|
5019
|
+
if isinstance(config, types.GenerateContentConfig):
|
|
5020
|
+
if config.tools:
|
|
5021
|
+
original_tools_length = len(config.tools)
|
|
5022
|
+
elif isinstance(config, dict):
|
|
5023
|
+
tools = config.get('tools', [])
|
|
5024
|
+
if tools:
|
|
5025
|
+
original_tools_length = len(tools)
|
|
5026
|
+
if len(incompatible_tools_indexes) != original_tools_length:
|
|
5027
|
+
indices_str = ', '.join(map(str, incompatible_tools_indexes))
|
|
5028
|
+
logger.warning(
|
|
5029
|
+
'Tools at indices [%s] are not compatible with automatic function '
|
|
5030
|
+
'calling (AFC). AFC is disabled. If AFC is intended, please '
|
|
5031
|
+
'include python callables in the tool list, and do not include '
|
|
5032
|
+
'function declaration in the tool list.',
|
|
5033
|
+
indices_str,
|
|
5034
|
+
)
|
|
5035
|
+
return self._generate_content(
|
|
5036
|
+
model=model, contents=contents, config=parsed_config
|
|
5037
|
+
)
|
|
5038
|
+
|
|
4995
5039
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
|
4996
5040
|
parsed_config
|
|
4997
5041
|
)
|
|
@@ -5115,6 +5159,9 @@ class Models(_api_module.BaseModule):
|
|
|
5115
5159
|
# scones.
|
|
5116
5160
|
"""
|
|
5117
5161
|
|
|
5162
|
+
incompatible_tools_indexes = (
|
|
5163
|
+
_extra_utils.find_afc_incompatible_tool_indexes(config)
|
|
5164
|
+
)
|
|
5118
5165
|
parsed_config = _extra_utils.parse_config_for_mcp_usage(config)
|
|
5119
5166
|
if (
|
|
5120
5167
|
parsed_config
|
|
@@ -5130,6 +5177,27 @@ class Models(_api_module.BaseModule):
|
|
|
5130
5177
|
)
|
|
5131
5178
|
return
|
|
5132
5179
|
|
|
5180
|
+
if incompatible_tools_indexes:
|
|
5181
|
+
original_tools_length = 0
|
|
5182
|
+
if isinstance(config, types.GenerateContentConfig):
|
|
5183
|
+
if config.tools:
|
|
5184
|
+
original_tools_length = len(config.tools)
|
|
5185
|
+
elif isinstance(config, dict):
|
|
5186
|
+
tools = config.get('tools', [])
|
|
5187
|
+
if tools:
|
|
5188
|
+
original_tools_length = len(tools)
|
|
5189
|
+
if len(incompatible_tools_indexes) != original_tools_length:
|
|
5190
|
+
indices_str = ', '.join(map(str, incompatible_tools_indexes))
|
|
5191
|
+
logger.warning(
|
|
5192
|
+
'Tools at indices [%s] are not compatible with automatic function '
|
|
5193
|
+
'calling. AFC will be disabled.',
|
|
5194
|
+
indices_str,
|
|
5195
|
+
)
|
|
5196
|
+
yield from self._generate_content_stream(
|
|
5197
|
+
model=model, contents=contents, config=parsed_config
|
|
5198
|
+
)
|
|
5199
|
+
return
|
|
5200
|
+
|
|
5133
5201
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
|
5134
5202
|
parsed_config
|
|
5135
5203
|
)
|
|
@@ -5154,7 +5222,7 @@ class Models(_api_module.BaseModule):
|
|
|
5154
5222
|
# Yield chunks only if there's no function response parts.
|
|
5155
5223
|
for chunk in response:
|
|
5156
5224
|
if not function_map:
|
|
5157
|
-
_extra_utils.append_chunk_contents(contents, chunk)
|
|
5225
|
+
contents = _extra_utils.append_chunk_contents(contents, chunk) # type: ignore[assignment]
|
|
5158
5226
|
yield chunk
|
|
5159
5227
|
else:
|
|
5160
5228
|
if (
|
|
@@ -5167,7 +5235,7 @@ class Models(_api_module.BaseModule):
|
|
|
5167
5235
|
chunk, function_map
|
|
5168
5236
|
)
|
|
5169
5237
|
if not func_response_parts:
|
|
5170
|
-
_extra_utils.append_chunk_contents(contents, chunk)
|
|
5238
|
+
contents = _extra_utils.append_chunk_contents(contents, chunk) # type: ignore[assignment]
|
|
5171
5239
|
yield chunk
|
|
5172
5240
|
|
|
5173
5241
|
else:
|
|
@@ -5177,7 +5245,7 @@ class Models(_api_module.BaseModule):
|
|
|
5177
5245
|
chunk.automatic_function_calling_history = (
|
|
5178
5246
|
automatic_function_calling_history
|
|
5179
5247
|
)
|
|
5180
|
-
_extra_utils.append_chunk_contents(contents, chunk)
|
|
5248
|
+
contents = _extra_utils.append_chunk_contents(contents, chunk) # type: ignore[assignment]
|
|
5181
5249
|
yield chunk
|
|
5182
5250
|
if (
|
|
5183
5251
|
chunk is None
|
|
@@ -5376,6 +5444,8 @@ class Models(_api_module.BaseModule):
|
|
|
5376
5444
|
api_config = types._UpscaleImageAPIConfigDict(
|
|
5377
5445
|
http_options=config_dct.get('http_options', None),
|
|
5378
5446
|
output_gcs_uri=config_dct.get('output_gcs_uri', None),
|
|
5447
|
+
safety_filter_level=config_dct.get('safety_filter_level', None),
|
|
5448
|
+
person_generation=config_dct.get('person_generation', None),
|
|
5379
5449
|
include_rai_reason=config_dct.get('include_rai_reason', None),
|
|
5380
5450
|
output_mime_type=config_dct.get('output_mime_type', None),
|
|
5381
5451
|
output_compression_quality=config_dct.get(
|
|
@@ -6743,6 +6813,9 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6743
6813
|
# J'aime les bagels.
|
|
6744
6814
|
"""
|
|
6745
6815
|
# Retrieve and cache any MCP sessions if provided.
|
|
6816
|
+
incompatible_tools_indexes = (
|
|
6817
|
+
_extra_utils.find_afc_incompatible_tool_indexes(config)
|
|
6818
|
+
)
|
|
6746
6819
|
parsed_config, mcp_to_genai_tool_adapters = (
|
|
6747
6820
|
await _extra_utils.parse_config_for_mcp_sessions(config)
|
|
6748
6821
|
)
|
|
@@ -6750,6 +6823,27 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6750
6823
|
return await self._generate_content(
|
|
6751
6824
|
model=model, contents=contents, config=parsed_config
|
|
6752
6825
|
)
|
|
6826
|
+
if incompatible_tools_indexes:
|
|
6827
|
+
original_tools_length = 0
|
|
6828
|
+
if isinstance(config, types.GenerateContentConfig):
|
|
6829
|
+
if config.tools:
|
|
6830
|
+
original_tools_length = len(config.tools)
|
|
6831
|
+
elif isinstance(config, dict):
|
|
6832
|
+
tools = config.get('tools', [])
|
|
6833
|
+
if tools:
|
|
6834
|
+
original_tools_length = len(tools)
|
|
6835
|
+
if len(incompatible_tools_indexes) != original_tools_length:
|
|
6836
|
+
indices_str = ', '.join(map(str, incompatible_tools_indexes))
|
|
6837
|
+
logger.warning(
|
|
6838
|
+
'Tools at indices [%s] are not compatible with automatic function '
|
|
6839
|
+
'calling (AFC). AFC is disabled. If AFC is intended, please '
|
|
6840
|
+
'include python callables in the tool list, and do not include '
|
|
6841
|
+
'function declaration in the tool list.',
|
|
6842
|
+
indices_str,
|
|
6843
|
+
)
|
|
6844
|
+
return await self._generate_content(
|
|
6845
|
+
model=model, contents=contents, config=parsed_config
|
|
6846
|
+
)
|
|
6753
6847
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
|
6754
6848
|
parsed_config
|
|
6755
6849
|
)
|
|
@@ -6874,6 +6968,10 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6874
6968
|
# scones.
|
|
6875
6969
|
"""
|
|
6876
6970
|
|
|
6971
|
+
# Retrieve and cache any MCP sessions if provided.
|
|
6972
|
+
incompatible_tools_indexes = (
|
|
6973
|
+
_extra_utils.find_afc_incompatible_tool_indexes(config)
|
|
6974
|
+
)
|
|
6877
6975
|
# Retrieve and cache any MCP sessions if provided.
|
|
6878
6976
|
parsed_config, mcp_to_genai_tool_adapters = (
|
|
6879
6977
|
await _extra_utils.parse_config_for_mcp_sessions(config)
|
|
@@ -6889,6 +6987,34 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6889
6987
|
|
|
6890
6988
|
return base_async_generator(model, contents, parsed_config) # type: ignore[no-untyped-call, no-any-return]
|
|
6891
6989
|
|
|
6990
|
+
if incompatible_tools_indexes:
|
|
6991
|
+
original_tools_length = 0
|
|
6992
|
+
if isinstance(config, types.GenerateContentConfig):
|
|
6993
|
+
if config.tools:
|
|
6994
|
+
original_tools_length = len(config.tools)
|
|
6995
|
+
elif isinstance(config, dict):
|
|
6996
|
+
tools = config.get('tools', [])
|
|
6997
|
+
if tools:
|
|
6998
|
+
original_tools_length = len(tools)
|
|
6999
|
+
if len(incompatible_tools_indexes) != original_tools_length:
|
|
7000
|
+
indices_str = ', '.join(map(str, incompatible_tools_indexes))
|
|
7001
|
+
logger.warning(
|
|
7002
|
+
'Tools at indices [%s] are not compatible with automatic function '
|
|
7003
|
+
'calling (AFC). AFC is disabled. If AFC is intended, please '
|
|
7004
|
+
'include python callables in the tool list, and do not include '
|
|
7005
|
+
'function declaration in the tool list.',
|
|
7006
|
+
indices_str,
|
|
7007
|
+
)
|
|
7008
|
+
response = await self._generate_content_stream(
|
|
7009
|
+
model=model, contents=contents, config=parsed_config
|
|
7010
|
+
)
|
|
7011
|
+
|
|
7012
|
+
async def base_async_generator(model, contents, config): # type: ignore[no-untyped-def]
|
|
7013
|
+
async for chunk in response: # type: ignore[attr-defined]
|
|
7014
|
+
yield chunk
|
|
7015
|
+
|
|
7016
|
+
return base_async_generator(model, contents, parsed_config) # type: ignore[no-untyped-call, no-any-return]
|
|
7017
|
+
|
|
6892
7018
|
async def async_generator(model, contents, config): # type: ignore[no-untyped-def]
|
|
6893
7019
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(config)
|
|
6894
7020
|
logger.info(
|
|
@@ -6922,7 +7048,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6922
7048
|
# Yield chunks only if there's no function response parts.
|
|
6923
7049
|
async for chunk in response: # type: ignore[attr-defined]
|
|
6924
7050
|
if not function_map:
|
|
6925
|
-
_extra_utils.append_chunk_contents(contents, chunk)
|
|
7051
|
+
contents = _extra_utils.append_chunk_contents(contents, chunk)
|
|
6926
7052
|
yield chunk
|
|
6927
7053
|
else:
|
|
6928
7054
|
if (
|
|
@@ -6937,7 +7063,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6937
7063
|
)
|
|
6938
7064
|
)
|
|
6939
7065
|
if not func_response_parts:
|
|
6940
|
-
_extra_utils.append_chunk_contents(contents, chunk)
|
|
7066
|
+
contents = _extra_utils.append_chunk_contents(contents, chunk)
|
|
6941
7067
|
yield chunk
|
|
6942
7068
|
|
|
6943
7069
|
else:
|
|
@@ -6948,7 +7074,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
6948
7074
|
chunk.automatic_function_calling_history = (
|
|
6949
7075
|
automatic_function_calling_history
|
|
6950
7076
|
)
|
|
6951
|
-
_extra_utils.append_chunk_contents(contents, chunk)
|
|
7077
|
+
contents = _extra_utils.append_chunk_contents(contents, chunk)
|
|
6952
7078
|
yield chunk
|
|
6953
7079
|
if (
|
|
6954
7080
|
chunk is None
|
|
@@ -7200,6 +7326,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
|
7200
7326
|
api_config = types._UpscaleImageAPIConfigDict(
|
|
7201
7327
|
http_options=config_dct.get('http_options', None),
|
|
7202
7328
|
output_gcs_uri=config_dct.get('output_gcs_uri', None),
|
|
7329
|
+
safety_filter_level=config_dct.get('safety_filter_level', None),
|
|
7330
|
+
person_generation=config_dct.get('person_generation', None),
|
|
7203
7331
|
include_rai_reason=config_dct.get('include_rai_reason', None),
|
|
7204
7332
|
output_mime_type=config_dct.get('output_mime_type', None),
|
|
7205
7333
|
output_compression_quality=config_dct.get(
|