google-genai 1.15.0__py3-none-any.whl → 1.16.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/__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 +117 -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.0.dist-info}/METADATA +8 -4
- google_genai-1.16.0.dist-info/RECORD +35 -0
- {google_genai-1.15.0.dist-info → google_genai-1.16.0.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.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.15.0.dist-info → google_genai-1.16.0.dist-info}/top_level.txt +0 -0
google/genai/_transformers.py
CHANGED
@@ -27,6 +27,7 @@ import time
|
|
27
27
|
import types as builtin_types
|
28
28
|
import typing
|
29
29
|
from typing import Any, GenericAlias, Optional, Sequence, Union # type: ignore[attr-defined]
|
30
|
+
from ._mcp_utils import mcp_to_gemini_tool
|
30
31
|
|
31
32
|
if typing.TYPE_CHECKING:
|
32
33
|
import PIL.Image
|
@@ -47,6 +48,20 @@ else:
|
|
47
48
|
_UNION_TYPES = (typing.Union,)
|
48
49
|
from typing_extensions import TypeGuard
|
49
50
|
|
51
|
+
if typing.TYPE_CHECKING:
|
52
|
+
from mcp import ClientSession as McpClientSession
|
53
|
+
from mcp.types import Tool as McpTool
|
54
|
+
else:
|
55
|
+
McpClientSession: typing.Type = Any
|
56
|
+
McpTool: typing.Type = Any
|
57
|
+
try:
|
58
|
+
from mcp import ClientSession as McpClientSession
|
59
|
+
from mcp.types import Tool as McpTool
|
60
|
+
except ImportError:
|
61
|
+
McpClientSession = None
|
62
|
+
McpTool = None
|
63
|
+
|
64
|
+
|
50
65
|
def _resource_name(
|
51
66
|
client: _api_client.BaseApiClient,
|
52
67
|
resource_name: str,
|
@@ -211,7 +226,9 @@ def t_extract_models(
|
|
211
226
|
return []
|
212
227
|
|
213
228
|
|
214
|
-
def t_caches_model(
|
229
|
+
def t_caches_model(
|
230
|
+
api_client: _api_client.BaseApiClient, model: str
|
231
|
+
) -> Optional[str]:
|
215
232
|
model = t_model(api_client, model)
|
216
233
|
if not model:
|
217
234
|
return None
|
@@ -262,10 +279,11 @@ def t_function_response(
|
|
262
279
|
return function_response
|
263
280
|
else:
|
264
281
|
raise TypeError(
|
265
|
-
|
282
|
+
'Could not parse input as FunctionResponse. Unsupported'
|
266
283
|
f' function_response type: {type(function_response)}'
|
267
284
|
)
|
268
285
|
|
286
|
+
|
269
287
|
def t_function_responses(
|
270
288
|
function_responses: Union[
|
271
289
|
types.FunctionResponseOrDict,
|
@@ -361,7 +379,9 @@ def t_part(part: Optional[types.PartUnionDict]) -> types.Part:
|
|
361
379
|
|
362
380
|
|
363
381
|
def t_parts(
|
364
|
-
parts: Optional[
|
382
|
+
parts: Optional[
|
383
|
+
Union[list[types.PartUnionDict], types.PartUnionDict, list[types.Part]]
|
384
|
+
],
|
365
385
|
) -> list[types.Part]:
|
366
386
|
#
|
367
387
|
if parts is None or (isinstance(parts, list) and not parts):
|
@@ -442,9 +462,7 @@ def t_contents_for_embed(
|
|
442
462
|
if part.text:
|
443
463
|
text_parts.append(part.text)
|
444
464
|
else:
|
445
|
-
logger.warning(
|
446
|
-
f'Non-text part found, only returning text parts.'
|
447
|
-
)
|
465
|
+
logger.warning(f'Non-text part found, only returning text parts.')
|
448
466
|
return text_parts
|
449
467
|
else:
|
450
468
|
return transformed_contents
|
@@ -471,7 +489,9 @@ def t_contents(
|
|
471
489
|
result: list[types.Content] = []
|
472
490
|
accumulated_parts: list[types.Part] = []
|
473
491
|
|
474
|
-
def _is_part(
|
492
|
+
def _is_part(
|
493
|
+
part: Union[types.PartUnionDict, Any],
|
494
|
+
) -> TypeGuard[types.PartUnionDict]:
|
475
495
|
if (
|
476
496
|
isinstance(part, str)
|
477
497
|
or isinstance(part, types.File)
|
@@ -538,7 +558,7 @@ def t_contents(
|
|
538
558
|
result.append(types.UserContent(parts=content)) # type: ignore[arg-type]
|
539
559
|
else:
|
540
560
|
result.append(content)
|
541
|
-
elif
|
561
|
+
elif _is_part(content):
|
542
562
|
_handle_current_part(result, accumulated_parts, content)
|
543
563
|
elif isinstance(content, dict):
|
544
564
|
# PactDict is already handled in _is_part
|
@@ -777,7 +797,9 @@ def _process_enum(
|
|
777
797
|
return types.Schema.model_validate(enum_schema)
|
778
798
|
|
779
799
|
|
780
|
-
def _is_type_dict_str_any(
|
800
|
+
def _is_type_dict_str_any(
|
801
|
+
origin: Union[types.SchemaUnionDict, Any],
|
802
|
+
) -> TypeGuard[dict[str, Any]]:
|
781
803
|
"""Verifies the schema is of type dict[str, Any] for mypy type checking."""
|
782
804
|
return isinstance(origin, dict) and all(
|
783
805
|
isinstance(key, str) for key in origin
|
@@ -844,27 +866,32 @@ def t_speech_config(
|
|
844
866
|
prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name=origin)
|
845
867
|
)
|
846
868
|
)
|
847
|
-
if (
|
848
|
-
|
849
|
-
|
850
|
-
and origin['voice_config'] is not None
|
851
|
-
and 'prebuilt_voice_config' in origin['voice_config']
|
852
|
-
and origin['voice_config']['prebuilt_voice_config'] is not None
|
853
|
-
and 'voice_name' in origin['voice_config']['prebuilt_voice_config']
|
854
|
-
):
|
855
|
-
return types.SpeechConfig(
|
856
|
-
voice_config=types.VoiceConfig(
|
857
|
-
prebuilt_voice_config=types.PrebuiltVoiceConfig(
|
858
|
-
voice_name=origin['voice_config']['prebuilt_voice_config'].get(
|
859
|
-
'voice_name'
|
860
|
-
)
|
861
|
-
)
|
862
|
-
)
|
863
|
-
)
|
869
|
+
if isinstance(origin, dict):
|
870
|
+
return types.SpeechConfig.model_validate(origin)
|
871
|
+
|
864
872
|
raise ValueError(f'Unsupported speechConfig type: {type(origin)}')
|
865
873
|
|
866
874
|
|
867
|
-
def
|
875
|
+
def t_live_speech_config(
|
876
|
+
client: _api_client.BaseApiClient,
|
877
|
+
origin: types.SpeechConfigOrDict,
|
878
|
+
) -> Optional[types.SpeechConfig]:
|
879
|
+
if isinstance(origin, types.SpeechConfig):
|
880
|
+
speech_config = origin
|
881
|
+
if isinstance(origin, dict):
|
882
|
+
speech_config = types.SpeechConfig.model_validate(origin)
|
883
|
+
|
884
|
+
if speech_config.multi_speaker_voice_config is not None:
|
885
|
+
raise ValueError(
|
886
|
+
'multi_speaker_voice_config is not supported in the live API.'
|
887
|
+
)
|
888
|
+
|
889
|
+
return speech_config
|
890
|
+
|
891
|
+
|
892
|
+
def t_tool(
|
893
|
+
client: _api_client.BaseApiClient, origin: Any
|
894
|
+
) -> Optional[Union[types.Tool, Any]]:
|
868
895
|
if not origin:
|
869
896
|
return None
|
870
897
|
if inspect.isfunction(origin) or inspect.ismethod(origin):
|
@@ -875,13 +902,14 @@ def t_tool(client: _api_client.BaseApiClient, origin: Any) -> Optional[Union[typ
|
|
875
902
|
)
|
876
903
|
]
|
877
904
|
)
|
905
|
+
elif McpTool is not None and isinstance(origin, McpTool):
|
906
|
+
return mcp_to_gemini_tool(origin)
|
878
907
|
elif isinstance(origin, dict):
|
879
908
|
return types.Tool.model_validate(origin)
|
880
909
|
else:
|
881
910
|
return origin
|
882
911
|
|
883
912
|
|
884
|
-
# Only support functions now.
|
885
913
|
def t_tools(
|
886
914
|
client: _api_client.BaseApiClient, origin: list[Any]
|
887
915
|
) -> list[types.Tool]:
|
@@ -911,7 +939,9 @@ def t_cached_content_name(client: _api_client.BaseApiClient, name: str) -> str:
|
|
911
939
|
return _resource_name(client, name, collection_identifier='cachedContents')
|
912
940
|
|
913
941
|
|
914
|
-
def t_batch_job_source(
|
942
|
+
def t_batch_job_source(
|
943
|
+
client: _api_client.BaseApiClient, src: str
|
944
|
+
) -> types.BatchJobSource:
|
915
945
|
if src.startswith('gs://'):
|
916
946
|
return types.BatchJobSource(
|
917
947
|
format='jsonl',
|
@@ -926,7 +956,9 @@ def t_batch_job_source(client: _api_client.BaseApiClient, src: str) -> types.Bat
|
|
926
956
|
raise ValueError(f'Unsupported source: {src}')
|
927
957
|
|
928
958
|
|
929
|
-
def t_batch_job_destination(
|
959
|
+
def t_batch_job_destination(
|
960
|
+
client: _api_client.BaseApiClient, dest: str
|
961
|
+
) -> types.BatchJobDestination:
|
930
962
|
if dest.startswith('gs://'):
|
931
963
|
return types.BatchJobDestination(
|
932
964
|
format='jsonl',
|
@@ -960,7 +992,9 @@ LRO_POLLING_TIMEOUT_SECONDS = 900.0
|
|
960
992
|
LRO_POLLING_MULTIPLIER = 1.5
|
961
993
|
|
962
994
|
|
963
|
-
def t_resolve_operation(
|
995
|
+
def t_resolve_operation(
|
996
|
+
api_client: _api_client.BaseApiClient, struct: dict[str, Any]
|
997
|
+
) -> Any:
|
964
998
|
if (name := struct.get('name')) and '/operations/' in name:
|
965
999
|
operation: dict[str, Any] = struct
|
966
1000
|
total_seconds = 0.0
|
@@ -1058,8 +1092,7 @@ def t_content_strict(content: types.ContentOrDict) -> types.Content:
|
|
1058
1092
|
return content
|
1059
1093
|
else:
|
1060
1094
|
raise ValueError(
|
1061
|
-
f'Could not convert input (type "{type(content)}") to '
|
1062
|
-
'`types.Content`'
|
1095
|
+
f'Could not convert input (type "{type(content)}") to `types.Content`'
|
1063
1096
|
)
|
1064
1097
|
|
1065
1098
|
|
google/genai/caches.py
CHANGED
@@ -30,6 +30,24 @@ from .pagers import AsyncPager, Pager
|
|
30
30
|
logger = logging.getLogger('google_genai.caches')
|
31
31
|
|
32
32
|
|
33
|
+
def _VideoMetadata_to_mldev(
|
34
|
+
api_client: BaseApiClient,
|
35
|
+
from_object: Union[dict[str, Any], object],
|
36
|
+
parent_object: Optional[dict[str, Any]] = None,
|
37
|
+
) -> dict[str, Any]:
|
38
|
+
to_object: dict[str, Any] = {}
|
39
|
+
if getv(from_object, ['fps']) is not None:
|
40
|
+
setv(to_object, ['fps'], getv(from_object, ['fps']))
|
41
|
+
|
42
|
+
if getv(from_object, ['end_offset']) is not None:
|
43
|
+
setv(to_object, ['endOffset'], getv(from_object, ['end_offset']))
|
44
|
+
|
45
|
+
if getv(from_object, ['start_offset']) is not None:
|
46
|
+
setv(to_object, ['startOffset'], getv(from_object, ['start_offset']))
|
47
|
+
|
48
|
+
return to_object
|
49
|
+
|
50
|
+
|
33
51
|
def _Blob_to_mldev(
|
34
52
|
api_client: BaseApiClient,
|
35
53
|
from_object: Union[dict[str, Any], object],
|
@@ -55,7 +73,13 @@ def _Part_to_mldev(
|
|
55
73
|
) -> dict[str, Any]:
|
56
74
|
to_object: dict[str, Any] = {}
|
57
75
|
if getv(from_object, ['video_metadata']) is not None:
|
58
|
-
|
76
|
+
setv(
|
77
|
+
to_object,
|
78
|
+
['videoMetadata'],
|
79
|
+
_VideoMetadata_to_mldev(
|
80
|
+
api_client, getv(from_object, ['video_metadata']), to_object
|
81
|
+
),
|
82
|
+
)
|
59
83
|
|
60
84
|
if getv(from_object, ['thought']) is not None:
|
61
85
|
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
@@ -120,12 +144,59 @@ def _Content_to_mldev(
|
|
120
144
|
return to_object
|
121
145
|
|
122
146
|
|
147
|
+
def _FunctionDeclaration_to_mldev(
|
148
|
+
api_client: BaseApiClient,
|
149
|
+
from_object: Union[dict[str, Any], object],
|
150
|
+
parent_object: Optional[dict[str, Any]] = None,
|
151
|
+
) -> dict[str, Any]:
|
152
|
+
to_object: dict[str, Any] = {}
|
153
|
+
if getv(from_object, ['behavior']) is not None:
|
154
|
+
setv(to_object, ['behavior'], getv(from_object, ['behavior']))
|
155
|
+
|
156
|
+
if getv(from_object, ['description']) is not None:
|
157
|
+
setv(to_object, ['description'], getv(from_object, ['description']))
|
158
|
+
|
159
|
+
if getv(from_object, ['name']) is not None:
|
160
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
161
|
+
|
162
|
+
if getv(from_object, ['parameters']) is not None:
|
163
|
+
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
|
164
|
+
|
165
|
+
if getv(from_object, ['response']) is not None:
|
166
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
167
|
+
|
168
|
+
return to_object
|
169
|
+
|
170
|
+
|
171
|
+
def _Interval_to_mldev(
|
172
|
+
api_client: BaseApiClient,
|
173
|
+
from_object: Union[dict[str, Any], object],
|
174
|
+
parent_object: Optional[dict[str, Any]] = None,
|
175
|
+
) -> dict[str, Any]:
|
176
|
+
to_object: dict[str, Any] = {}
|
177
|
+
if getv(from_object, ['start_time']) is not None:
|
178
|
+
setv(to_object, ['startTime'], getv(from_object, ['start_time']))
|
179
|
+
|
180
|
+
if getv(from_object, ['end_time']) is not None:
|
181
|
+
setv(to_object, ['endTime'], getv(from_object, ['end_time']))
|
182
|
+
|
183
|
+
return to_object
|
184
|
+
|
185
|
+
|
123
186
|
def _GoogleSearch_to_mldev(
|
124
187
|
api_client: BaseApiClient,
|
125
188
|
from_object: Union[dict[str, Any], object],
|
126
189
|
parent_object: Optional[dict[str, Any]] = None,
|
127
190
|
) -> dict[str, Any]:
|
128
191
|
to_object: dict[str, Any] = {}
|
192
|
+
if getv(from_object, ['time_range_filter']) is not None:
|
193
|
+
setv(
|
194
|
+
to_object,
|
195
|
+
['timeRangeFilter'],
|
196
|
+
_Interval_to_mldev(
|
197
|
+
api_client, getv(from_object, ['time_range_filter']), to_object
|
198
|
+
),
|
199
|
+
)
|
129
200
|
|
130
201
|
return to_object
|
131
202
|
|
@@ -238,12 +309,32 @@ def _GoogleMaps_to_mldev(
|
|
238
309
|
return to_object
|
239
310
|
|
240
311
|
|
312
|
+
def _UrlContext_to_mldev(
|
313
|
+
api_client: BaseApiClient,
|
314
|
+
from_object: Union[dict[str, Any], object],
|
315
|
+
parent_object: Optional[dict[str, Any]] = None,
|
316
|
+
) -> dict[str, Any]:
|
317
|
+
to_object: dict[str, Any] = {}
|
318
|
+
|
319
|
+
return to_object
|
320
|
+
|
321
|
+
|
241
322
|
def _Tool_to_mldev(
|
242
323
|
api_client: BaseApiClient,
|
243
324
|
from_object: Union[dict[str, Any], object],
|
244
325
|
parent_object: Optional[dict[str, Any]] = None,
|
245
326
|
) -> dict[str, Any]:
|
246
327
|
to_object: dict[str, Any] = {}
|
328
|
+
if getv(from_object, ['function_declarations']) is not None:
|
329
|
+
setv(
|
330
|
+
to_object,
|
331
|
+
['functionDeclarations'],
|
332
|
+
[
|
333
|
+
_FunctionDeclaration_to_mldev(api_client, item, to_object)
|
334
|
+
for item in getv(from_object, ['function_declarations'])
|
335
|
+
],
|
336
|
+
)
|
337
|
+
|
247
338
|
if getv(from_object, ['retrieval']) is not None:
|
248
339
|
raise ValueError('retrieval parameter is not supported in Gemini API.')
|
249
340
|
|
@@ -275,16 +366,18 @@ def _Tool_to_mldev(
|
|
275
366
|
if getv(from_object, ['google_maps']) is not None:
|
276
367
|
raise ValueError('google_maps parameter is not supported in Gemini API.')
|
277
368
|
|
278
|
-
if getv(from_object, ['
|
279
|
-
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
280
|
-
|
281
|
-
if getv(from_object, ['function_declarations']) is not None:
|
369
|
+
if getv(from_object, ['url_context']) is not None:
|
282
370
|
setv(
|
283
371
|
to_object,
|
284
|
-
['
|
285
|
-
|
372
|
+
['urlContext'],
|
373
|
+
_UrlContext_to_mldev(
|
374
|
+
api_client, getv(from_object, ['url_context']), to_object
|
375
|
+
),
|
286
376
|
)
|
287
377
|
|
378
|
+
if getv(from_object, ['code_execution']) is not None:
|
379
|
+
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
380
|
+
|
288
381
|
return to_object
|
289
382
|
|
290
383
|
|
@@ -314,10 +407,10 @@ def _LatLng_to_mldev(
|
|
314
407
|
) -> dict[str, Any]:
|
315
408
|
to_object: dict[str, Any] = {}
|
316
409
|
if getv(from_object, ['latitude']) is not None:
|
317
|
-
|
410
|
+
setv(to_object, ['latitude'], getv(from_object, ['latitude']))
|
318
411
|
|
319
412
|
if getv(from_object, ['longitude']) is not None:
|
320
|
-
|
413
|
+
setv(to_object, ['longitude'], getv(from_object, ['longitude']))
|
321
414
|
|
322
415
|
return to_object
|
323
416
|
|
@@ -329,7 +422,11 @@ def _RetrievalConfig_to_mldev(
|
|
329
422
|
) -> dict[str, Any]:
|
330
423
|
to_object: dict[str, Any] = {}
|
331
424
|
if getv(from_object, ['lat_lng']) is not None:
|
332
|
-
|
425
|
+
setv(
|
426
|
+
to_object,
|
427
|
+
['latLng'],
|
428
|
+
_LatLng_to_mldev(api_client, getv(from_object, ['lat_lng']), to_object),
|
429
|
+
)
|
333
430
|
|
334
431
|
return to_object
|
335
432
|
|
@@ -352,8 +449,12 @@ def _ToolConfig_to_mldev(
|
|
352
449
|
)
|
353
450
|
|
354
451
|
if getv(from_object, ['retrieval_config']) is not None:
|
355
|
-
|
356
|
-
|
452
|
+
setv(
|
453
|
+
to_object,
|
454
|
+
['retrievalConfig'],
|
455
|
+
_RetrievalConfig_to_mldev(
|
456
|
+
api_client, getv(from_object, ['retrieval_config']), to_object
|
457
|
+
),
|
357
458
|
)
|
358
459
|
|
359
460
|
return to_object
|
@@ -417,6 +518,9 @@ def _CreateCachedContentConfig_to_mldev(
|
|
417
518
|
),
|
418
519
|
)
|
419
520
|
|
521
|
+
if getv(from_object, ['kms_key_name']) is not None:
|
522
|
+
raise ValueError('kms_key_name parameter is not supported in Gemini API.')
|
523
|
+
|
420
524
|
return to_object
|
421
525
|
|
422
526
|
|
@@ -564,6 +668,24 @@ def _ListCachedContentsParameters_to_mldev(
|
|
564
668
|
return to_object
|
565
669
|
|
566
670
|
|
671
|
+
def _VideoMetadata_to_vertex(
|
672
|
+
api_client: BaseApiClient,
|
673
|
+
from_object: Union[dict[str, Any], object],
|
674
|
+
parent_object: Optional[dict[str, Any]] = None,
|
675
|
+
) -> dict[str, Any]:
|
676
|
+
to_object: dict[str, Any] = {}
|
677
|
+
if getv(from_object, ['fps']) is not None:
|
678
|
+
setv(to_object, ['fps'], getv(from_object, ['fps']))
|
679
|
+
|
680
|
+
if getv(from_object, ['end_offset']) is not None:
|
681
|
+
setv(to_object, ['endOffset'], getv(from_object, ['end_offset']))
|
682
|
+
|
683
|
+
if getv(from_object, ['start_offset']) is not None:
|
684
|
+
setv(to_object, ['startOffset'], getv(from_object, ['start_offset']))
|
685
|
+
|
686
|
+
return to_object
|
687
|
+
|
688
|
+
|
567
689
|
def _Blob_to_vertex(
|
568
690
|
api_client: BaseApiClient,
|
569
691
|
from_object: Union[dict[str, Any], object],
|
@@ -589,7 +711,13 @@ def _Part_to_vertex(
|
|
589
711
|
) -> dict[str, Any]:
|
590
712
|
to_object: dict[str, Any] = {}
|
591
713
|
if getv(from_object, ['video_metadata']) is not None:
|
592
|
-
setv(
|
714
|
+
setv(
|
715
|
+
to_object,
|
716
|
+
['videoMetadata'],
|
717
|
+
_VideoMetadata_to_vertex(
|
718
|
+
api_client, getv(from_object, ['video_metadata']), to_object
|
719
|
+
),
|
720
|
+
)
|
593
721
|
|
594
722
|
if getv(from_object, ['thought']) is not None:
|
595
723
|
setv(to_object, ['thought'], getv(from_object, ['thought']))
|
@@ -654,12 +782,59 @@ def _Content_to_vertex(
|
|
654
782
|
return to_object
|
655
783
|
|
656
784
|
|
785
|
+
def _FunctionDeclaration_to_vertex(
|
786
|
+
api_client: BaseApiClient,
|
787
|
+
from_object: Union[dict[str, Any], object],
|
788
|
+
parent_object: Optional[dict[str, Any]] = None,
|
789
|
+
) -> dict[str, Any]:
|
790
|
+
to_object: dict[str, Any] = {}
|
791
|
+
if getv(from_object, ['behavior']) is not None:
|
792
|
+
raise ValueError('behavior parameter is not supported in Vertex AI.')
|
793
|
+
|
794
|
+
if getv(from_object, ['description']) is not None:
|
795
|
+
setv(to_object, ['description'], getv(from_object, ['description']))
|
796
|
+
|
797
|
+
if getv(from_object, ['name']) is not None:
|
798
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
799
|
+
|
800
|
+
if getv(from_object, ['parameters']) is not None:
|
801
|
+
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
|
802
|
+
|
803
|
+
if getv(from_object, ['response']) is not None:
|
804
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
805
|
+
|
806
|
+
return to_object
|
807
|
+
|
808
|
+
|
809
|
+
def _Interval_to_vertex(
|
810
|
+
api_client: BaseApiClient,
|
811
|
+
from_object: Union[dict[str, Any], object],
|
812
|
+
parent_object: Optional[dict[str, Any]] = None,
|
813
|
+
) -> dict[str, Any]:
|
814
|
+
to_object: dict[str, Any] = {}
|
815
|
+
if getv(from_object, ['start_time']) is not None:
|
816
|
+
setv(to_object, ['startTime'], getv(from_object, ['start_time']))
|
817
|
+
|
818
|
+
if getv(from_object, ['end_time']) is not None:
|
819
|
+
setv(to_object, ['endTime'], getv(from_object, ['end_time']))
|
820
|
+
|
821
|
+
return to_object
|
822
|
+
|
823
|
+
|
657
824
|
def _GoogleSearch_to_vertex(
|
658
825
|
api_client: BaseApiClient,
|
659
826
|
from_object: Union[dict[str, Any], object],
|
660
827
|
parent_object: Optional[dict[str, Any]] = None,
|
661
828
|
) -> dict[str, Any]:
|
662
829
|
to_object: dict[str, Any] = {}
|
830
|
+
if getv(from_object, ['time_range_filter']) is not None:
|
831
|
+
setv(
|
832
|
+
to_object,
|
833
|
+
['timeRangeFilter'],
|
834
|
+
_Interval_to_vertex(
|
835
|
+
api_client, getv(from_object, ['time_range_filter']), to_object
|
836
|
+
),
|
837
|
+
)
|
663
838
|
|
664
839
|
return to_object
|
665
840
|
|
@@ -784,12 +959,32 @@ def _GoogleMaps_to_vertex(
|
|
784
959
|
return to_object
|
785
960
|
|
786
961
|
|
962
|
+
def _UrlContext_to_vertex(
|
963
|
+
api_client: BaseApiClient,
|
964
|
+
from_object: Union[dict[str, Any], object],
|
965
|
+
parent_object: Optional[dict[str, Any]] = None,
|
966
|
+
) -> dict[str, Any]:
|
967
|
+
to_object: dict[str, Any] = {}
|
968
|
+
|
969
|
+
return to_object
|
970
|
+
|
971
|
+
|
787
972
|
def _Tool_to_vertex(
|
788
973
|
api_client: BaseApiClient,
|
789
974
|
from_object: Union[dict[str, Any], object],
|
790
975
|
parent_object: Optional[dict[str, Any]] = None,
|
791
976
|
) -> dict[str, Any]:
|
792
977
|
to_object: dict[str, Any] = {}
|
978
|
+
if getv(from_object, ['function_declarations']) is not None:
|
979
|
+
setv(
|
980
|
+
to_object,
|
981
|
+
['functionDeclarations'],
|
982
|
+
[
|
983
|
+
_FunctionDeclaration_to_vertex(api_client, item, to_object)
|
984
|
+
for item in getv(from_object, ['function_declarations'])
|
985
|
+
],
|
986
|
+
)
|
987
|
+
|
793
988
|
if getv(from_object, ['retrieval']) is not None:
|
794
989
|
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
|
795
990
|
|
@@ -831,16 +1026,12 @@ def _Tool_to_vertex(
|
|
831
1026
|
),
|
832
1027
|
)
|
833
1028
|
|
1029
|
+
if getv(from_object, ['url_context']) is not None:
|
1030
|
+
raise ValueError('url_context parameter is not supported in Vertex AI.')
|
1031
|
+
|
834
1032
|
if getv(from_object, ['code_execution']) is not None:
|
835
1033
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
836
1034
|
|
837
|
-
if getv(from_object, ['function_declarations']) is not None:
|
838
|
-
setv(
|
839
|
-
to_object,
|
840
|
-
['functionDeclarations'],
|
841
|
-
getv(from_object, ['function_declarations']),
|
842
|
-
)
|
843
|
-
|
844
1035
|
return to_object
|
845
1036
|
|
846
1037
|
|
@@ -983,6 +1174,13 @@ def _CreateCachedContentConfig_to_vertex(
|
|
983
1174
|
),
|
984
1175
|
)
|
985
1176
|
|
1177
|
+
if getv(from_object, ['kms_key_name']) is not None:
|
1178
|
+
setv(
|
1179
|
+
parent_object,
|
1180
|
+
['encryption_spec', 'kmsKeyName'],
|
1181
|
+
getv(from_object, ['kms_key_name']),
|
1182
|
+
)
|
1183
|
+
|
986
1184
|
return to_object
|
987
1185
|
|
988
1186
|
|
@@ -1130,6 +1328,11 @@ def _ListCachedContentsParameters_to_vertex(
|
|
1130
1328
|
return to_object
|
1131
1329
|
|
1132
1330
|
|
1331
|
+
def _Behavior_to_vertex_enum_validate(enum_value: Any) -> None:
|
1332
|
+
if enum_value in set(['UNSPECIFIED', 'BLOCKING', 'NON_BLOCKING']):
|
1333
|
+
raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
|
1334
|
+
|
1335
|
+
|
1133
1336
|
def _CachedContent_from_mldev(
|
1134
1337
|
api_client: BaseApiClient,
|
1135
1338
|
from_object: Union[dict[str, Any], object],
|
google/genai/chats.py
CHANGED
google/genai/client.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2025 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -29,6 +29,7 @@ from .files import AsyncFiles, Files
|
|
29
29
|
from .live import AsyncLive
|
30
30
|
from .models import AsyncModels, Models
|
31
31
|
from .operations import AsyncOperations, Operations
|
32
|
+
from .tokens import AsyncTokens, Tokens
|
32
33
|
from .tunings import AsyncTunings, Tunings
|
33
34
|
from .types import HttpOptions, HttpOptionsDict
|
34
35
|
|
@@ -45,6 +46,7 @@ class AsyncClient:
|
|
45
46
|
self._batches = AsyncBatches(self._api_client)
|
46
47
|
self._files = AsyncFiles(self._api_client)
|
47
48
|
self._live = AsyncLive(self._api_client)
|
49
|
+
self._tokens = AsyncTokens(self._api_client)
|
48
50
|
self._operations = AsyncOperations(self._api_client)
|
49
51
|
|
50
52
|
@property
|
@@ -75,6 +77,10 @@ class AsyncClient:
|
|
75
77
|
def live(self) -> AsyncLive:
|
76
78
|
return self._live
|
77
79
|
|
80
|
+
@property
|
81
|
+
def auth_tokens(self) -> AsyncTokens:
|
82
|
+
return self._tokens
|
83
|
+
|
78
84
|
@property
|
79
85
|
def operations(self) -> AsyncOperations:
|
80
86
|
return self._operations
|
@@ -226,6 +232,7 @@ class Client:
|
|
226
232
|
self._caches = Caches(self._api_client)
|
227
233
|
self._batches = Batches(self._api_client)
|
228
234
|
self._files = Files(self._api_client)
|
235
|
+
self._tokens = Tokens(self._api_client)
|
229
236
|
self._operations = Operations(self._api_client)
|
230
237
|
|
231
238
|
@staticmethod
|
@@ -292,6 +299,10 @@ class Client:
|
|
292
299
|
def files(self) -> Files:
|
293
300
|
return self._files
|
294
301
|
|
302
|
+
@property
|
303
|
+
def auth_tokens(self) -> Tokens:
|
304
|
+
return self._tokens
|
305
|
+
|
295
306
|
@property
|
296
307
|
def operations(self) -> Operations:
|
297
308
|
return self._operations
|
google/genai/errors.py
CHANGED