google-genai 1.39.1__tar.gz → 1.41.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_genai-1.39.1/google_genai.egg-info → google_genai-1.41.0}/PKG-INFO +1 -1
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_extra_utils.py +72 -1
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_live_converters.py +68 -22
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_tokens_converters.py +34 -11
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/batches.py +37 -21
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/caches.py +38 -42
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/files.py +17 -97
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/live.py +33 -4
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/models.py +74 -42
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/tunings.py +6 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/types.py +143 -5
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/version.py +1 -1
- {google_genai-1.39.1 → google_genai-1.41.0/google_genai.egg-info}/PKG-INFO +1 -1
- {google_genai-1.39.1 → google_genai-1.41.0}/pyproject.toml +1 -1
- {google_genai-1.39.1 → google_genai-1.41.0}/LICENSE +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/MANIFEST.in +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/README.md +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/__init__.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_adapters.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_api_client.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_api_module.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_automatic_function_calling_util.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_base_transformers.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_base_url.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_common.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_local_tokenizer_loader.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_mcp_utils.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_operations_converters.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_replay_api_client.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_transformers.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/chats.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/client.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/errors.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/live_music.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/local_tokenizer.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/operations.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/pagers.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/py.typed +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google/genai/tokens.py +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google_genai.egg-info/SOURCES.txt +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google_genai.egg-info/requires.txt +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/google_genai.egg-info/top_level.txt +0 -0
- {google_genai-1.39.1 → google_genai-1.41.0}/setup.cfg +0 -0
@@ -16,11 +16,13 @@
|
|
16
16
|
"""Extra utils depending on types that are shared between sync and async modules."""
|
17
17
|
|
18
18
|
import inspect
|
19
|
+
import io
|
19
20
|
import logging
|
20
21
|
import sys
|
21
22
|
import typing
|
22
23
|
from typing import Any, Callable, Dict, Optional, Union, get_args, get_origin
|
23
|
-
|
24
|
+
import mimetypes
|
25
|
+
import os
|
24
26
|
import pydantic
|
25
27
|
|
26
28
|
from . import _common
|
@@ -541,3 +543,72 @@ def append_chunk_contents(
|
|
541
543
|
contents = t.t_contents(contents) # type: ignore[assignment]
|
542
544
|
if isinstance(contents, list) and chunk_content is not None:
|
543
545
|
contents.append(chunk_content) # type: ignore[arg-type]
|
546
|
+
|
547
|
+
|
548
|
+
def prepare_resumable_upload(
|
549
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
550
|
+
user_http_options: Optional[types.HttpOptionsOrDict] = None,
|
551
|
+
user_mime_type: Optional[str] = None,
|
552
|
+
) -> tuple[
|
553
|
+
types.HttpOptions,
|
554
|
+
int,
|
555
|
+
str,
|
556
|
+
]:
|
557
|
+
"""Prepares the HTTP options, file bytes size and mime type for a resumable upload.
|
558
|
+
|
559
|
+
This function inspects a file (from a path or an in-memory object) to
|
560
|
+
determine its size and MIME type. It then constructs the necessary HTTP
|
561
|
+
headers and options required to initiate a resumable upload session.
|
562
|
+
"""
|
563
|
+
size_bytes = None
|
564
|
+
mime_type = user_mime_type
|
565
|
+
if isinstance(file, io.IOBase):
|
566
|
+
if mime_type is None:
|
567
|
+
raise ValueError(
|
568
|
+
'Unknown mime type: Could not determine the mimetype for your'
|
569
|
+
' file\n please set the `mime_type` argument'
|
570
|
+
)
|
571
|
+
if hasattr(file, 'mode'):
|
572
|
+
if 'b' not in file.mode:
|
573
|
+
raise ValueError('The file must be opened in binary mode.')
|
574
|
+
offset = file.tell()
|
575
|
+
file.seek(0, os.SEEK_END)
|
576
|
+
size_bytes = file.tell() - offset
|
577
|
+
file.seek(offset, os.SEEK_SET)
|
578
|
+
else:
|
579
|
+
fs_path = os.fspath(file)
|
580
|
+
if not fs_path or not os.path.isfile(fs_path):
|
581
|
+
raise FileNotFoundError(f'{file} is not a valid file path.')
|
582
|
+
size_bytes = os.path.getsize(fs_path)
|
583
|
+
if mime_type is None:
|
584
|
+
mime_type, _ = mimetypes.guess_type(fs_path)
|
585
|
+
if mime_type is None:
|
586
|
+
raise ValueError(
|
587
|
+
'Unknown mime type: Could not determine the mimetype for your'
|
588
|
+
' file\n please set the `mime_type` argument'
|
589
|
+
)
|
590
|
+
http_options: types.HttpOptions
|
591
|
+
if user_http_options:
|
592
|
+
if isinstance(user_http_options, dict):
|
593
|
+
user_http_options = types.HttpOptions(**user_http_options)
|
594
|
+
http_options = user_http_options
|
595
|
+
http_options.api_version = ''
|
596
|
+
http_options.headers = {
|
597
|
+
'Content-Type': 'application/json',
|
598
|
+
'X-Goog-Upload-Protocol': 'resumable',
|
599
|
+
'X-Goog-Upload-Command': 'start',
|
600
|
+
'X-Goog-Upload-Header-Content-Length': f'{size_bytes}',
|
601
|
+
'X-Goog-Upload-Header-Content-Type': f'{mime_type}',
|
602
|
+
}
|
603
|
+
else:
|
604
|
+
http_options = types.HttpOptions(
|
605
|
+
api_version='',
|
606
|
+
headers={
|
607
|
+
'Content-Type': 'application/json',
|
608
|
+
'X-Goog-Upload-Protocol': 'resumable',
|
609
|
+
'X-Goog-Upload-Command': 'start',
|
610
|
+
'X-Goog-Upload-Header-Content-Length': f'{size_bytes}',
|
611
|
+
'X-Goog-Upload-Header-Content-Type': f'{mime_type}',
|
612
|
+
},
|
613
|
+
)
|
614
|
+
return http_options, size_bytes, mime_type
|
@@ -291,6 +291,42 @@ def _Blob_to_vertex(
|
|
291
291
|
return to_object
|
292
292
|
|
293
293
|
|
294
|
+
def _ComputerUse_to_mldev(
|
295
|
+
from_object: Union[dict[str, Any], object],
|
296
|
+
parent_object: Optional[dict[str, Any]] = None,
|
297
|
+
) -> dict[str, Any]:
|
298
|
+
to_object: dict[str, Any] = {}
|
299
|
+
if getv(from_object, ['environment']) is not None:
|
300
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
301
|
+
|
302
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
303
|
+
setv(
|
304
|
+
to_object,
|
305
|
+
['excludedPredefinedFunctions'],
|
306
|
+
getv(from_object, ['excluded_predefined_functions']),
|
307
|
+
)
|
308
|
+
|
309
|
+
return to_object
|
310
|
+
|
311
|
+
|
312
|
+
def _ComputerUse_to_vertex(
|
313
|
+
from_object: Union[dict[str, Any], object],
|
314
|
+
parent_object: Optional[dict[str, Any]] = None,
|
315
|
+
) -> dict[str, Any]:
|
316
|
+
to_object: dict[str, Any] = {}
|
317
|
+
if getv(from_object, ['environment']) is not None:
|
318
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
319
|
+
|
320
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
321
|
+
setv(
|
322
|
+
to_object,
|
323
|
+
['excludedPredefinedFunctions'],
|
324
|
+
getv(from_object, ['excluded_predefined_functions']),
|
325
|
+
)
|
326
|
+
|
327
|
+
return to_object
|
328
|
+
|
329
|
+
|
294
330
|
def _Content_from_mldev(
|
295
331
|
from_object: Union[dict[str, Any], object],
|
296
332
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1448,6 +1484,15 @@ def _LiveConnectConfig_to_mldev(
|
|
1448
1484
|
),
|
1449
1485
|
)
|
1450
1486
|
|
1487
|
+
if getv(from_object, ['thinking_config']) is not None:
|
1488
|
+
setv(
|
1489
|
+
parent_object,
|
1490
|
+
['setup', 'generationConfig', 'thinkingConfig'],
|
1491
|
+
_ThinkingConfig_to_mldev(
|
1492
|
+
getv(from_object, ['thinking_config']), to_object
|
1493
|
+
),
|
1494
|
+
)
|
1495
|
+
|
1451
1496
|
if getv(from_object, ['enable_affective_dialog']) is not None:
|
1452
1497
|
setv(
|
1453
1498
|
parent_object,
|
@@ -1604,6 +1649,15 @@ def _LiveConnectConfig_to_vertex(
|
|
1604
1649
|
),
|
1605
1650
|
)
|
1606
1651
|
|
1652
|
+
if getv(from_object, ['thinking_config']) is not None:
|
1653
|
+
setv(
|
1654
|
+
parent_object,
|
1655
|
+
['setup', 'generationConfig', 'thinkingConfig'],
|
1656
|
+
_ThinkingConfig_to_vertex(
|
1657
|
+
getv(from_object, ['thinking_config']), to_object
|
1658
|
+
),
|
1659
|
+
)
|
1660
|
+
|
1607
1661
|
if getv(from_object, ['enable_affective_dialog']) is not None:
|
1608
1662
|
setv(
|
1609
1663
|
parent_object,
|
@@ -3189,39 +3243,35 @@ def _SpeechConfig_to_vertex(
|
|
3189
3243
|
return to_object
|
3190
3244
|
|
3191
3245
|
|
3192
|
-
def
|
3246
|
+
def _ThinkingConfig_to_mldev(
|
3193
3247
|
from_object: Union[dict[str, Any], object],
|
3194
3248
|
parent_object: Optional[dict[str, Any]] = None,
|
3195
3249
|
) -> dict[str, Any]:
|
3196
3250
|
to_object: dict[str, Any] = {}
|
3197
|
-
if getv(from_object, ['
|
3198
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
3199
|
-
|
3200
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
3251
|
+
if getv(from_object, ['include_thoughts']) is not None:
|
3201
3252
|
setv(
|
3202
|
-
to_object,
|
3203
|
-
['excludedPredefinedFunctions'],
|
3204
|
-
getv(from_object, ['excluded_predefined_functions']),
|
3253
|
+
to_object, ['includeThoughts'], getv(from_object, ['include_thoughts'])
|
3205
3254
|
)
|
3206
3255
|
|
3256
|
+
if getv(from_object, ['thinking_budget']) is not None:
|
3257
|
+
setv(to_object, ['thinkingBudget'], getv(from_object, ['thinking_budget']))
|
3258
|
+
|
3207
3259
|
return to_object
|
3208
3260
|
|
3209
3261
|
|
3210
|
-
def
|
3262
|
+
def _ThinkingConfig_to_vertex(
|
3211
3263
|
from_object: Union[dict[str, Any], object],
|
3212
3264
|
parent_object: Optional[dict[str, Any]] = None,
|
3213
3265
|
) -> dict[str, Any]:
|
3214
3266
|
to_object: dict[str, Any] = {}
|
3215
|
-
if getv(from_object, ['
|
3216
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
3217
|
-
|
3218
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
3267
|
+
if getv(from_object, ['include_thoughts']) is not None:
|
3219
3268
|
setv(
|
3220
|
-
to_object,
|
3221
|
-
['excludedPredefinedFunctions'],
|
3222
|
-
getv(from_object, ['excluded_predefined_functions']),
|
3269
|
+
to_object, ['includeThoughts'], getv(from_object, ['include_thoughts'])
|
3223
3270
|
)
|
3224
3271
|
|
3272
|
+
if getv(from_object, ['thinking_budget']) is not None:
|
3273
|
+
setv(to_object, ['thinkingBudget'], getv(from_object, ['thinking_budget']))
|
3274
|
+
|
3225
3275
|
return to_object
|
3226
3276
|
|
3227
3277
|
|
@@ -3278,9 +3328,7 @@ def _Tool_to_mldev(
|
|
3278
3328
|
setv(
|
3279
3329
|
to_object,
|
3280
3330
|
['computerUse'],
|
3281
|
-
|
3282
|
-
getv(from_object, ['computer_use']), to_object
|
3283
|
-
),
|
3331
|
+
_ComputerUse_to_mldev(getv(from_object, ['computer_use']), to_object),
|
3284
3332
|
)
|
3285
3333
|
|
3286
3334
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -3352,9 +3400,7 @@ def _Tool_to_vertex(
|
|
3352
3400
|
setv(
|
3353
3401
|
to_object,
|
3354
3402
|
['computerUse'],
|
3355
|
-
|
3356
|
-
getv(from_object, ['computer_use']), to_object
|
3357
|
-
),
|
3403
|
+
_ComputerUse_to_vertex(getv(from_object, ['computer_use']), to_object),
|
3358
3404
|
)
|
3359
3405
|
|
3360
3406
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -106,6 +106,24 @@ def _Blob_to_mldev(
|
|
106
106
|
return to_object
|
107
107
|
|
108
108
|
|
109
|
+
def _ComputerUse_to_mldev(
|
110
|
+
from_object: Union[dict[str, Any], object],
|
111
|
+
parent_object: Optional[dict[str, Any]] = None,
|
112
|
+
) -> dict[str, Any]:
|
113
|
+
to_object: dict[str, Any] = {}
|
114
|
+
if getv(from_object, ['environment']) is not None:
|
115
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
116
|
+
|
117
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
118
|
+
setv(
|
119
|
+
to_object,
|
120
|
+
['excludedPredefinedFunctions'],
|
121
|
+
getv(from_object, ['excluded_predefined_functions']),
|
122
|
+
)
|
123
|
+
|
124
|
+
return to_object
|
125
|
+
|
126
|
+
|
109
127
|
def _Content_to_mldev(
|
110
128
|
from_object: Union[dict[str, Any], object],
|
111
129
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -430,6 +448,15 @@ def _LiveConnectConfig_to_mldev(
|
|
430
448
|
),
|
431
449
|
)
|
432
450
|
|
451
|
+
if getv(from_object, ['thinking_config']) is not None:
|
452
|
+
setv(
|
453
|
+
parent_object,
|
454
|
+
['setup', 'generationConfig', 'thinkingConfig'],
|
455
|
+
_ThinkingConfig_to_mldev(
|
456
|
+
getv(from_object, ['thinking_config']), to_object
|
457
|
+
),
|
458
|
+
)
|
459
|
+
|
433
460
|
if getv(from_object, ['enable_affective_dialog']) is not None:
|
434
461
|
setv(
|
435
462
|
parent_object,
|
@@ -743,21 +770,19 @@ def _SpeechConfig_to_mldev(
|
|
743
770
|
return to_object
|
744
771
|
|
745
772
|
|
746
|
-
def
|
773
|
+
def _ThinkingConfig_to_mldev(
|
747
774
|
from_object: Union[dict[str, Any], object],
|
748
775
|
parent_object: Optional[dict[str, Any]] = None,
|
749
776
|
) -> dict[str, Any]:
|
750
777
|
to_object: dict[str, Any] = {}
|
751
|
-
if getv(from_object, ['
|
752
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
753
|
-
|
754
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
778
|
+
if getv(from_object, ['include_thoughts']) is not None:
|
755
779
|
setv(
|
756
|
-
to_object,
|
757
|
-
['excludedPredefinedFunctions'],
|
758
|
-
getv(from_object, ['excluded_predefined_functions']),
|
780
|
+
to_object, ['includeThoughts'], getv(from_object, ['include_thoughts'])
|
759
781
|
)
|
760
782
|
|
783
|
+
if getv(from_object, ['thinking_budget']) is not None:
|
784
|
+
setv(to_object, ['thinkingBudget'], getv(from_object, ['thinking_budget']))
|
785
|
+
|
761
786
|
return to_object
|
762
787
|
|
763
788
|
|
@@ -814,9 +839,7 @@ def _Tool_to_mldev(
|
|
814
839
|
setv(
|
815
840
|
to_object,
|
816
841
|
['computerUse'],
|
817
|
-
|
818
|
-
getv(from_object, ['computer_use']), to_object
|
819
|
-
),
|
842
|
+
_ComputerUse_to_mldev(getv(from_object, ['computer_use']), to_object),
|
820
843
|
)
|
821
844
|
|
822
845
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -467,6 +467,24 @@ def _CitationMetadata_from_mldev(
|
|
467
467
|
return to_object
|
468
468
|
|
469
469
|
|
470
|
+
def _ComputerUse_to_mldev(
|
471
|
+
from_object: Union[dict[str, Any], object],
|
472
|
+
parent_object: Optional[dict[str, Any]] = None,
|
473
|
+
) -> dict[str, Any]:
|
474
|
+
to_object: dict[str, Any] = {}
|
475
|
+
if getv(from_object, ['environment']) is not None:
|
476
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
477
|
+
|
478
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
479
|
+
setv(
|
480
|
+
to_object,
|
481
|
+
['excludedPredefinedFunctions'],
|
482
|
+
getv(from_object, ['excluded_predefined_functions']),
|
483
|
+
)
|
484
|
+
|
485
|
+
return to_object
|
486
|
+
|
487
|
+
|
470
488
|
def _ContentEmbedding_from_mldev(
|
471
489
|
from_object: Union[dict[str, Any], object],
|
472
490
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1131,6 +1149,13 @@ def _GenerateContentConfig_to_mldev(
|
|
1131
1149
|
),
|
1132
1150
|
)
|
1133
1151
|
|
1152
|
+
if getv(from_object, ['image_config']) is not None:
|
1153
|
+
setv(
|
1154
|
+
to_object,
|
1155
|
+
['imageConfig'],
|
1156
|
+
_ImageConfig_to_mldev(getv(from_object, ['image_config']), to_object),
|
1157
|
+
)
|
1158
|
+
|
1134
1159
|
return to_object
|
1135
1160
|
|
1136
1161
|
|
@@ -1238,6 +1263,17 @@ def _GoogleSearch_to_mldev(
|
|
1238
1263
|
return to_object
|
1239
1264
|
|
1240
1265
|
|
1266
|
+
def _ImageConfig_to_mldev(
|
1267
|
+
from_object: Union[dict[str, Any], object],
|
1268
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1269
|
+
) -> dict[str, Any]:
|
1270
|
+
to_object: dict[str, Any] = {}
|
1271
|
+
if getv(from_object, ['aspect_ratio']) is not None:
|
1272
|
+
setv(to_object, ['aspectRatio'], getv(from_object, ['aspect_ratio']))
|
1273
|
+
|
1274
|
+
return to_object
|
1275
|
+
|
1276
|
+
|
1241
1277
|
def _InlinedEmbedContentResponse_from_mldev(
|
1242
1278
|
from_object: Union[dict[str, Any], object],
|
1243
1279
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1877,24 +1913,6 @@ def _ThinkingConfig_to_mldev(
|
|
1877
1913
|
return to_object
|
1878
1914
|
|
1879
1915
|
|
1880
|
-
def _ToolComputerUse_to_mldev(
|
1881
|
-
from_object: Union[dict[str, Any], object],
|
1882
|
-
parent_object: Optional[dict[str, Any]] = None,
|
1883
|
-
) -> dict[str, Any]:
|
1884
|
-
to_object: dict[str, Any] = {}
|
1885
|
-
if getv(from_object, ['environment']) is not None:
|
1886
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
1887
|
-
|
1888
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
1889
|
-
setv(
|
1890
|
-
to_object,
|
1891
|
-
['excludedPredefinedFunctions'],
|
1892
|
-
getv(from_object, ['excluded_predefined_functions']),
|
1893
|
-
)
|
1894
|
-
|
1895
|
-
return to_object
|
1896
|
-
|
1897
|
-
|
1898
1916
|
def _ToolConfig_to_mldev(
|
1899
1917
|
from_object: Union[dict[str, Any], object],
|
1900
1918
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1974,9 +1992,7 @@ def _Tool_to_mldev(
|
|
1974
1992
|
setv(
|
1975
1993
|
to_object,
|
1976
1994
|
['computerUse'],
|
1977
|
-
|
1978
|
-
getv(from_object, ['computer_use']), to_object
|
1979
|
-
),
|
1995
|
+
_ComputerUse_to_mldev(getv(from_object, ['computer_use']), to_object),
|
1980
1996
|
)
|
1981
1997
|
|
1982
1998
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -181,6 +181,42 @@ def _CachedContent_from_vertex(
|
|
181
181
|
return to_object
|
182
182
|
|
183
183
|
|
184
|
+
def _ComputerUse_to_mldev(
|
185
|
+
from_object: Union[dict[str, Any], object],
|
186
|
+
parent_object: Optional[dict[str, Any]] = None,
|
187
|
+
) -> dict[str, Any]:
|
188
|
+
to_object: dict[str, Any] = {}
|
189
|
+
if getv(from_object, ['environment']) is not None:
|
190
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
191
|
+
|
192
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
193
|
+
setv(
|
194
|
+
to_object,
|
195
|
+
['excludedPredefinedFunctions'],
|
196
|
+
getv(from_object, ['excluded_predefined_functions']),
|
197
|
+
)
|
198
|
+
|
199
|
+
return to_object
|
200
|
+
|
201
|
+
|
202
|
+
def _ComputerUse_to_vertex(
|
203
|
+
from_object: Union[dict[str, Any], object],
|
204
|
+
parent_object: Optional[dict[str, Any]] = None,
|
205
|
+
) -> dict[str, Any]:
|
206
|
+
to_object: dict[str, Any] = {}
|
207
|
+
if getv(from_object, ['environment']) is not None:
|
208
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
209
|
+
|
210
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
211
|
+
setv(
|
212
|
+
to_object,
|
213
|
+
['excludedPredefinedFunctions'],
|
214
|
+
getv(from_object, ['excluded_predefined_functions']),
|
215
|
+
)
|
216
|
+
|
217
|
+
return to_object
|
218
|
+
|
219
|
+
|
184
220
|
def _Content_to_mldev(
|
185
221
|
from_object: Union[dict[str, Any], object],
|
186
222
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1135,42 +1171,6 @@ def _RetrievalConfig_to_vertex(
|
|
1135
1171
|
return to_object
|
1136
1172
|
|
1137
1173
|
|
1138
|
-
def _ToolComputerUse_to_mldev(
|
1139
|
-
from_object: Union[dict[str, Any], object],
|
1140
|
-
parent_object: Optional[dict[str, Any]] = None,
|
1141
|
-
) -> dict[str, Any]:
|
1142
|
-
to_object: dict[str, Any] = {}
|
1143
|
-
if getv(from_object, ['environment']) is not None:
|
1144
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
1145
|
-
|
1146
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
1147
|
-
setv(
|
1148
|
-
to_object,
|
1149
|
-
['excludedPredefinedFunctions'],
|
1150
|
-
getv(from_object, ['excluded_predefined_functions']),
|
1151
|
-
)
|
1152
|
-
|
1153
|
-
return to_object
|
1154
|
-
|
1155
|
-
|
1156
|
-
def _ToolComputerUse_to_vertex(
|
1157
|
-
from_object: Union[dict[str, Any], object],
|
1158
|
-
parent_object: Optional[dict[str, Any]] = None,
|
1159
|
-
) -> dict[str, Any]:
|
1160
|
-
to_object: dict[str, Any] = {}
|
1161
|
-
if getv(from_object, ['environment']) is not None:
|
1162
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
1163
|
-
|
1164
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
1165
|
-
setv(
|
1166
|
-
to_object,
|
1167
|
-
['excludedPredefinedFunctions'],
|
1168
|
-
getv(from_object, ['excluded_predefined_functions']),
|
1169
|
-
)
|
1170
|
-
|
1171
|
-
return to_object
|
1172
|
-
|
1173
|
-
|
1174
1174
|
def _ToolConfig_to_mldev(
|
1175
1175
|
from_object: Union[dict[str, Any], object],
|
1176
1176
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1276,9 +1276,7 @@ def _Tool_to_mldev(
|
|
1276
1276
|
setv(
|
1277
1277
|
to_object,
|
1278
1278
|
['computerUse'],
|
1279
|
-
|
1280
|
-
getv(from_object, ['computer_use']), to_object
|
1281
|
-
),
|
1279
|
+
_ComputerUse_to_mldev(getv(from_object, ['computer_use']), to_object),
|
1282
1280
|
)
|
1283
1281
|
|
1284
1282
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -1350,9 +1348,7 @@ def _Tool_to_vertex(
|
|
1350
1348
|
setv(
|
1351
1349
|
to_object,
|
1352
1350
|
['computerUse'],
|
1353
|
-
|
1354
|
-
getv(from_object, ['computer_use']), to_object
|
1355
|
-
),
|
1351
|
+
_ComputerUse_to_vertex(getv(from_object, ['computer_use']), to_object),
|
1356
1352
|
)
|
1357
1353
|
|
1358
1354
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -18,13 +18,13 @@
|
|
18
18
|
import io
|
19
19
|
import json
|
20
20
|
import logging
|
21
|
-
import mimetypes
|
22
21
|
import os
|
23
22
|
from typing import Any, Optional, Union
|
24
23
|
from urllib.parse import urlencode
|
25
24
|
|
26
25
|
from . import _api_module
|
27
26
|
from . import _common
|
27
|
+
from . import _extra_utils
|
28
28
|
from . import _transformers as t
|
29
29
|
from . import types
|
30
30
|
from ._common import get_value_by_path as getv
|
@@ -611,54 +611,13 @@ class Files(_api_module.BaseModule):
|
|
611
611
|
if file_obj.name is not None and not file_obj.name.startswith('files/'):
|
612
612
|
file_obj.name = f'files/{file_obj.name}'
|
613
613
|
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
if 'b' not in file.mode:
|
622
|
-
raise ValueError('The file must be opened in binary mode.')
|
623
|
-
offset = file.tell()
|
624
|
-
file.seek(0, os.SEEK_END)
|
625
|
-
file_obj.size_bytes = file.tell() - offset
|
626
|
-
file.seek(offset, os.SEEK_SET)
|
627
|
-
else:
|
628
|
-
fs_path = os.fspath(file)
|
629
|
-
if not fs_path or not os.path.isfile(fs_path):
|
630
|
-
raise FileNotFoundError(f'{file} is not a valid file path.')
|
631
|
-
file_obj.size_bytes = os.path.getsize(fs_path)
|
632
|
-
if file_obj.mime_type is None:
|
633
|
-
file_obj.mime_type, _ = mimetypes.guess_type(fs_path)
|
634
|
-
if file_obj.mime_type is None:
|
635
|
-
raise ValueError(
|
636
|
-
'Unknown mime type: Could not determine the mimetype for your'
|
637
|
-
' file\n please set the `mime_type` argument'
|
638
|
-
)
|
639
|
-
|
640
|
-
http_options: types.HttpOptions
|
641
|
-
if config_model and config_model.http_options:
|
642
|
-
http_options = config_model.http_options
|
643
|
-
http_options.api_version = ''
|
644
|
-
http_options.headers = {
|
645
|
-
'Content-Type': 'application/json',
|
646
|
-
'X-Goog-Upload-Protocol': 'resumable',
|
647
|
-
'X-Goog-Upload-Command': 'start',
|
648
|
-
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
649
|
-
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
650
|
-
}
|
651
|
-
else:
|
652
|
-
http_options = types.HttpOptions(
|
653
|
-
api_version='',
|
654
|
-
headers={
|
655
|
-
'Content-Type': 'application/json',
|
656
|
-
'X-Goog-Upload-Protocol': 'resumable',
|
657
|
-
'X-Goog-Upload-Command': 'start',
|
658
|
-
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
659
|
-
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
660
|
-
},
|
661
|
-
)
|
614
|
+
http_options, size_bytes, mime_type = _extra_utils.prepare_resumable_upload(
|
615
|
+
file,
|
616
|
+
user_http_options=config_model.http_options,
|
617
|
+
user_mime_type=config_model.mime_type,
|
618
|
+
)
|
619
|
+
file_obj.size_bytes = size_bytes
|
620
|
+
file_obj.mime_type = mime_type
|
662
621
|
response = self._create(
|
663
622
|
file=file_obj,
|
664
623
|
config=types.CreateFileConfig(
|
@@ -682,6 +641,7 @@ class Files(_api_module.BaseModule):
|
|
682
641
|
file, upload_url, file_obj.size_bytes, http_options=http_options
|
683
642
|
)
|
684
643
|
else:
|
644
|
+
fs_path = os.fspath(file)
|
685
645
|
return_file = self._api_client.upload_file(
|
686
646
|
fs_path, upload_url, file_obj.size_bytes, http_options=http_options
|
687
647
|
)
|
@@ -1096,54 +1056,13 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1096
1056
|
if file_obj.name is not None and not file_obj.name.startswith('files/'):
|
1097
1057
|
file_obj.name = f'files/{file_obj.name}'
|
1098
1058
|
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
if 'b' not in file.mode:
|
1107
|
-
raise ValueError('The file must be opened in binary mode.')
|
1108
|
-
offset = file.tell()
|
1109
|
-
file.seek(0, os.SEEK_END)
|
1110
|
-
file_obj.size_bytes = file.tell() - offset
|
1111
|
-
file.seek(offset, os.SEEK_SET)
|
1112
|
-
else:
|
1113
|
-
fs_path = os.fspath(file)
|
1114
|
-
if not fs_path or not os.path.isfile(fs_path):
|
1115
|
-
raise FileNotFoundError(f'{file} is not a valid file path.')
|
1116
|
-
file_obj.size_bytes = os.path.getsize(fs_path)
|
1117
|
-
if file_obj.mime_type is None:
|
1118
|
-
file_obj.mime_type, _ = mimetypes.guess_type(fs_path)
|
1119
|
-
if file_obj.mime_type is None:
|
1120
|
-
raise ValueError(
|
1121
|
-
'Unknown mime type: Could not determine the mimetype for your'
|
1122
|
-
' file\n please set the `mime_type` argument'
|
1123
|
-
)
|
1124
|
-
|
1125
|
-
http_options: types.HttpOptions
|
1126
|
-
if config_model and config_model.http_options:
|
1127
|
-
http_options = config_model.http_options
|
1128
|
-
http_options.api_version = ''
|
1129
|
-
http_options.headers = {
|
1130
|
-
'Content-Type': 'application/json',
|
1131
|
-
'X-Goog-Upload-Protocol': 'resumable',
|
1132
|
-
'X-Goog-Upload-Command': 'start',
|
1133
|
-
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
1134
|
-
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
1135
|
-
}
|
1136
|
-
else:
|
1137
|
-
http_options = types.HttpOptions(
|
1138
|
-
api_version='',
|
1139
|
-
headers={
|
1140
|
-
'Content-Type': 'application/json',
|
1141
|
-
'X-Goog-Upload-Protocol': 'resumable',
|
1142
|
-
'X-Goog-Upload-Command': 'start',
|
1143
|
-
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
1144
|
-
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
1145
|
-
},
|
1146
|
-
)
|
1059
|
+
http_options, size_bytes, mime_type = _extra_utils.prepare_resumable_upload(
|
1060
|
+
file,
|
1061
|
+
user_http_options=config_model.http_options,
|
1062
|
+
user_mime_type=config_model.mime_type,
|
1063
|
+
)
|
1064
|
+
file_obj.size_bytes = size_bytes
|
1065
|
+
file_obj.mime_type = mime_type
|
1147
1066
|
response = await self._create(
|
1148
1067
|
file=file_obj,
|
1149
1068
|
config=types.CreateFileConfig(
|
@@ -1172,6 +1091,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1172
1091
|
file, upload_url, file_obj.size_bytes, http_options=http_options
|
1173
1092
|
)
|
1174
1093
|
else:
|
1094
|
+
fs_path = os.fspath(file)
|
1175
1095
|
return_file = await self._api_client.async_upload_file(
|
1176
1096
|
fs_path, upload_url, file_obj.size_bytes, http_options=http_options
|
1177
1097
|
)
|
@@ -82,9 +82,15 @@ _FUNCTION_RESPONSE_REQUIRES_ID = (
|
|
82
82
|
class AsyncSession:
|
83
83
|
"""[Preview] AsyncSession."""
|
84
84
|
|
85
|
-
def __init__(
|
85
|
+
def __init__(
|
86
|
+
self,
|
87
|
+
api_client: BaseApiClient,
|
88
|
+
websocket: ClientConnection,
|
89
|
+
session_id: Optional[str] = None,
|
90
|
+
):
|
86
91
|
self._api_client = api_client
|
87
92
|
self._ws = websocket
|
93
|
+
self.session_id = session_id
|
88
94
|
|
89
95
|
async def send(
|
90
96
|
self,
|
@@ -1054,11 +1060,34 @@ class AsyncLive(_api_module.BaseModule):
|
|
1054
1060
|
await ws.send(request)
|
1055
1061
|
try:
|
1056
1062
|
# websockets 14.0+
|
1057
|
-
|
1063
|
+
raw_response = await ws.recv(decode=False)
|
1058
1064
|
except TypeError:
|
1059
|
-
|
1065
|
+
raw_response = await ws.recv() # type: ignore[assignment]
|
1066
|
+
if raw_response:
|
1067
|
+
try:
|
1068
|
+
response = json.loads(raw_response)
|
1069
|
+
except json.decoder.JSONDecodeError:
|
1070
|
+
raise ValueError(f'Failed to parse response: {raw_response!r}')
|
1071
|
+
else:
|
1072
|
+
response = {}
|
1060
1073
|
|
1061
|
-
|
1074
|
+
if self._api_client.vertexai:
|
1075
|
+
response_dict = live_converters._LiveServerMessage_from_vertex(response)
|
1076
|
+
else:
|
1077
|
+
response_dict = live_converters._LiveServerMessage_from_mldev(response)
|
1078
|
+
|
1079
|
+
setup_response = types.LiveServerMessage._from_response(
|
1080
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
1081
|
+
)
|
1082
|
+
if setup_response.setup_complete:
|
1083
|
+
session_id = setup_response.setup_complete.session_id
|
1084
|
+
else:
|
1085
|
+
session_id = None
|
1086
|
+
yield AsyncSession(
|
1087
|
+
api_client=self._api_client,
|
1088
|
+
websocket=ws,
|
1089
|
+
session_id=session_id,
|
1090
|
+
)
|
1062
1091
|
|
1063
1092
|
|
1064
1093
|
async def _t_live_connect_config(
|
@@ -366,6 +366,42 @@ def _ComputeTokensResponse_from_vertex(
|
|
366
366
|
return to_object
|
367
367
|
|
368
368
|
|
369
|
+
def _ComputerUse_to_mldev(
|
370
|
+
from_object: Union[dict[str, Any], object],
|
371
|
+
parent_object: Optional[dict[str, Any]] = None,
|
372
|
+
) -> dict[str, Any]:
|
373
|
+
to_object: dict[str, Any] = {}
|
374
|
+
if getv(from_object, ['environment']) is not None:
|
375
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
376
|
+
|
377
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
378
|
+
setv(
|
379
|
+
to_object,
|
380
|
+
['excludedPredefinedFunctions'],
|
381
|
+
getv(from_object, ['excluded_predefined_functions']),
|
382
|
+
)
|
383
|
+
|
384
|
+
return to_object
|
385
|
+
|
386
|
+
|
387
|
+
def _ComputerUse_to_vertex(
|
388
|
+
from_object: Union[dict[str, Any], object],
|
389
|
+
parent_object: Optional[dict[str, Any]] = None,
|
390
|
+
) -> dict[str, Any]:
|
391
|
+
to_object: dict[str, Any] = {}
|
392
|
+
if getv(from_object, ['environment']) is not None:
|
393
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
394
|
+
|
395
|
+
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
396
|
+
setv(
|
397
|
+
to_object,
|
398
|
+
['excludedPredefinedFunctions'],
|
399
|
+
getv(from_object, ['excluded_predefined_functions']),
|
400
|
+
)
|
401
|
+
|
402
|
+
return to_object
|
403
|
+
|
404
|
+
|
369
405
|
def _ContentEmbeddingStatistics_from_vertex(
|
370
406
|
from_object: Union[dict[str, Any], object],
|
371
407
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1602,6 +1638,13 @@ def _GenerateContentConfig_to_mldev(
|
|
1602
1638
|
),
|
1603
1639
|
)
|
1604
1640
|
|
1641
|
+
if getv(from_object, ['image_config']) is not None:
|
1642
|
+
setv(
|
1643
|
+
to_object,
|
1644
|
+
['imageConfig'],
|
1645
|
+
_ImageConfig_to_mldev(getv(from_object, ['image_config']), to_object),
|
1646
|
+
)
|
1647
|
+
|
1605
1648
|
return to_object
|
1606
1649
|
|
1607
1650
|
|
@@ -1774,6 +1817,13 @@ def _GenerateContentConfig_to_vertex(
|
|
1774
1817
|
),
|
1775
1818
|
)
|
1776
1819
|
|
1820
|
+
if getv(from_object, ['image_config']) is not None:
|
1821
|
+
setv(
|
1822
|
+
to_object,
|
1823
|
+
['imageConfig'],
|
1824
|
+
_ImageConfig_to_vertex(getv(from_object, ['image_config']), to_object),
|
1825
|
+
)
|
1826
|
+
|
1777
1827
|
return to_object
|
1778
1828
|
|
1779
1829
|
|
@@ -2960,6 +3010,28 @@ def _GoogleSearch_to_vertex(
|
|
2960
3010
|
return to_object
|
2961
3011
|
|
2962
3012
|
|
3013
|
+
def _ImageConfig_to_mldev(
|
3014
|
+
from_object: Union[dict[str, Any], object],
|
3015
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3016
|
+
) -> dict[str, Any]:
|
3017
|
+
to_object: dict[str, Any] = {}
|
3018
|
+
if getv(from_object, ['aspect_ratio']) is not None:
|
3019
|
+
setv(to_object, ['aspectRatio'], getv(from_object, ['aspect_ratio']))
|
3020
|
+
|
3021
|
+
return to_object
|
3022
|
+
|
3023
|
+
|
3024
|
+
def _ImageConfig_to_vertex(
|
3025
|
+
from_object: Union[dict[str, Any], object],
|
3026
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3027
|
+
) -> dict[str, Any]:
|
3028
|
+
to_object: dict[str, Any] = {}
|
3029
|
+
if getv(from_object, ['aspect_ratio']) is not None:
|
3030
|
+
setv(to_object, ['aspectRatio'], getv(from_object, ['aspect_ratio']))
|
3031
|
+
|
3032
|
+
return to_object
|
3033
|
+
|
3034
|
+
|
2963
3035
|
def _Image_from_mldev(
|
2964
3036
|
from_object: Union[dict[str, Any], object],
|
2965
3037
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -4467,42 +4539,6 @@ def _ThinkingConfig_to_vertex(
|
|
4467
4539
|
return to_object
|
4468
4540
|
|
4469
4541
|
|
4470
|
-
def _ToolComputerUse_to_mldev(
|
4471
|
-
from_object: Union[dict[str, Any], object],
|
4472
|
-
parent_object: Optional[dict[str, Any]] = None,
|
4473
|
-
) -> dict[str, Any]:
|
4474
|
-
to_object: dict[str, Any] = {}
|
4475
|
-
if getv(from_object, ['environment']) is not None:
|
4476
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
4477
|
-
|
4478
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
4479
|
-
setv(
|
4480
|
-
to_object,
|
4481
|
-
['excludedPredefinedFunctions'],
|
4482
|
-
getv(from_object, ['excluded_predefined_functions']),
|
4483
|
-
)
|
4484
|
-
|
4485
|
-
return to_object
|
4486
|
-
|
4487
|
-
|
4488
|
-
def _ToolComputerUse_to_vertex(
|
4489
|
-
from_object: Union[dict[str, Any], object],
|
4490
|
-
parent_object: Optional[dict[str, Any]] = None,
|
4491
|
-
) -> dict[str, Any]:
|
4492
|
-
to_object: dict[str, Any] = {}
|
4493
|
-
if getv(from_object, ['environment']) is not None:
|
4494
|
-
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
4495
|
-
|
4496
|
-
if getv(from_object, ['excluded_predefined_functions']) is not None:
|
4497
|
-
setv(
|
4498
|
-
to_object,
|
4499
|
-
['excludedPredefinedFunctions'],
|
4500
|
-
getv(from_object, ['excluded_predefined_functions']),
|
4501
|
-
)
|
4502
|
-
|
4503
|
-
return to_object
|
4504
|
-
|
4505
|
-
|
4506
4542
|
def _ToolConfig_to_mldev(
|
4507
4543
|
from_object: Union[dict[str, Any], object],
|
4508
4544
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -4608,9 +4644,7 @@ def _Tool_to_mldev(
|
|
4608
4644
|
setv(
|
4609
4645
|
to_object,
|
4610
4646
|
['computerUse'],
|
4611
|
-
|
4612
|
-
getv(from_object, ['computer_use']), to_object
|
4613
|
-
),
|
4647
|
+
_ComputerUse_to_mldev(getv(from_object, ['computer_use']), to_object),
|
4614
4648
|
)
|
4615
4649
|
|
4616
4650
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -4682,9 +4716,7 @@ def _Tool_to_vertex(
|
|
4682
4716
|
setv(
|
4683
4717
|
to_object,
|
4684
4718
|
['computerUse'],
|
4685
|
-
|
4686
|
-
getv(from_object, ['computer_use']), to_object
|
4687
|
-
),
|
4719
|
+
_ComputerUse_to_vertex(getv(from_object, ['computer_use']), to_object),
|
4688
4720
|
)
|
4689
4721
|
|
4690
4722
|
if getv(from_object, ['code_execution']) is not None:
|
@@ -753,6 +753,9 @@ def _TuningJob_from_mldev(
|
|
753
753
|
getv(from_object, ['tunedModelDisplayName']),
|
754
754
|
)
|
755
755
|
|
756
|
+
if getv(from_object, ['veoTuningSpec']) is not None:
|
757
|
+
setv(to_object, ['veo_tuning_spec'], getv(from_object, ['veoTuningSpec']))
|
758
|
+
|
756
759
|
return to_object
|
757
760
|
|
758
761
|
|
@@ -865,6 +868,9 @@ def _TuningJob_from_vertex(
|
|
865
868
|
getv(from_object, ['tunedModelDisplayName']),
|
866
869
|
)
|
867
870
|
|
871
|
+
if getv(from_object, ['veoTuningSpec']) is not None:
|
872
|
+
setv(to_object, ['veo_tuning_spec'], getv(from_object, ['veoTuningSpec']))
|
873
|
+
|
868
874
|
return to_object
|
869
875
|
|
870
876
|
|
@@ -285,6 +285,10 @@ class FinishReason(_common.CaseInSensitiveEnum):
|
|
285
285
|
"""Token generation stopped because generated images have safety violations."""
|
286
286
|
UNEXPECTED_TOOL_CALL = 'UNEXPECTED_TOOL_CALL'
|
287
287
|
"""The tool call generated by the model is invalid."""
|
288
|
+
IMAGE_PROHIBITED_CONTENT = 'IMAGE_PROHIBITED_CONTENT'
|
289
|
+
"""Image generation stopped because the generated images have prohibited content."""
|
290
|
+
NO_IMAGE = 'NO_IMAGE'
|
291
|
+
"""The model was expected to generate an image, but none was generated."""
|
288
292
|
|
289
293
|
|
290
294
|
class HarmProbability(_common.CaseInSensitiveEnum):
|
@@ -434,6 +438,17 @@ class AdapterSize(_common.CaseInSensitiveEnum):
|
|
434
438
|
"""Adapter size 32."""
|
435
439
|
|
436
440
|
|
441
|
+
class TuningTask(_common.CaseInSensitiveEnum):
|
442
|
+
"""Optional. The tuning task. Either I2V or T2V."""
|
443
|
+
|
444
|
+
TUNING_TASK_UNSPECIFIED = 'TUNING_TASK_UNSPECIFIED'
|
445
|
+
"""Default value. This value is unused."""
|
446
|
+
TUNING_TASK_I2V = 'TUNING_TASK_I2V'
|
447
|
+
"""Tuning task for image to video."""
|
448
|
+
TUNING_TASK_T2V = 'TUNING_TASK_T2V'
|
449
|
+
"""Tuning task for text to video."""
|
450
|
+
|
451
|
+
|
437
452
|
class JSONSchemaType(Enum):
|
438
453
|
"""The type of the data supported by JSON Schema.
|
439
454
|
|
@@ -2795,7 +2810,7 @@ class UrlContextDict(TypedDict, total=False):
|
|
2795
2810
|
UrlContextOrDict = Union[UrlContext, UrlContextDict]
|
2796
2811
|
|
2797
2812
|
|
2798
|
-
class
|
2813
|
+
class ComputerUse(_common.BaseModel):
|
2799
2814
|
"""Tool to support computer use."""
|
2800
2815
|
|
2801
2816
|
environment: Optional[Environment] = Field(
|
@@ -2811,7 +2826,7 @@ class ToolComputerUse(_common.BaseModel):
|
|
2811
2826
|
)
|
2812
2827
|
|
2813
2828
|
|
2814
|
-
class
|
2829
|
+
class ComputerUseDict(TypedDict, total=False):
|
2815
2830
|
"""Tool to support computer use."""
|
2816
2831
|
|
2817
2832
|
environment: Optional[Environment]
|
@@ -2825,7 +2840,7 @@ class ToolComputerUseDict(TypedDict, total=False):
|
|
2825
2840
|
2. Improving the definitions / instructions of predefined functions."""
|
2826
2841
|
|
2827
2842
|
|
2828
|
-
|
2843
|
+
ComputerUseOrDict = Union[ComputerUse, ComputerUseDict]
|
2829
2844
|
|
2830
2845
|
|
2831
2846
|
class ApiAuthApiKeyConfig(_common.BaseModel):
|
@@ -3422,7 +3437,7 @@ class Tool(_common.BaseModel):
|
|
3422
3437
|
default=None,
|
3423
3438
|
description="""Optional. Tool to support URL context retrieval.""",
|
3424
3439
|
)
|
3425
|
-
computer_use: Optional[
|
3440
|
+
computer_use: Optional[ComputerUse] = Field(
|
3426
3441
|
default=None,
|
3427
3442
|
description="""Optional. Tool to support the model interacting directly with the
|
3428
3443
|
computer. If enabled, it automatically populates computer-use specific
|
@@ -3461,7 +3476,7 @@ class ToolDict(TypedDict, total=False):
|
|
3461
3476
|
url_context: Optional[UrlContextDict]
|
3462
3477
|
"""Optional. Tool to support URL context retrieval."""
|
3463
3478
|
|
3464
|
-
computer_use: Optional[
|
3479
|
+
computer_use: Optional[ComputerUseDict]
|
3465
3480
|
"""Optional. Tool to support the model interacting directly with the
|
3466
3481
|
computer. If enabled, it automatically populates computer-use specific
|
3467
3482
|
Function Declarations."""
|
@@ -3826,6 +3841,27 @@ class ThinkingConfigDict(TypedDict, total=False):
|
|
3826
3841
|
ThinkingConfigOrDict = Union[ThinkingConfig, ThinkingConfigDict]
|
3827
3842
|
|
3828
3843
|
|
3844
|
+
class ImageConfig(_common.BaseModel):
|
3845
|
+
"""The image generation configuration to be used in GenerateContentConfig."""
|
3846
|
+
|
3847
|
+
aspect_ratio: Optional[str] = Field(
|
3848
|
+
default=None,
|
3849
|
+
description="""Aspect ratio of the generated images. Supported values are
|
3850
|
+
"1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", and "21:9".""",
|
3851
|
+
)
|
3852
|
+
|
3853
|
+
|
3854
|
+
class ImageConfigDict(TypedDict, total=False):
|
3855
|
+
"""The image generation configuration to be used in GenerateContentConfig."""
|
3856
|
+
|
3857
|
+
aspect_ratio: Optional[str]
|
3858
|
+
"""Aspect ratio of the generated images. Supported values are
|
3859
|
+
"1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", and "21:9"."""
|
3860
|
+
|
3861
|
+
|
3862
|
+
ImageConfigOrDict = Union[ImageConfig, ImageConfigDict]
|
3863
|
+
|
3864
|
+
|
3829
3865
|
class FileStatus(_common.BaseModel):
|
3830
3866
|
"""Status of a File that uses a common error model."""
|
3831
3867
|
|
@@ -4263,6 +4299,11 @@ class GenerateContentConfig(_common.BaseModel):
|
|
4263
4299
|
description="""The thinking features configuration.
|
4264
4300
|
""",
|
4265
4301
|
)
|
4302
|
+
image_config: Optional[ImageConfig] = Field(
|
4303
|
+
default=None,
|
4304
|
+
description="""The image generation configuration.
|
4305
|
+
""",
|
4306
|
+
)
|
4266
4307
|
|
4267
4308
|
@pydantic.field_validator('response_schema', mode='before')
|
4268
4309
|
@classmethod
|
@@ -4278,6 +4319,15 @@ class GenerateContentConfig(_common.BaseModel):
|
|
4278
4319
|
return Enum('PlaceholderLiteralEnum', {s: s for s in enum_vals})
|
4279
4320
|
return value
|
4280
4321
|
|
4322
|
+
@pydantic.field_validator('image_config', mode='before')
|
4323
|
+
@classmethod
|
4324
|
+
def _check_image_config_type(cls, value: Any) -> Any:
|
4325
|
+
if isinstance(value, GenerateImagesConfig):
|
4326
|
+
raise ValueError(
|
4327
|
+
'image_config must be an instance of ImageConfig or compatible dict.'
|
4328
|
+
)
|
4329
|
+
return value
|
4330
|
+
|
4281
4331
|
|
4282
4332
|
class GenerateContentConfigDict(TypedDict, total=False):
|
4283
4333
|
"""Optional model configuration parameters.
|
@@ -4452,6 +4502,10 @@ class GenerateContentConfigDict(TypedDict, total=False):
|
|
4452
4502
|
"""The thinking features configuration.
|
4453
4503
|
"""
|
4454
4504
|
|
4505
|
+
image_config: Optional[ImageConfigDict]
|
4506
|
+
"""The image generation configuration.
|
4507
|
+
"""
|
4508
|
+
|
4455
4509
|
|
4456
4510
|
GenerateContentConfigOrDict = Union[
|
4457
4511
|
GenerateContentConfig, GenerateContentConfigDict
|
@@ -10134,6 +10188,71 @@ PartnerModelTuningSpecOrDict = Union[
|
|
10134
10188
|
]
|
10135
10189
|
|
10136
10190
|
|
10191
|
+
class VeoHyperParameters(_common.BaseModel):
|
10192
|
+
"""Hyperparameters for Veo."""
|
10193
|
+
|
10194
|
+
epoch_count: Optional[int] = Field(
|
10195
|
+
default=None,
|
10196
|
+
description="""Optional. Number of complete passes the model makes over the entire training dataset during training.""",
|
10197
|
+
)
|
10198
|
+
learning_rate_multiplier: Optional[float] = Field(
|
10199
|
+
default=None,
|
10200
|
+
description="""Optional. Multiplier for adjusting the default learning rate.""",
|
10201
|
+
)
|
10202
|
+
tuning_task: Optional[TuningTask] = Field(
|
10203
|
+
default=None,
|
10204
|
+
description="""Optional. The tuning task. Either I2V or T2V.""",
|
10205
|
+
)
|
10206
|
+
|
10207
|
+
|
10208
|
+
class VeoHyperParametersDict(TypedDict, total=False):
|
10209
|
+
"""Hyperparameters for Veo."""
|
10210
|
+
|
10211
|
+
epoch_count: Optional[int]
|
10212
|
+
"""Optional. Number of complete passes the model makes over the entire training dataset during training."""
|
10213
|
+
|
10214
|
+
learning_rate_multiplier: Optional[float]
|
10215
|
+
"""Optional. Multiplier for adjusting the default learning rate."""
|
10216
|
+
|
10217
|
+
tuning_task: Optional[TuningTask]
|
10218
|
+
"""Optional. The tuning task. Either I2V or T2V."""
|
10219
|
+
|
10220
|
+
|
10221
|
+
VeoHyperParametersOrDict = Union[VeoHyperParameters, VeoHyperParametersDict]
|
10222
|
+
|
10223
|
+
|
10224
|
+
class VeoTuningSpec(_common.BaseModel):
|
10225
|
+
"""Tuning Spec for Veo Model Tuning."""
|
10226
|
+
|
10227
|
+
hyper_parameters: Optional[VeoHyperParameters] = Field(
|
10228
|
+
default=None, description="""Optional. Hyperparameters for Veo."""
|
10229
|
+
)
|
10230
|
+
training_dataset_uri: Optional[str] = Field(
|
10231
|
+
default=None,
|
10232
|
+
description="""Required. Training dataset used for tuning. The dataset can be specified as either a Cloud Storage path to a JSONL file or as the resource name of a Vertex Multimodal Dataset.""",
|
10233
|
+
)
|
10234
|
+
validation_dataset_uri: Optional[str] = Field(
|
10235
|
+
default=None,
|
10236
|
+
description="""Optional. Validation dataset used for tuning. The dataset can be specified as either a Cloud Storage path to a JSONL file or as the resource name of a Vertex Multimodal Dataset.""",
|
10237
|
+
)
|
10238
|
+
|
10239
|
+
|
10240
|
+
class VeoTuningSpecDict(TypedDict, total=False):
|
10241
|
+
"""Tuning Spec for Veo Model Tuning."""
|
10242
|
+
|
10243
|
+
hyper_parameters: Optional[VeoHyperParametersDict]
|
10244
|
+
"""Optional. Hyperparameters for Veo."""
|
10245
|
+
|
10246
|
+
training_dataset_uri: Optional[str]
|
10247
|
+
"""Required. Training dataset used for tuning. The dataset can be specified as either a Cloud Storage path to a JSONL file or as the resource name of a Vertex Multimodal Dataset."""
|
10248
|
+
|
10249
|
+
validation_dataset_uri: Optional[str]
|
10250
|
+
"""Optional. Validation dataset used for tuning. The dataset can be specified as either a Cloud Storage path to a JSONL file or as the resource name of a Vertex Multimodal Dataset."""
|
10251
|
+
|
10252
|
+
|
10253
|
+
VeoTuningSpecOrDict = Union[VeoTuningSpec, VeoTuningSpecDict]
|
10254
|
+
|
10255
|
+
|
10137
10256
|
class TuningJob(_common.BaseModel):
|
10138
10257
|
"""A tuning job."""
|
10139
10258
|
|
@@ -10229,6 +10348,9 @@ class TuningJob(_common.BaseModel):
|
|
10229
10348
|
default=None,
|
10230
10349
|
description="""Optional. The display name of the TunedModel. The name can be up to 128 characters long and can consist of any UTF-8 characters.""",
|
10231
10350
|
)
|
10351
|
+
veo_tuning_spec: Optional[VeoTuningSpec] = Field(
|
10352
|
+
default=None, description="""Tuning Spec for Veo Tuning."""
|
10353
|
+
)
|
10232
10354
|
|
10233
10355
|
@property
|
10234
10356
|
def has_ended(self) -> bool:
|
@@ -10316,6 +10438,9 @@ class TuningJobDict(TypedDict, total=False):
|
|
10316
10438
|
tuned_model_display_name: Optional[str]
|
10317
10439
|
"""Optional. The display name of the TunedModel. The name can be up to 128 characters long and can consist of any UTF-8 characters."""
|
10318
10440
|
|
10441
|
+
veo_tuning_spec: Optional[VeoTuningSpecDict]
|
10442
|
+
"""Tuning Spec for Veo Tuning."""
|
10443
|
+
|
10319
10444
|
|
10320
10445
|
TuningJobOrDict = Union[TuningJob, TuningJobDict]
|
10321
10446
|
|
@@ -14594,6 +14719,13 @@ class LiveConnectConfig(_common.BaseModel):
|
|
14594
14719
|
description="""The speech generation configuration.
|
14595
14720
|
""",
|
14596
14721
|
)
|
14722
|
+
thinking_config: Optional[ThinkingConfig] = Field(
|
14723
|
+
default=None,
|
14724
|
+
description="""Config for thinking features.
|
14725
|
+
An error will be returned if this field is set for models that don't
|
14726
|
+
support thinking.
|
14727
|
+
""",
|
14728
|
+
)
|
14597
14729
|
enable_affective_dialog: Optional[bool] = Field(
|
14598
14730
|
default=None,
|
14599
14731
|
description="""If enabled, the model will detect emotions and adapt its responses accordingly.""",
|
@@ -14699,6 +14831,12 @@ class LiveConnectConfigDict(TypedDict, total=False):
|
|
14699
14831
|
"""The speech generation configuration.
|
14700
14832
|
"""
|
14701
14833
|
|
14834
|
+
thinking_config: Optional[ThinkingConfigDict]
|
14835
|
+
"""Config for thinking features.
|
14836
|
+
An error will be returned if this field is set for models that don't
|
14837
|
+
support thinking.
|
14838
|
+
"""
|
14839
|
+
|
14702
14840
|
enable_affective_dialog: Optional[bool]
|
14703
14841
|
"""If enabled, the model will detect emotions and adapt its responses accordingly."""
|
14704
14842
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{google_genai-1.39.1 → google_genai-1.41.0}/google/genai/_automatic_function_calling_util.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|