google-genai 1.15.0__py3-none-any.whl → 1.16.1__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/__init__.py +5 -3
- google/genai/_adapters.py +55 -0
- google/genai/_api_client.py +3 -3
- google/genai/_api_module.py +1 -1
- google/genai/_automatic_function_calling_util.py +1 -1
- google/genai/_common.py +1 -1
- google/genai/_extra_utils.py +114 -9
- google/genai/_live_converters.py +1295 -20
- google/genai/_mcp_utils.py +117 -0
- google/genai/_replay_api_client.py +1 -1
- google/genai/_test_api_client.py +1 -1
- google/genai/_tokens_converters.py +1701 -0
- google/genai/_transformers.py +66 -33
- google/genai/caches.py +223 -20
- google/genai/chats.py +1 -1
- google/genai/client.py +12 -1
- google/genai/errors.py +1 -1
- google/genai/live.py +218 -35
- google/genai/live_music.py +201 -0
- google/genai/models.py +505 -44
- google/genai/pagers.py +1 -1
- google/genai/tokens.py +357 -0
- google/genai/types.py +7887 -6765
- google/genai/version.py +2 -2
- {google_genai-1.15.0.dist-info → google_genai-1.16.1.dist-info}/METADATA +8 -4
- google_genai-1.16.1.dist-info/RECORD +35 -0
- {google_genai-1.15.0.dist-info → google_genai-1.16.1.dist-info}/WHEEL +1 -1
- google_genai-1.15.0.dist-info/RECORD +0 -30
- {google_genai-1.15.0.dist-info → google_genai-1.16.1.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.15.0.dist-info → google_genai-1.16.1.dist-info}/top_level.txt +0 -0
google/genai/models.py
CHANGED
@@ -21,7 +21,9 @@ from urllib.parse import urlencode
|
|
21
21
|
from . import _api_module
|
22
22
|
from . import _common
|
23
23
|
from . import _extra_utils
|
24
|
+
from . import _mcp_utils
|
24
25
|
from . import _transformers as t
|
26
|
+
from . import errors
|
25
27
|
from . import types
|
26
28
|
from ._api_client import BaseApiClient
|
27
29
|
from ._common import get_value_by_path as getv
|
@@ -31,6 +33,24 @@ from .pagers import AsyncPager, Pager
|
|
31
33
|
logger = logging.getLogger('google_genai.models')
|
32
34
|
|
33
35
|
|
36
|
+
def _VideoMetadata_to_mldev(
|
37
|
+
api_client: BaseApiClient,
|
38
|
+
from_object: Union[dict[str, Any], object],
|
39
|
+
parent_object: Optional[dict[str, Any]] = None,
|
40
|
+
) -> dict[str, Any]:
|
41
|
+
to_object: dict[str, Any] = {}
|
42
|
+
if getv(from_object, ['fps']) is not None:
|
43
|
+
setv(to_object, ['fps'], getv(from_object, ['fps']))
|
44
|
+
|
45
|
+
if getv(from_object, ['end_offset']) is not None:
|
46
|
+
setv(to_object, ['endOffset'], getv(from_object, ['end_offset']))
|
47
|
+
|
48
|
+
if getv(from_object, ['start_offset']) is not None:
|
49
|
+
setv(to_object, ['startOffset'], getv(from_object, ['start_offset']))
|
50
|
+
|
51
|
+
return to_object
|
52
|
+
|
53
|
+
|
34
54
|
def _Blob_to_mldev(
|
35
55
|
api_client: BaseApiClient,
|
36
56
|
from_object: Union[dict[str, Any], object],
|
@@ -56,7 +76,13 @@ def _Part_to_mldev(
|
|
56
76
|
) -> dict[str, Any]:
|
57
77
|
to_object: dict[str, Any] = {}
|
58
78
|
if getv(from_object, ['video_metadata']) is not None:
|
59
|
-
|
79
|
+
setv(
|
80
|
+
to_object,
|
81
|
+
['videoMetadata'],
|
82
|
+
_VideoMetadata_to_mldev(
|
83
|
+
api_client, getv(from_object, ['video_metadata']), to_object
|
84
|
+
),
|
85
|
+
)
|
60
86
|
|
61
87
|
if getv(from_object, ['thought']) is not None:
|
62
88
|
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
@@ -153,12 +179,59 @@ def _SafetySetting_to_mldev(
|
|
153
179
|
return to_object
|
154
180
|
|
155
181
|
|
182
|
+
def _FunctionDeclaration_to_mldev(
|
183
|
+
api_client: BaseApiClient,
|
184
|
+
from_object: Union[dict[str, Any], object],
|
185
|
+
parent_object: Optional[dict[str, Any]] = None,
|
186
|
+
) -> dict[str, Any]:
|
187
|
+
to_object: dict[str, Any] = {}
|
188
|
+
if getv(from_object, ['behavior']) is not None:
|
189
|
+
setv(to_object, ['behavior'], getv(from_object, ['behavior']))
|
190
|
+
|
191
|
+
if getv(from_object, ['description']) is not None:
|
192
|
+
setv(to_object, ['description'], getv(from_object, ['description']))
|
193
|
+
|
194
|
+
if getv(from_object, ['name']) is not None:
|
195
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
196
|
+
|
197
|
+
if getv(from_object, ['parameters']) is not None:
|
198
|
+
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
|
199
|
+
|
200
|
+
if getv(from_object, ['response']) is not None:
|
201
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
202
|
+
|
203
|
+
return to_object
|
204
|
+
|
205
|
+
|
206
|
+
def _Interval_to_mldev(
|
207
|
+
api_client: BaseApiClient,
|
208
|
+
from_object: Union[dict[str, Any], object],
|
209
|
+
parent_object: Optional[dict[str, Any]] = None,
|
210
|
+
) -> dict[str, Any]:
|
211
|
+
to_object: dict[str, Any] = {}
|
212
|
+
if getv(from_object, ['start_time']) is not None:
|
213
|
+
setv(to_object, ['startTime'], getv(from_object, ['start_time']))
|
214
|
+
|
215
|
+
if getv(from_object, ['end_time']) is not None:
|
216
|
+
setv(to_object, ['endTime'], getv(from_object, ['end_time']))
|
217
|
+
|
218
|
+
return to_object
|
219
|
+
|
220
|
+
|
156
221
|
def _GoogleSearch_to_mldev(
|
157
222
|
api_client: BaseApiClient,
|
158
223
|
from_object: Union[dict[str, Any], object],
|
159
224
|
parent_object: Optional[dict[str, Any]] = None,
|
160
225
|
) -> dict[str, Any]:
|
161
226
|
to_object: dict[str, Any] = {}
|
227
|
+
if getv(from_object, ['time_range_filter']) is not None:
|
228
|
+
setv(
|
229
|
+
to_object,
|
230
|
+
['timeRangeFilter'],
|
231
|
+
_Interval_to_mldev(
|
232
|
+
api_client, getv(from_object, ['time_range_filter']), to_object
|
233
|
+
),
|
234
|
+
)
|
162
235
|
|
163
236
|
return to_object
|
164
237
|
|
@@ -271,12 +344,32 @@ def _GoogleMaps_to_mldev(
|
|
271
344
|
return to_object
|
272
345
|
|
273
346
|
|
347
|
+
def _UrlContext_to_mldev(
|
348
|
+
api_client: BaseApiClient,
|
349
|
+
from_object: Union[dict[str, Any], object],
|
350
|
+
parent_object: Optional[dict[str, Any]] = None,
|
351
|
+
) -> dict[str, Any]:
|
352
|
+
to_object: dict[str, Any] = {}
|
353
|
+
|
354
|
+
return to_object
|
355
|
+
|
356
|
+
|
274
357
|
def _Tool_to_mldev(
|
275
358
|
api_client: BaseApiClient,
|
276
359
|
from_object: Union[dict[str, Any], object],
|
277
360
|
parent_object: Optional[dict[str, Any]] = None,
|
278
361
|
) -> dict[str, Any]:
|
279
362
|
to_object: dict[str, Any] = {}
|
363
|
+
if getv(from_object, ['function_declarations']) is not None:
|
364
|
+
setv(
|
365
|
+
to_object,
|
366
|
+
['functionDeclarations'],
|
367
|
+
[
|
368
|
+
_FunctionDeclaration_to_mldev(api_client, item, to_object)
|
369
|
+
for item in getv(from_object, ['function_declarations'])
|
370
|
+
],
|
371
|
+
)
|
372
|
+
|
280
373
|
if getv(from_object, ['retrieval']) is not None:
|
281
374
|
raise ValueError('retrieval parameter is not supported in Gemini API.')
|
282
375
|
|
@@ -308,16 +401,18 @@ def _Tool_to_mldev(
|
|
308
401
|
if getv(from_object, ['google_maps']) is not None:
|
309
402
|
raise ValueError('google_maps parameter is not supported in Gemini API.')
|
310
403
|
|
311
|
-
if getv(from_object, ['
|
312
|
-
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
313
|
-
|
314
|
-
if getv(from_object, ['function_declarations']) is not None:
|
404
|
+
if getv(from_object, ['url_context']) is not None:
|
315
405
|
setv(
|
316
406
|
to_object,
|
317
|
-
['
|
318
|
-
|
407
|
+
['urlContext'],
|
408
|
+
_UrlContext_to_mldev(
|
409
|
+
api_client, getv(from_object, ['url_context']), to_object
|
410
|
+
),
|
319
411
|
)
|
320
412
|
|
413
|
+
if getv(from_object, ['code_execution']) is not None:
|
414
|
+
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
415
|
+
|
321
416
|
return to_object
|
322
417
|
|
323
418
|
|
@@ -347,10 +442,10 @@ def _LatLng_to_mldev(
|
|
347
442
|
) -> dict[str, Any]:
|
348
443
|
to_object: dict[str, Any] = {}
|
349
444
|
if getv(from_object, ['latitude']) is not None:
|
350
|
-
|
445
|
+
setv(to_object, ['latitude'], getv(from_object, ['latitude']))
|
351
446
|
|
352
447
|
if getv(from_object, ['longitude']) is not None:
|
353
|
-
|
448
|
+
setv(to_object, ['longitude'], getv(from_object, ['longitude']))
|
354
449
|
|
355
450
|
return to_object
|
356
451
|
|
@@ -362,7 +457,11 @@ def _RetrievalConfig_to_mldev(
|
|
362
457
|
) -> dict[str, Any]:
|
363
458
|
to_object: dict[str, Any] = {}
|
364
459
|
if getv(from_object, ['lat_lng']) is not None:
|
365
|
-
|
460
|
+
setv(
|
461
|
+
to_object,
|
462
|
+
['latLng'],
|
463
|
+
_LatLng_to_mldev(api_client, getv(from_object, ['lat_lng']), to_object),
|
464
|
+
)
|
366
465
|
|
367
466
|
return to_object
|
368
467
|
|
@@ -385,8 +484,12 @@ def _ToolConfig_to_mldev(
|
|
385
484
|
)
|
386
485
|
|
387
486
|
if getv(from_object, ['retrieval_config']) is not None:
|
388
|
-
|
389
|
-
|
487
|
+
setv(
|
488
|
+
to_object,
|
489
|
+
['retrievalConfig'],
|
490
|
+
_RetrievalConfig_to_mldev(
|
491
|
+
api_client, getv(from_object, ['retrieval_config']), to_object
|
492
|
+
),
|
390
493
|
)
|
391
494
|
|
392
495
|
return to_object
|
@@ -422,6 +525,46 @@ def _VoiceConfig_to_mldev(
|
|
422
525
|
return to_object
|
423
526
|
|
424
527
|
|
528
|
+
def _SpeakerVoiceConfig_to_mldev(
|
529
|
+
api_client: BaseApiClient,
|
530
|
+
from_object: Union[dict[str, Any], object],
|
531
|
+
parent_object: Optional[dict[str, Any]] = None,
|
532
|
+
) -> dict[str, Any]:
|
533
|
+
to_object: dict[str, Any] = {}
|
534
|
+
if getv(from_object, ['speaker']) is not None:
|
535
|
+
setv(to_object, ['speaker'], getv(from_object, ['speaker']))
|
536
|
+
|
537
|
+
if getv(from_object, ['voice_config']) is not None:
|
538
|
+
setv(
|
539
|
+
to_object,
|
540
|
+
['voiceConfig'],
|
541
|
+
_VoiceConfig_to_mldev(
|
542
|
+
api_client, getv(from_object, ['voice_config']), to_object
|
543
|
+
),
|
544
|
+
)
|
545
|
+
|
546
|
+
return to_object
|
547
|
+
|
548
|
+
|
549
|
+
def _MultiSpeakerVoiceConfig_to_mldev(
|
550
|
+
api_client: BaseApiClient,
|
551
|
+
from_object: Union[dict[str, Any], object],
|
552
|
+
parent_object: Optional[dict[str, Any]] = None,
|
553
|
+
) -> dict[str, Any]:
|
554
|
+
to_object: dict[str, Any] = {}
|
555
|
+
if getv(from_object, ['speaker_voice_configs']) is not None:
|
556
|
+
setv(
|
557
|
+
to_object,
|
558
|
+
['speakerVoiceConfigs'],
|
559
|
+
[
|
560
|
+
_SpeakerVoiceConfig_to_mldev(api_client, item, to_object)
|
561
|
+
for item in getv(from_object, ['speaker_voice_configs'])
|
562
|
+
],
|
563
|
+
)
|
564
|
+
|
565
|
+
return to_object
|
566
|
+
|
567
|
+
|
425
568
|
def _SpeechConfig_to_mldev(
|
426
569
|
api_client: BaseApiClient,
|
427
570
|
from_object: Union[dict[str, Any], object],
|
@@ -437,6 +580,17 @@ def _SpeechConfig_to_mldev(
|
|
437
580
|
),
|
438
581
|
)
|
439
582
|
|
583
|
+
if getv(from_object, ['multi_speaker_voice_config']) is not None:
|
584
|
+
setv(
|
585
|
+
to_object,
|
586
|
+
['multiSpeakerVoiceConfig'],
|
587
|
+
_MultiSpeakerVoiceConfig_to_mldev(
|
588
|
+
api_client,
|
589
|
+
getv(from_object, ['multi_speaker_voice_config']),
|
590
|
+
to_object,
|
591
|
+
),
|
592
|
+
)
|
593
|
+
|
440
594
|
if getv(from_object, ['language_code']) is not None:
|
441
595
|
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
|
442
596
|
|
@@ -1180,6 +1334,24 @@ def _GenerateVideosParameters_to_mldev(
|
|
1180
1334
|
return to_object
|
1181
1335
|
|
1182
1336
|
|
1337
|
+
def _VideoMetadata_to_vertex(
|
1338
|
+
api_client: BaseApiClient,
|
1339
|
+
from_object: Union[dict[str, Any], object],
|
1340
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1341
|
+
) -> dict[str, Any]:
|
1342
|
+
to_object: dict[str, Any] = {}
|
1343
|
+
if getv(from_object, ['fps']) is not None:
|
1344
|
+
setv(to_object, ['fps'], getv(from_object, ['fps']))
|
1345
|
+
|
1346
|
+
if getv(from_object, ['end_offset']) is not None:
|
1347
|
+
setv(to_object, ['endOffset'], getv(from_object, ['end_offset']))
|
1348
|
+
|
1349
|
+
if getv(from_object, ['start_offset']) is not None:
|
1350
|
+
setv(to_object, ['startOffset'], getv(from_object, ['start_offset']))
|
1351
|
+
|
1352
|
+
return to_object
|
1353
|
+
|
1354
|
+
|
1183
1355
|
def _Blob_to_vertex(
|
1184
1356
|
api_client: BaseApiClient,
|
1185
1357
|
from_object: Union[dict[str, Any], object],
|
@@ -1205,7 +1377,13 @@ def _Part_to_vertex(
|
|
1205
1377
|
) -> dict[str, Any]:
|
1206
1378
|
to_object: dict[str, Any] = {}
|
1207
1379
|
if getv(from_object, ['video_metadata']) is not None:
|
1208
|
-
setv(
|
1380
|
+
setv(
|
1381
|
+
to_object,
|
1382
|
+
['videoMetadata'],
|
1383
|
+
_VideoMetadata_to_vertex(
|
1384
|
+
api_client, getv(from_object, ['video_metadata']), to_object
|
1385
|
+
),
|
1386
|
+
)
|
1209
1387
|
|
1210
1388
|
if getv(from_object, ['thought']) is not None:
|
1211
1389
|
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
@@ -1304,12 +1482,59 @@ def _SafetySetting_to_vertex(
|
|
1304
1482
|
return to_object
|
1305
1483
|
|
1306
1484
|
|
1485
|
+
def _FunctionDeclaration_to_vertex(
|
1486
|
+
api_client: BaseApiClient,
|
1487
|
+
from_object: Union[dict[str, Any], object],
|
1488
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1489
|
+
) -> dict[str, Any]:
|
1490
|
+
to_object: dict[str, Any] = {}
|
1491
|
+
if getv(from_object, ['behavior']) is not None:
|
1492
|
+
raise ValueError('behavior parameter is not supported in Vertex AI.')
|
1493
|
+
|
1494
|
+
if getv(from_object, ['description']) is not None:
|
1495
|
+
setv(to_object, ['description'], getv(from_object, ['description']))
|
1496
|
+
|
1497
|
+
if getv(from_object, ['name']) is not None:
|
1498
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
1499
|
+
|
1500
|
+
if getv(from_object, ['parameters']) is not None:
|
1501
|
+
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
|
1502
|
+
|
1503
|
+
if getv(from_object, ['response']) is not None:
|
1504
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
1505
|
+
|
1506
|
+
return to_object
|
1507
|
+
|
1508
|
+
|
1509
|
+
def _Interval_to_vertex(
|
1510
|
+
api_client: BaseApiClient,
|
1511
|
+
from_object: Union[dict[str, Any], object],
|
1512
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1513
|
+
) -> dict[str, Any]:
|
1514
|
+
to_object: dict[str, Any] = {}
|
1515
|
+
if getv(from_object, ['start_time']) is not None:
|
1516
|
+
setv(to_object, ['startTime'], getv(from_object, ['start_time']))
|
1517
|
+
|
1518
|
+
if getv(from_object, ['end_time']) is not None:
|
1519
|
+
setv(to_object, ['endTime'], getv(from_object, ['end_time']))
|
1520
|
+
|
1521
|
+
return to_object
|
1522
|
+
|
1523
|
+
|
1307
1524
|
def _GoogleSearch_to_vertex(
|
1308
1525
|
api_client: BaseApiClient,
|
1309
1526
|
from_object: Union[dict[str, Any], object],
|
1310
1527
|
parent_object: Optional[dict[str, Any]] = None,
|
1311
1528
|
) -> dict[str, Any]:
|
1312
1529
|
to_object: dict[str, Any] = {}
|
1530
|
+
if getv(from_object, ['time_range_filter']) is not None:
|
1531
|
+
setv(
|
1532
|
+
to_object,
|
1533
|
+
['timeRangeFilter'],
|
1534
|
+
_Interval_to_vertex(
|
1535
|
+
api_client, getv(from_object, ['time_range_filter']), to_object
|
1536
|
+
),
|
1537
|
+
)
|
1313
1538
|
|
1314
1539
|
return to_object
|
1315
1540
|
|
@@ -1434,12 +1659,32 @@ def _GoogleMaps_to_vertex(
|
|
1434
1659
|
return to_object
|
1435
1660
|
|
1436
1661
|
|
1662
|
+
def _UrlContext_to_vertex(
|
1663
|
+
api_client: BaseApiClient,
|
1664
|
+
from_object: Union[dict[str, Any], object],
|
1665
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1666
|
+
) -> dict[str, Any]:
|
1667
|
+
to_object: dict[str, Any] = {}
|
1668
|
+
|
1669
|
+
return to_object
|
1670
|
+
|
1671
|
+
|
1437
1672
|
def _Tool_to_vertex(
|
1438
1673
|
api_client: BaseApiClient,
|
1439
1674
|
from_object: Union[dict[str, Any], object],
|
1440
1675
|
parent_object: Optional[dict[str, Any]] = None,
|
1441
1676
|
) -> dict[str, Any]:
|
1442
1677
|
to_object: dict[str, Any] = {}
|
1678
|
+
if getv(from_object, ['function_declarations']) is not None:
|
1679
|
+
setv(
|
1680
|
+
to_object,
|
1681
|
+
['functionDeclarations'],
|
1682
|
+
[
|
1683
|
+
_FunctionDeclaration_to_vertex(api_client, item, to_object)
|
1684
|
+
for item in getv(from_object, ['function_declarations'])
|
1685
|
+
],
|
1686
|
+
)
|
1687
|
+
|
1443
1688
|
if getv(from_object, ['retrieval']) is not None:
|
1444
1689
|
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
|
1445
1690
|
|
@@ -1481,16 +1726,12 @@ def _Tool_to_vertex(
|
|
1481
1726
|
),
|
1482
1727
|
)
|
1483
1728
|
|
1729
|
+
if getv(from_object, ['url_context']) is not None:
|
1730
|
+
raise ValueError('url_context parameter is not supported in Vertex AI.')
|
1731
|
+
|
1484
1732
|
if getv(from_object, ['code_execution']) is not None:
|
1485
1733
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
1486
1734
|
|
1487
|
-
if getv(from_object, ['function_declarations']) is not None:
|
1488
|
-
setv(
|
1489
|
-
to_object,
|
1490
|
-
['functionDeclarations'],
|
1491
|
-
getv(from_object, ['function_declarations']),
|
1492
|
-
)
|
1493
|
-
|
1494
1735
|
return to_object
|
1495
1736
|
|
1496
1737
|
|
@@ -1605,6 +1846,35 @@ def _VoiceConfig_to_vertex(
|
|
1605
1846
|
return to_object
|
1606
1847
|
|
1607
1848
|
|
1849
|
+
def _SpeakerVoiceConfig_to_vertex(
|
1850
|
+
api_client: BaseApiClient,
|
1851
|
+
from_object: Union[dict[str, Any], object],
|
1852
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1853
|
+
) -> dict[str, Any]:
|
1854
|
+
to_object: dict[str, Any] = {}
|
1855
|
+
if getv(from_object, ['speaker']) is not None:
|
1856
|
+
raise ValueError('speaker parameter is not supported in Vertex AI.')
|
1857
|
+
|
1858
|
+
if getv(from_object, ['voice_config']) is not None:
|
1859
|
+
raise ValueError('voice_config parameter is not supported in Vertex AI.')
|
1860
|
+
|
1861
|
+
return to_object
|
1862
|
+
|
1863
|
+
|
1864
|
+
def _MultiSpeakerVoiceConfig_to_vertex(
|
1865
|
+
api_client: BaseApiClient,
|
1866
|
+
from_object: Union[dict[str, Any], object],
|
1867
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1868
|
+
) -> dict[str, Any]:
|
1869
|
+
to_object: dict[str, Any] = {}
|
1870
|
+
if getv(from_object, ['speaker_voice_configs']) is not None:
|
1871
|
+
raise ValueError(
|
1872
|
+
'speaker_voice_configs parameter is not supported in Vertex AI.'
|
1873
|
+
)
|
1874
|
+
|
1875
|
+
return to_object
|
1876
|
+
|
1877
|
+
|
1608
1878
|
def _SpeechConfig_to_vertex(
|
1609
1879
|
api_client: BaseApiClient,
|
1610
1880
|
from_object: Union[dict[str, Any], object],
|
@@ -1620,6 +1890,11 @@ def _SpeechConfig_to_vertex(
|
|
1620
1890
|
),
|
1621
1891
|
)
|
1622
1892
|
|
1893
|
+
if getv(from_object, ['multi_speaker_voice_config']) is not None:
|
1894
|
+
raise ValueError(
|
1895
|
+
'multi_speaker_voice_config parameter is not supported in Vertex AI.'
|
1896
|
+
)
|
1897
|
+
|
1623
1898
|
if getv(from_object, ['language_code']) is not None:
|
1624
1899
|
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
|
1625
1900
|
|
@@ -2821,6 +3096,29 @@ def _PersonGeneration_to_mldev_enum_validate(enum_value: Any) -> None:
|
|
2821
3096
|
raise ValueError(f'{enum_value} enum value is not supported in Gemini API.')
|
2822
3097
|
|
2823
3098
|
|
3099
|
+
def _Behavior_to_vertex_enum_validate(enum_value: Any) -> None:
|
3100
|
+
if enum_value in set(['UNSPECIFIED', 'BLOCKING', 'NON_BLOCKING']):
|
3101
|
+
raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
|
3102
|
+
|
3103
|
+
|
3104
|
+
def _VideoMetadata_from_mldev(
|
3105
|
+
api_client: BaseApiClient,
|
3106
|
+
from_object: Union[dict[str, Any], object],
|
3107
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3108
|
+
) -> dict[str, Any]:
|
3109
|
+
to_object: dict[str, Any] = {}
|
3110
|
+
if getv(from_object, ['fps']) is not None:
|
3111
|
+
setv(to_object, ['fps'], getv(from_object, ['fps']))
|
3112
|
+
|
3113
|
+
if getv(from_object, ['endOffset']) is not None:
|
3114
|
+
setv(to_object, ['end_offset'], getv(from_object, ['endOffset']))
|
3115
|
+
|
3116
|
+
if getv(from_object, ['startOffset']) is not None:
|
3117
|
+
setv(to_object, ['start_offset'], getv(from_object, ['startOffset']))
|
3118
|
+
|
3119
|
+
return to_object
|
3120
|
+
|
3121
|
+
|
2824
3122
|
def _Blob_from_mldev(
|
2825
3123
|
api_client: BaseApiClient,
|
2826
3124
|
from_object: Union[dict[str, Any], object],
|
@@ -2843,6 +3141,14 @@ def _Part_from_mldev(
|
|
2843
3141
|
parent_object: Optional[dict[str, Any]] = None,
|
2844
3142
|
) -> dict[str, Any]:
|
2845
3143
|
to_object: dict[str, Any] = {}
|
3144
|
+
if getv(from_object, ['videoMetadata']) is not None:
|
3145
|
+
setv(
|
3146
|
+
to_object,
|
3147
|
+
['video_metadata'],
|
3148
|
+
_VideoMetadata_from_mldev(
|
3149
|
+
api_client, getv(from_object, ['videoMetadata']), to_object
|
3150
|
+
),
|
3151
|
+
)
|
2846
3152
|
|
2847
3153
|
if getv(from_object, ['thought']) is not None:
|
2848
3154
|
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
@@ -2919,6 +3225,44 @@ def _CitationMetadata_from_mldev(
|
|
2919
3225
|
return to_object
|
2920
3226
|
|
2921
3227
|
|
3228
|
+
def _UrlMetadata_from_mldev(
|
3229
|
+
api_client: BaseApiClient,
|
3230
|
+
from_object: Union[dict[str, Any], object],
|
3231
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3232
|
+
) -> dict[str, Any]:
|
3233
|
+
to_object: dict[str, Any] = {}
|
3234
|
+
if getv(from_object, ['retrievedUrl']) is not None:
|
3235
|
+
setv(to_object, ['retrieved_url'], getv(from_object, ['retrievedUrl']))
|
3236
|
+
|
3237
|
+
if getv(from_object, ['urlRetrievalStatus']) is not None:
|
3238
|
+
setv(
|
3239
|
+
to_object,
|
3240
|
+
['url_retrieval_status'],
|
3241
|
+
getv(from_object, ['urlRetrievalStatus']),
|
3242
|
+
)
|
3243
|
+
|
3244
|
+
return to_object
|
3245
|
+
|
3246
|
+
|
3247
|
+
def _UrlContextMetadata_from_mldev(
|
3248
|
+
api_client: BaseApiClient,
|
3249
|
+
from_object: Union[dict[str, Any], object],
|
3250
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3251
|
+
) -> dict[str, Any]:
|
3252
|
+
to_object: dict[str, Any] = {}
|
3253
|
+
if getv(from_object, ['urlMetadata']) is not None:
|
3254
|
+
setv(
|
3255
|
+
to_object,
|
3256
|
+
['url_metadata'],
|
3257
|
+
[
|
3258
|
+
_UrlMetadata_from_mldev(api_client, item, to_object)
|
3259
|
+
for item in getv(from_object, ['urlMetadata'])
|
3260
|
+
],
|
3261
|
+
)
|
3262
|
+
|
3263
|
+
return to_object
|
3264
|
+
|
3265
|
+
|
2922
3266
|
def _Candidate_from_mldev(
|
2923
3267
|
api_client: BaseApiClient,
|
2924
3268
|
from_object: Union[dict[str, Any], object],
|
@@ -2949,6 +3293,15 @@ def _Candidate_from_mldev(
|
|
2949
3293
|
if getv(from_object, ['finishReason']) is not None:
|
2950
3294
|
setv(to_object, ['finish_reason'], getv(from_object, ['finishReason']))
|
2951
3295
|
|
3296
|
+
if getv(from_object, ['urlContextMetadata']) is not None:
|
3297
|
+
setv(
|
3298
|
+
to_object,
|
3299
|
+
['url_context_metadata'],
|
3300
|
+
_UrlContextMetadata_from_mldev(
|
3301
|
+
api_client, getv(from_object, ['urlContextMetadata']), to_object
|
3302
|
+
),
|
3303
|
+
)
|
3304
|
+
|
2952
3305
|
if getv(from_object, ['avgLogprobs']) is not None:
|
2953
3306
|
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
|
2954
3307
|
|
@@ -3419,6 +3772,24 @@ def _GenerateVideosOperation_from_mldev(
|
|
3419
3772
|
return to_object
|
3420
3773
|
|
3421
3774
|
|
3775
|
+
def _VideoMetadata_from_vertex(
|
3776
|
+
api_client: BaseApiClient,
|
3777
|
+
from_object: Union[dict[str, Any], object],
|
3778
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3779
|
+
) -> dict[str, Any]:
|
3780
|
+
to_object: dict[str, Any] = {}
|
3781
|
+
if getv(from_object, ['fps']) is not None:
|
3782
|
+
setv(to_object, ['fps'], getv(from_object, ['fps']))
|
3783
|
+
|
3784
|
+
if getv(from_object, ['endOffset']) is not None:
|
3785
|
+
setv(to_object, ['end_offset'], getv(from_object, ['endOffset']))
|
3786
|
+
|
3787
|
+
if getv(from_object, ['startOffset']) is not None:
|
3788
|
+
setv(to_object, ['start_offset'], getv(from_object, ['startOffset']))
|
3789
|
+
|
3790
|
+
return to_object
|
3791
|
+
|
3792
|
+
|
3422
3793
|
def _Blob_from_vertex(
|
3423
3794
|
api_client: BaseApiClient,
|
3424
3795
|
from_object: Union[dict[str, Any], object],
|
@@ -3444,7 +3815,13 @@ def _Part_from_vertex(
|
|
3444
3815
|
) -> dict[str, Any]:
|
3445
3816
|
to_object: dict[str, Any] = {}
|
3446
3817
|
if getv(from_object, ['videoMetadata']) is not None:
|
3447
|
-
setv(
|
3818
|
+
setv(
|
3819
|
+
to_object,
|
3820
|
+
['video_metadata'],
|
3821
|
+
_VideoMetadata_from_vertex(
|
3822
|
+
api_client, getv(from_object, ['videoMetadata']), to_object
|
3823
|
+
),
|
3824
|
+
)
|
3448
3825
|
|
3449
3826
|
if getv(from_object, ['thought']) is not None:
|
3450
3827
|
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
@@ -3521,6 +3898,44 @@ def _CitationMetadata_from_vertex(
|
|
3521
3898
|
return to_object
|
3522
3899
|
|
3523
3900
|
|
3901
|
+
def _UrlMetadata_from_vertex(
|
3902
|
+
api_client: BaseApiClient,
|
3903
|
+
from_object: Union[dict[str, Any], object],
|
3904
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3905
|
+
) -> dict[str, Any]:
|
3906
|
+
to_object: dict[str, Any] = {}
|
3907
|
+
if getv(from_object, ['retrievedUrl']) is not None:
|
3908
|
+
setv(to_object, ['retrieved_url'], getv(from_object, ['retrievedUrl']))
|
3909
|
+
|
3910
|
+
if getv(from_object, ['urlRetrievalStatus']) is not None:
|
3911
|
+
setv(
|
3912
|
+
to_object,
|
3913
|
+
['url_retrieval_status'],
|
3914
|
+
getv(from_object, ['urlRetrievalStatus']),
|
3915
|
+
)
|
3916
|
+
|
3917
|
+
return to_object
|
3918
|
+
|
3919
|
+
|
3920
|
+
def _UrlContextMetadata_from_vertex(
|
3921
|
+
api_client: BaseApiClient,
|
3922
|
+
from_object: Union[dict[str, Any], object],
|
3923
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3924
|
+
) -> dict[str, Any]:
|
3925
|
+
to_object: dict[str, Any] = {}
|
3926
|
+
if getv(from_object, ['urlMetadata']) is not None:
|
3927
|
+
setv(
|
3928
|
+
to_object,
|
3929
|
+
['url_metadata'],
|
3930
|
+
[
|
3931
|
+
_UrlMetadata_from_vertex(api_client, item, to_object)
|
3932
|
+
for item in getv(from_object, ['urlMetadata'])
|
3933
|
+
],
|
3934
|
+
)
|
3935
|
+
|
3936
|
+
return to_object
|
3937
|
+
|
3938
|
+
|
3524
3939
|
def _Candidate_from_vertex(
|
3525
3940
|
api_client: BaseApiClient,
|
3526
3941
|
from_object: Union[dict[str, Any], object],
|
@@ -5151,6 +5566,8 @@ class Models(_api_module.BaseModule):
|
|
5151
5566
|
|
5152
5567
|
Some models support multimodal input and output.
|
5153
5568
|
|
5569
|
+
Built-in MCP support is an experimental feature.
|
5570
|
+
|
5154
5571
|
Usage:
|
5155
5572
|
|
5156
5573
|
.. code-block:: python
|
@@ -5186,11 +5603,22 @@ class Models(_api_module.BaseModule):
|
|
5186
5603
|
# scones.
|
5187
5604
|
"""
|
5188
5605
|
|
5189
|
-
|
5606
|
+
parsed_config = _extra_utils.parse_config_for_mcp_usage(config)
|
5607
|
+
if (
|
5608
|
+
parsed_config
|
5609
|
+
and parsed_config.tools
|
5610
|
+
and _mcp_utils.has_mcp_session_usage(parsed_config.tools)
|
5611
|
+
):
|
5612
|
+
raise errors.UnsupportedFunctionError(
|
5613
|
+
'MCP sessions are not supported in synchronous methods.'
|
5614
|
+
)
|
5615
|
+
if _extra_utils.should_disable_afc(parsed_config):
|
5190
5616
|
return self._generate_content(
|
5191
|
-
model=model, contents=contents, config=
|
5617
|
+
model=model, contents=contents, config=parsed_config
|
5192
5618
|
)
|
5193
|
-
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
5619
|
+
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
5620
|
+
parsed_config
|
5621
|
+
)
|
5194
5622
|
logger.info(
|
5195
5623
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
5196
5624
|
)
|
@@ -5200,14 +5628,14 @@ class Models(_api_module.BaseModule):
|
|
5200
5628
|
while remaining_remote_calls_afc > 0:
|
5201
5629
|
i += 1
|
5202
5630
|
response = self._generate_content(
|
5203
|
-
model=model, contents=contents, config=
|
5631
|
+
model=model, contents=contents, config=parsed_config
|
5204
5632
|
)
|
5205
5633
|
logger.info(f'AFC remote call {i} is done.')
|
5206
5634
|
remaining_remote_calls_afc -= 1
|
5207
5635
|
if remaining_remote_calls_afc == 0:
|
5208
5636
|
logger.info('Reached max remote calls for automatic function calling.')
|
5209
5637
|
|
5210
|
-
function_map = _extra_utils.get_function_map(
|
5638
|
+
function_map = _extra_utils.get_function_map(parsed_config)
|
5211
5639
|
if not function_map:
|
5212
5640
|
break
|
5213
5641
|
if not response:
|
@@ -5236,7 +5664,10 @@ class Models(_api_module.BaseModule):
|
|
5236
5664
|
contents.append(func_response_content) # type: ignore[arg-type]
|
5237
5665
|
automatic_function_calling_history.append(func_call_content)
|
5238
5666
|
automatic_function_calling_history.append(func_response_content)
|
5239
|
-
if
|
5667
|
+
if (
|
5668
|
+
_extra_utils.should_append_afc_history(parsed_config)
|
5669
|
+
and response is not None
|
5670
|
+
):
|
5240
5671
|
response.automatic_function_calling_history = (
|
5241
5672
|
automatic_function_calling_history
|
5242
5673
|
)
|
@@ -5271,6 +5702,8 @@ class Models(_api_module.BaseModule):
|
|
5271
5702
|
|
5272
5703
|
Some models support multimodal input and output.
|
5273
5704
|
|
5705
|
+
Built-in MCP support is an experimental feature.
|
5706
|
+
|
5274
5707
|
Usage:
|
5275
5708
|
|
5276
5709
|
.. code-block:: python
|
@@ -5306,13 +5739,24 @@ class Models(_api_module.BaseModule):
|
|
5306
5739
|
# scones.
|
5307
5740
|
"""
|
5308
5741
|
|
5309
|
-
|
5742
|
+
parsed_config = _extra_utils.parse_config_for_mcp_usage(config)
|
5743
|
+
if (
|
5744
|
+
parsed_config
|
5745
|
+
and parsed_config.tools
|
5746
|
+
and _mcp_utils.has_mcp_session_usage(parsed_config.tools)
|
5747
|
+
):
|
5748
|
+
raise errors.UnsupportedFunctionError(
|
5749
|
+
'MCP sessions are not supported in synchronous methods.'
|
5750
|
+
)
|
5751
|
+
if _extra_utils.should_disable_afc(parsed_config):
|
5310
5752
|
yield from self._generate_content_stream(
|
5311
|
-
model=model, contents=contents, config=
|
5753
|
+
model=model, contents=contents, config=parsed_config
|
5312
5754
|
)
|
5313
5755
|
return
|
5314
5756
|
|
5315
|
-
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
5757
|
+
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
5758
|
+
parsed_config
|
5759
|
+
)
|
5316
5760
|
logger.info(
|
5317
5761
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
5318
5762
|
)
|
@@ -5323,14 +5767,14 @@ class Models(_api_module.BaseModule):
|
|
5323
5767
|
while remaining_remote_calls_afc > 0:
|
5324
5768
|
i += 1
|
5325
5769
|
response = self._generate_content_stream(
|
5326
|
-
model=model, contents=contents, config=
|
5770
|
+
model=model, contents=contents, config=parsed_config
|
5327
5771
|
)
|
5328
5772
|
logger.info(f'AFC remote call {i} is done.')
|
5329
5773
|
remaining_remote_calls_afc -= 1
|
5330
5774
|
if remaining_remote_calls_afc == 0:
|
5331
5775
|
logger.info('Reached max remote calls for automatic function calling.')
|
5332
5776
|
|
5333
|
-
function_map = _extra_utils.get_function_map(
|
5777
|
+
function_map = _extra_utils.get_function_map(parsed_config)
|
5334
5778
|
|
5335
5779
|
if i == 1:
|
5336
5780
|
# First request gets a function call.
|
@@ -5355,7 +5799,7 @@ class Models(_api_module.BaseModule):
|
|
5355
5799
|
else:
|
5356
5800
|
# Second request and beyond, yield chunks.
|
5357
5801
|
for chunk in response:
|
5358
|
-
if _extra_utils.should_append_afc_history(
|
5802
|
+
if _extra_utils.should_append_afc_history(parsed_config):
|
5359
5803
|
chunk.automatic_function_calling_history = (
|
5360
5804
|
automatic_function_calling_history
|
5361
5805
|
)
|
@@ -6633,6 +7077,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
6633
7077
|
|
6634
7078
|
Some models support multimodal input and output.
|
6635
7079
|
|
7080
|
+
Built-in MCP support is an experimental feature.
|
7081
|
+
|
6636
7082
|
Usage:
|
6637
7083
|
|
6638
7084
|
.. code-block:: python
|
@@ -6658,11 +7104,17 @@ class AsyncModels(_api_module.BaseModule):
|
|
6658
7104
|
print(response.text)
|
6659
7105
|
# J'aime les bagels.
|
6660
7106
|
"""
|
6661
|
-
if
|
7107
|
+
# Retrieve and cache any MCP sessions if provided.
|
7108
|
+
parsed_config, mcp_to_genai_tool_adapters = (
|
7109
|
+
await _extra_utils.parse_config_for_mcp_sessions(config)
|
7110
|
+
)
|
7111
|
+
if _extra_utils.should_disable_afc(parsed_config):
|
6662
7112
|
return await self._generate_content(
|
6663
|
-
model=model, contents=contents, config=
|
7113
|
+
model=model, contents=contents, config=parsed_config
|
6664
7114
|
)
|
6665
|
-
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
7115
|
+
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(
|
7116
|
+
parsed_config
|
7117
|
+
)
|
6666
7118
|
logger.info(
|
6667
7119
|
f'AFC is enabled with max remote calls: {remaining_remote_calls_afc}.'
|
6668
7120
|
)
|
@@ -6670,14 +7122,14 @@ class AsyncModels(_api_module.BaseModule):
|
|
6670
7122
|
response = types.GenerateContentResponse()
|
6671
7123
|
while remaining_remote_calls_afc > 0:
|
6672
7124
|
response = await self._generate_content(
|
6673
|
-
model=model, contents=contents, config=
|
7125
|
+
model=model, contents=contents, config=parsed_config
|
6674
7126
|
)
|
6675
7127
|
remaining_remote_calls_afc -= 1
|
6676
7128
|
if remaining_remote_calls_afc == 0:
|
6677
7129
|
logger.info('Reached max remote calls for automatic function calling.')
|
6678
7130
|
|
6679
7131
|
function_map = _extra_utils.get_function_map(
|
6680
|
-
|
7132
|
+
parsed_config, mcp_to_genai_tool_adapters, is_caller_method_async=True
|
6681
7133
|
)
|
6682
7134
|
if not function_map:
|
6683
7135
|
break
|
@@ -6710,7 +7162,10 @@ class AsyncModels(_api_module.BaseModule):
|
|
6710
7162
|
automatic_function_calling_history.append(func_call_content)
|
6711
7163
|
automatic_function_calling_history.append(func_response_content)
|
6712
7164
|
|
6713
|
-
if
|
7165
|
+
if (
|
7166
|
+
_extra_utils.should_append_afc_history(parsed_config)
|
7167
|
+
and response is not None
|
7168
|
+
):
|
6714
7169
|
response.automatic_function_calling_history = (
|
6715
7170
|
automatic_function_calling_history
|
6716
7171
|
)
|
@@ -6745,6 +7200,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
6745
7200
|
|
6746
7201
|
Some models support multimodal input and output.
|
6747
7202
|
|
7203
|
+
Built-in MCP support is an experimental feature.
|
7204
|
+
|
6748
7205
|
Usage:
|
6749
7206
|
|
6750
7207
|
.. code-block:: python
|
@@ -6780,16 +7237,20 @@ class AsyncModels(_api_module.BaseModule):
|
|
6780
7237
|
# scones.
|
6781
7238
|
"""
|
6782
7239
|
|
6783
|
-
if
|
7240
|
+
# Retrieve and cache any MCP sessions if provided.
|
7241
|
+
parsed_config, mcp_to_genai_tool_adapters = (
|
7242
|
+
await _extra_utils.parse_config_for_mcp_sessions(config)
|
7243
|
+
)
|
7244
|
+
if _extra_utils.should_disable_afc(parsed_config):
|
6784
7245
|
response = await self._generate_content_stream(
|
6785
|
-
model=model, contents=contents, config=
|
7246
|
+
model=model, contents=contents, config=parsed_config
|
6786
7247
|
)
|
6787
7248
|
|
6788
7249
|
async def base_async_generator(model, contents, config): # type: ignore[no-untyped-def]
|
6789
7250
|
async for chunk in response: # type: ignore[attr-defined]
|
6790
7251
|
yield chunk
|
6791
7252
|
|
6792
|
-
return base_async_generator(model, contents,
|
7253
|
+
return base_async_generator(model, contents, parsed_config) # type: ignore[no-untyped-call, no-any-return]
|
6793
7254
|
|
6794
7255
|
async def async_generator(model, contents, config): # type: ignore[no-untyped-def]
|
6795
7256
|
remaining_remote_calls_afc = _extra_utils.get_max_remote_calls_afc(config)
|
@@ -6813,7 +7274,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
6813
7274
|
)
|
6814
7275
|
|
6815
7276
|
function_map = _extra_utils.get_function_map(
|
6816
|
-
config, is_caller_method_async=True
|
7277
|
+
config, mcp_to_genai_tool_adapters, is_caller_method_async=True
|
6817
7278
|
)
|
6818
7279
|
|
6819
7280
|
if i == 1:
|
@@ -6878,7 +7339,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
6878
7339
|
automatic_function_calling_history.append(func_call_content)
|
6879
7340
|
automatic_function_calling_history.append(func_response_content)
|
6880
7341
|
|
6881
|
-
return async_generator(model, contents,
|
7342
|
+
return async_generator(model, contents, parsed_config) # type: ignore[no-untyped-call, no-any-return]
|
6882
7343
|
|
6883
7344
|
async def edit_image(
|
6884
7345
|
self,
|