google-genai 1.30.0__py3-none-any.whl → 1.32.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/_api_client.py +32 -32
- google/genai/_automatic_function_calling_util.py +12 -0
- google/genai/_base_transformers.py +26 -0
- google/genai/_live_converters.py +1 -0
- google/genai/_local_tokenizer_loader.py +223 -0
- google/genai/_operations_converters.py +307 -0
- google/genai/_tokens_converters.py +1 -0
- google/genai/_transformers.py +0 -10
- google/genai/batches.py +141 -0
- google/genai/caches.py +15 -2
- google/genai/files.py +11 -2
- google/genai/local_tokenizer.py +362 -0
- google/genai/models.py +518 -17
- google/genai/operations.py +1 -0
- google/genai/tunings.py +135 -0
- google/genai/types.py +781 -323
- google/genai/version.py +1 -1
- {google_genai-1.30.0.dist-info → google_genai-1.32.0.dist-info}/METADATA +6 -6
- google_genai-1.32.0.dist-info/RECORD +39 -0
- google_genai-1.30.0.dist-info/RECORD +0 -35
- {google_genai-1.30.0.dist-info → google_genai-1.32.0.dist-info}/WHEEL +0 -0
- {google_genai-1.30.0.dist-info → google_genai-1.32.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.30.0.dist-info → google_genai-1.32.0.dist-info}/top_level.txt +0 -0
google/genai/models.py
CHANGED
@@ -21,6 +21,7 @@ from typing import Any, AsyncIterator, Awaitable, Iterator, Optional, Union
|
|
21
21
|
from urllib.parse import urlencode
|
22
22
|
|
23
23
|
from . import _api_module
|
24
|
+
from . import _base_transformers as base_t
|
24
25
|
from . import _common
|
25
26
|
from . import _extra_utils
|
26
27
|
from . import _mcp_utils
|
@@ -32,6 +33,7 @@ from ._common import get_value_by_path as getv
|
|
32
33
|
from ._common import set_value_by_path as setv
|
33
34
|
from .pagers import AsyncPager, Pager
|
34
35
|
|
36
|
+
|
35
37
|
logger = logging.getLogger('google_genai.models')
|
36
38
|
|
37
39
|
|
@@ -1259,7 +1261,7 @@ def _Image_to_mldev(
|
|
1259
1261
|
setv(
|
1260
1262
|
to_object,
|
1261
1263
|
['bytesBase64Encoded'],
|
1262
|
-
|
1264
|
+
base_t.t_bytes(getv(from_object, ['image_bytes'])),
|
1263
1265
|
)
|
1264
1266
|
|
1265
1267
|
if getv(from_object, ['mime_type']) is not None:
|
@@ -1268,6 +1270,29 @@ def _Image_to_mldev(
|
|
1268
1270
|
return to_object
|
1269
1271
|
|
1270
1272
|
|
1273
|
+
def _GenerateVideosSource_to_mldev(
|
1274
|
+
from_object: Union[dict[str, Any], object],
|
1275
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1276
|
+
) -> dict[str, Any]:
|
1277
|
+
to_object: dict[str, Any] = {}
|
1278
|
+
if getv(from_object, ['prompt']) is not None:
|
1279
|
+
setv(
|
1280
|
+
parent_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt'])
|
1281
|
+
)
|
1282
|
+
|
1283
|
+
if getv(from_object, ['image']) is not None:
|
1284
|
+
setv(
|
1285
|
+
parent_object,
|
1286
|
+
['instances[0]', 'image'],
|
1287
|
+
_Image_to_mldev(getv(from_object, ['image']), to_object),
|
1288
|
+
)
|
1289
|
+
|
1290
|
+
if getv(from_object, ['video']) is not None:
|
1291
|
+
raise ValueError('video parameter is not supported in Gemini API.')
|
1292
|
+
|
1293
|
+
return to_object
|
1294
|
+
|
1295
|
+
|
1271
1296
|
def _GenerateVideosConfig_to_mldev(
|
1272
1297
|
from_object: Union[dict[str, Any], object],
|
1273
1298
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1337,6 +1362,11 @@ def _GenerateVideosConfig_to_mldev(
|
|
1337
1362
|
if getv(from_object, ['last_frame']) is not None:
|
1338
1363
|
raise ValueError('last_frame parameter is not supported in Gemini API.')
|
1339
1364
|
|
1365
|
+
if getv(from_object, ['reference_images']) is not None:
|
1366
|
+
raise ValueError(
|
1367
|
+
'reference_images parameter is not supported in Gemini API.'
|
1368
|
+
)
|
1369
|
+
|
1340
1370
|
if getv(from_object, ['compression_quality']) is not None:
|
1341
1371
|
raise ValueError(
|
1342
1372
|
'compression_quality parameter is not supported in Gemini API.'
|
@@ -1371,6 +1401,15 @@ def _GenerateVideosParameters_to_mldev(
|
|
1371
1401
|
if getv(from_object, ['video']) is not None:
|
1372
1402
|
raise ValueError('video parameter is not supported in Gemini API.')
|
1373
1403
|
|
1404
|
+
if getv(from_object, ['source']) is not None:
|
1405
|
+
setv(
|
1406
|
+
to_object,
|
1407
|
+
['config'],
|
1408
|
+
_GenerateVideosSource_to_mldev(
|
1409
|
+
getv(from_object, ['source']), to_object
|
1410
|
+
),
|
1411
|
+
)
|
1412
|
+
|
1374
1413
|
if getv(from_object, ['config']) is not None:
|
1375
1414
|
setv(
|
1376
1415
|
to_object,
|
@@ -2496,7 +2535,7 @@ def _Image_to_vertex(
|
|
2496
2535
|
setv(
|
2497
2536
|
to_object,
|
2498
2537
|
['bytesBase64Encoded'],
|
2499
|
-
|
2538
|
+
base_t.t_bytes(getv(from_object, ['image_bytes'])),
|
2500
2539
|
)
|
2501
2540
|
|
2502
2541
|
if getv(from_object, ['mime_type']) is not None:
|
@@ -2791,6 +2830,13 @@ def _UpscaleImageAPIConfig_to_vertex(
|
|
2791
2830
|
) -> dict[str, Any]:
|
2792
2831
|
to_object: dict[str, Any] = {}
|
2793
2832
|
|
2833
|
+
if getv(from_object, ['output_gcs_uri']) is not None:
|
2834
|
+
setv(
|
2835
|
+
parent_object,
|
2836
|
+
['parameters', 'storageUri'],
|
2837
|
+
getv(from_object, ['output_gcs_uri']),
|
2838
|
+
)
|
2839
|
+
|
2794
2840
|
if getv(from_object, ['include_rai_reason']) is not None:
|
2795
2841
|
setv(
|
2796
2842
|
parent_object,
|
@@ -2967,6 +3013,13 @@ def _RecontextImageConfig_to_vertex(
|
|
2967
3013
|
getv(from_object, ['person_generation']),
|
2968
3014
|
)
|
2969
3015
|
|
3016
|
+
if getv(from_object, ['add_watermark']) is not None:
|
3017
|
+
setv(
|
3018
|
+
parent_object,
|
3019
|
+
['parameters', 'addWatermark'],
|
3020
|
+
getv(from_object, ['add_watermark']),
|
3021
|
+
)
|
3022
|
+
|
2970
3023
|
if getv(from_object, ['output_mime_type']) is not None:
|
2971
3024
|
setv(
|
2972
3025
|
parent_object,
|
@@ -3025,6 +3078,120 @@ def _RecontextImageParameters_to_vertex(
|
|
3025
3078
|
return to_object
|
3026
3079
|
|
3027
3080
|
|
3081
|
+
def _ScribbleImage_to_vertex(
|
3082
|
+
from_object: Union[dict[str, Any], object],
|
3083
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3084
|
+
) -> dict[str, Any]:
|
3085
|
+
to_object: dict[str, Any] = {}
|
3086
|
+
if getv(from_object, ['image']) is not None:
|
3087
|
+
setv(
|
3088
|
+
to_object,
|
3089
|
+
['image'],
|
3090
|
+
_Image_to_vertex(getv(from_object, ['image']), to_object),
|
3091
|
+
)
|
3092
|
+
|
3093
|
+
return to_object
|
3094
|
+
|
3095
|
+
|
3096
|
+
def _SegmentImageSource_to_vertex(
|
3097
|
+
from_object: Union[dict[str, Any], object],
|
3098
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3099
|
+
) -> dict[str, Any]:
|
3100
|
+
to_object: dict[str, Any] = {}
|
3101
|
+
if getv(from_object, ['prompt']) is not None:
|
3102
|
+
setv(
|
3103
|
+
parent_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt'])
|
3104
|
+
)
|
3105
|
+
|
3106
|
+
if getv(from_object, ['image']) is not None:
|
3107
|
+
setv(
|
3108
|
+
parent_object,
|
3109
|
+
['instances[0]', 'image'],
|
3110
|
+
_Image_to_vertex(getv(from_object, ['image']), to_object),
|
3111
|
+
)
|
3112
|
+
|
3113
|
+
if getv(from_object, ['scribble_image']) is not None:
|
3114
|
+
setv(
|
3115
|
+
parent_object,
|
3116
|
+
['instances[0]', 'scribble'],
|
3117
|
+
_ScribbleImage_to_vertex(
|
3118
|
+
getv(from_object, ['scribble_image']), to_object
|
3119
|
+
),
|
3120
|
+
)
|
3121
|
+
|
3122
|
+
return to_object
|
3123
|
+
|
3124
|
+
|
3125
|
+
def _SegmentImageConfig_to_vertex(
|
3126
|
+
from_object: Union[dict[str, Any], object],
|
3127
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3128
|
+
) -> dict[str, Any]:
|
3129
|
+
to_object: dict[str, Any] = {}
|
3130
|
+
|
3131
|
+
if getv(from_object, ['mode']) is not None:
|
3132
|
+
setv(parent_object, ['parameters', 'mode'], getv(from_object, ['mode']))
|
3133
|
+
|
3134
|
+
if getv(from_object, ['max_predictions']) is not None:
|
3135
|
+
setv(
|
3136
|
+
parent_object,
|
3137
|
+
['parameters', 'maxPredictions'],
|
3138
|
+
getv(from_object, ['max_predictions']),
|
3139
|
+
)
|
3140
|
+
|
3141
|
+
if getv(from_object, ['confidence_threshold']) is not None:
|
3142
|
+
setv(
|
3143
|
+
parent_object,
|
3144
|
+
['parameters', 'confidenceThreshold'],
|
3145
|
+
getv(from_object, ['confidence_threshold']),
|
3146
|
+
)
|
3147
|
+
|
3148
|
+
if getv(from_object, ['mask_dilation']) is not None:
|
3149
|
+
setv(
|
3150
|
+
parent_object,
|
3151
|
+
['parameters', 'maskDilation'],
|
3152
|
+
getv(from_object, ['mask_dilation']),
|
3153
|
+
)
|
3154
|
+
|
3155
|
+
if getv(from_object, ['binary_color_threshold']) is not None:
|
3156
|
+
setv(
|
3157
|
+
parent_object,
|
3158
|
+
['parameters', 'binaryColorThreshold'],
|
3159
|
+
getv(from_object, ['binary_color_threshold']),
|
3160
|
+
)
|
3161
|
+
|
3162
|
+
return to_object
|
3163
|
+
|
3164
|
+
|
3165
|
+
def _SegmentImageParameters_to_vertex(
|
3166
|
+
api_client: BaseApiClient,
|
3167
|
+
from_object: Union[dict[str, Any], object],
|
3168
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3169
|
+
) -> dict[str, Any]:
|
3170
|
+
to_object: dict[str, Any] = {}
|
3171
|
+
if getv(from_object, ['model']) is not None:
|
3172
|
+
setv(
|
3173
|
+
to_object,
|
3174
|
+
['_url', 'model'],
|
3175
|
+
t.t_model(api_client, getv(from_object, ['model'])),
|
3176
|
+
)
|
3177
|
+
|
3178
|
+
if getv(from_object, ['source']) is not None:
|
3179
|
+
setv(
|
3180
|
+
to_object,
|
3181
|
+
['config'],
|
3182
|
+
_SegmentImageSource_to_vertex(getv(from_object, ['source']), to_object),
|
3183
|
+
)
|
3184
|
+
|
3185
|
+
if getv(from_object, ['config']) is not None:
|
3186
|
+
setv(
|
3187
|
+
to_object,
|
3188
|
+
['config'],
|
3189
|
+
_SegmentImageConfig_to_vertex(getv(from_object, ['config']), to_object),
|
3190
|
+
)
|
3191
|
+
|
3192
|
+
return to_object
|
3193
|
+
|
3194
|
+
|
3028
3195
|
def _GetModelParameters_to_vertex(
|
3029
3196
|
api_client: BaseApiClient,
|
3030
3197
|
from_object: Union[dict[str, Any], object],
|
@@ -3267,7 +3434,7 @@ def _Video_to_vertex(
|
|
3267
3434
|
setv(
|
3268
3435
|
to_object,
|
3269
3436
|
['bytesBase64Encoded'],
|
3270
|
-
|
3437
|
+
base_t.t_bytes(getv(from_object, ['video_bytes'])),
|
3271
3438
|
)
|
3272
3439
|
|
3273
3440
|
if getv(from_object, ['mime_type']) is not None:
|
@@ -3276,6 +3443,51 @@ def _Video_to_vertex(
|
|
3276
3443
|
return to_object
|
3277
3444
|
|
3278
3445
|
|
3446
|
+
def _GenerateVideosSource_to_vertex(
|
3447
|
+
from_object: Union[dict[str, Any], object],
|
3448
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3449
|
+
) -> dict[str, Any]:
|
3450
|
+
to_object: dict[str, Any] = {}
|
3451
|
+
if getv(from_object, ['prompt']) is not None:
|
3452
|
+
setv(
|
3453
|
+
parent_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt'])
|
3454
|
+
)
|
3455
|
+
|
3456
|
+
if getv(from_object, ['image']) is not None:
|
3457
|
+
setv(
|
3458
|
+
parent_object,
|
3459
|
+
['instances[0]', 'image'],
|
3460
|
+
_Image_to_vertex(getv(from_object, ['image']), to_object),
|
3461
|
+
)
|
3462
|
+
|
3463
|
+
if getv(from_object, ['video']) is not None:
|
3464
|
+
setv(
|
3465
|
+
parent_object,
|
3466
|
+
['instances[0]', 'video'],
|
3467
|
+
_Video_to_vertex(getv(from_object, ['video']), to_object),
|
3468
|
+
)
|
3469
|
+
|
3470
|
+
return to_object
|
3471
|
+
|
3472
|
+
|
3473
|
+
def _VideoGenerationReferenceImage_to_vertex(
|
3474
|
+
from_object: Union[dict[str, Any], object],
|
3475
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3476
|
+
) -> dict[str, Any]:
|
3477
|
+
to_object: dict[str, Any] = {}
|
3478
|
+
if getv(from_object, ['image']) is not None:
|
3479
|
+
setv(
|
3480
|
+
to_object,
|
3481
|
+
['image'],
|
3482
|
+
_Image_to_vertex(getv(from_object, ['image']), to_object),
|
3483
|
+
)
|
3484
|
+
|
3485
|
+
if getv(from_object, ['reference_type']) is not None:
|
3486
|
+
setv(to_object, ['referenceType'], getv(from_object, ['reference_type']))
|
3487
|
+
|
3488
|
+
return to_object
|
3489
|
+
|
3490
|
+
|
3279
3491
|
def _GenerateVideosConfig_to_vertex(
|
3280
3492
|
from_object: Union[dict[str, Any], object],
|
3281
3493
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -3365,6 +3577,16 @@ def _GenerateVideosConfig_to_vertex(
|
|
3365
3577
|
_Image_to_vertex(getv(from_object, ['last_frame']), to_object),
|
3366
3578
|
)
|
3367
3579
|
|
3580
|
+
if getv(from_object, ['reference_images']) is not None:
|
3581
|
+
setv(
|
3582
|
+
parent_object,
|
3583
|
+
['instances[0]', 'referenceImages'],
|
3584
|
+
[
|
3585
|
+
_VideoGenerationReferenceImage_to_vertex(item, to_object)
|
3586
|
+
for item in getv(from_object, ['reference_images'])
|
3587
|
+
],
|
3588
|
+
)
|
3589
|
+
|
3368
3590
|
if getv(from_object, ['compression_quality']) is not None:
|
3369
3591
|
setv(
|
3370
3592
|
parent_object,
|
@@ -3405,6 +3627,15 @@ def _GenerateVideosParameters_to_vertex(
|
|
3405
3627
|
_Video_to_vertex(getv(from_object, ['video']), to_object),
|
3406
3628
|
)
|
3407
3629
|
|
3630
|
+
if getv(from_object, ['source']) is not None:
|
3631
|
+
setv(
|
3632
|
+
to_object,
|
3633
|
+
['config'],
|
3634
|
+
_GenerateVideosSource_to_vertex(
|
3635
|
+
getv(from_object, ['source']), to_object
|
3636
|
+
),
|
3637
|
+
)
|
3638
|
+
|
3408
3639
|
if getv(from_object, ['config']) is not None:
|
3409
3640
|
setv(
|
3410
3641
|
to_object,
|
@@ -3766,7 +3997,7 @@ def _Image_from_mldev(
|
|
3766
3997
|
setv(
|
3767
3998
|
to_object,
|
3768
3999
|
['image_bytes'],
|
3769
|
-
|
4000
|
+
base_t.t_bytes(getv(from_object, ['bytesBase64Encoded'])),
|
3770
4001
|
)
|
3771
4002
|
|
3772
4003
|
if getv(from_object, ['mimeType']) is not None:
|
@@ -3953,6 +4184,10 @@ def _DeleteModelResponse_from_mldev(
|
|
3953
4184
|
parent_object: Optional[dict[str, Any]] = None,
|
3954
4185
|
) -> dict[str, Any]:
|
3955
4186
|
to_object: dict[str, Any] = {}
|
4187
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
4188
|
+
setv(
|
4189
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
4190
|
+
)
|
3956
4191
|
|
3957
4192
|
return to_object
|
3958
4193
|
|
@@ -3992,7 +4227,7 @@ def _Video_from_mldev(
|
|
3992
4227
|
setv(
|
3993
4228
|
to_object,
|
3994
4229
|
['video_bytes'],
|
3995
|
-
|
4230
|
+
base_t.t_bytes(getv(from_object, ['video', 'encodedVideo'])),
|
3996
4231
|
)
|
3997
4232
|
|
3998
4233
|
if getv(from_object, ['encoding']) is not None:
|
@@ -4458,7 +4693,7 @@ def _Image_from_vertex(
|
|
4458
4693
|
setv(
|
4459
4694
|
to_object,
|
4460
4695
|
['image_bytes'],
|
4461
|
-
|
4696
|
+
base_t.t_bytes(getv(from_object, ['bytesBase64Encoded'])),
|
4462
4697
|
)
|
4463
4698
|
|
4464
4699
|
if getv(from_object, ['mimeType']) is not None:
|
@@ -4618,6 +4853,63 @@ def _RecontextImageResponse_from_vertex(
|
|
4618
4853
|
return to_object
|
4619
4854
|
|
4620
4855
|
|
4856
|
+
def _EntityLabel_from_vertex(
|
4857
|
+
from_object: Union[dict[str, Any], object],
|
4858
|
+
parent_object: Optional[dict[str, Any]] = None,
|
4859
|
+
) -> dict[str, Any]:
|
4860
|
+
to_object: dict[str, Any] = {}
|
4861
|
+
if getv(from_object, ['label']) is not None:
|
4862
|
+
setv(to_object, ['label'], getv(from_object, ['label']))
|
4863
|
+
|
4864
|
+
if getv(from_object, ['score']) is not None:
|
4865
|
+
setv(to_object, ['score'], getv(from_object, ['score']))
|
4866
|
+
|
4867
|
+
return to_object
|
4868
|
+
|
4869
|
+
|
4870
|
+
def _GeneratedImageMask_from_vertex(
|
4871
|
+
from_object: Union[dict[str, Any], object],
|
4872
|
+
parent_object: Optional[dict[str, Any]] = None,
|
4873
|
+
) -> dict[str, Any]:
|
4874
|
+
to_object: dict[str, Any] = {}
|
4875
|
+
if getv(from_object, ['_self']) is not None:
|
4876
|
+
setv(
|
4877
|
+
to_object,
|
4878
|
+
['mask'],
|
4879
|
+
_Image_from_vertex(getv(from_object, ['_self']), to_object),
|
4880
|
+
)
|
4881
|
+
|
4882
|
+
if getv(from_object, ['labels']) is not None:
|
4883
|
+
setv(
|
4884
|
+
to_object,
|
4885
|
+
['labels'],
|
4886
|
+
[
|
4887
|
+
_EntityLabel_from_vertex(item, to_object)
|
4888
|
+
for item in getv(from_object, ['labels'])
|
4889
|
+
],
|
4890
|
+
)
|
4891
|
+
|
4892
|
+
return to_object
|
4893
|
+
|
4894
|
+
|
4895
|
+
def _SegmentImageResponse_from_vertex(
|
4896
|
+
from_object: Union[dict[str, Any], object],
|
4897
|
+
parent_object: Optional[dict[str, Any]] = None,
|
4898
|
+
) -> dict[str, Any]:
|
4899
|
+
to_object: dict[str, Any] = {}
|
4900
|
+
if getv(from_object, ['predictions']) is not None:
|
4901
|
+
setv(
|
4902
|
+
to_object,
|
4903
|
+
['generated_masks'],
|
4904
|
+
[
|
4905
|
+
_GeneratedImageMask_from_vertex(item, to_object)
|
4906
|
+
for item in getv(from_object, ['predictions'])
|
4907
|
+
],
|
4908
|
+
)
|
4909
|
+
|
4910
|
+
return to_object
|
4911
|
+
|
4912
|
+
|
4621
4913
|
def _Endpoint_from_vertex(
|
4622
4914
|
from_object: Union[dict[str, Any], object],
|
4623
4915
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -4763,6 +5055,10 @@ def _DeleteModelResponse_from_vertex(
|
|
4763
5055
|
parent_object: Optional[dict[str, Any]] = None,
|
4764
5056
|
) -> dict[str, Any]:
|
4765
5057
|
to_object: dict[str, Any] = {}
|
5058
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
5059
|
+
setv(
|
5060
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
5061
|
+
)
|
4766
5062
|
|
4767
5063
|
return to_object
|
4768
5064
|
|
@@ -4811,7 +5107,7 @@ def _Video_from_vertex(
|
|
4811
5107
|
setv(
|
4812
5108
|
to_object,
|
4813
5109
|
['video_bytes'],
|
4814
|
-
|
5110
|
+
base_t.t_bytes(getv(from_object, ['bytesBase64Encoded'])),
|
4815
5111
|
)
|
4816
5112
|
|
4817
5113
|
if getv(from_object, ['mimeType']) is not None:
|
@@ -5511,6 +5807,89 @@ class Models(_api_module.BaseModule):
|
|
5511
5807
|
self._api_client._verify_response(return_value)
|
5512
5808
|
return return_value
|
5513
5809
|
|
5810
|
+
def segment_image(
|
5811
|
+
self,
|
5812
|
+
*,
|
5813
|
+
model: str,
|
5814
|
+
source: types.SegmentImageSourceOrDict,
|
5815
|
+
config: Optional[types.SegmentImageConfigOrDict] = None,
|
5816
|
+
) -> types.SegmentImageResponse:
|
5817
|
+
"""Segments an image, creating a mask of a specified area.
|
5818
|
+
|
5819
|
+
Args:
|
5820
|
+
model (str): The model to use.
|
5821
|
+
source (SegmentImageSource): An object containing the source inputs
|
5822
|
+
(prompt, image, scribble_image) for image segmentation. The prompt is
|
5823
|
+
required for prompt mode and semantic mode, disallowed for other modes.
|
5824
|
+
scribble_image is required for the interactive mode, disallowed for
|
5825
|
+
other modes.
|
5826
|
+
config (SegmentImageConfig): Configuration for segmentation.
|
5827
|
+
|
5828
|
+
Usage:
|
5829
|
+
|
5830
|
+
```
|
5831
|
+
response = client.models.segment_image(
|
5832
|
+
model="image-segmentation-001",
|
5833
|
+
source=types.SegmentImageSource(
|
5834
|
+
image=types.Image.from_file(IMAGE_FILE_PATH),
|
5835
|
+
),
|
5836
|
+
)
|
5837
|
+
|
5838
|
+
mask_image = response.generated_masks[0].mask
|
5839
|
+
```
|
5840
|
+
"""
|
5841
|
+
|
5842
|
+
parameter_model = types._SegmentImageParameters(
|
5843
|
+
model=model,
|
5844
|
+
source=source,
|
5845
|
+
config=config,
|
5846
|
+
)
|
5847
|
+
|
5848
|
+
request_url_dict: Optional[dict[str, str]]
|
5849
|
+
if not self._api_client.vertexai:
|
5850
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
5851
|
+
else:
|
5852
|
+
request_dict = _SegmentImageParameters_to_vertex(
|
5853
|
+
self._api_client, parameter_model
|
5854
|
+
)
|
5855
|
+
request_url_dict = request_dict.get('_url')
|
5856
|
+
if request_url_dict:
|
5857
|
+
path = '{model}:predict'.format_map(request_url_dict)
|
5858
|
+
else:
|
5859
|
+
path = '{model}:predict'
|
5860
|
+
|
5861
|
+
query_params = request_dict.get('_query')
|
5862
|
+
if query_params:
|
5863
|
+
path = f'{path}?{urlencode(query_params)}'
|
5864
|
+
# TODO: remove the hack that pops config.
|
5865
|
+
request_dict.pop('config', None)
|
5866
|
+
|
5867
|
+
http_options: Optional[types.HttpOptions] = None
|
5868
|
+
if (
|
5869
|
+
parameter_model.config is not None
|
5870
|
+
and parameter_model.config.http_options is not None
|
5871
|
+
):
|
5872
|
+
http_options = parameter_model.config.http_options
|
5873
|
+
|
5874
|
+
request_dict = _common.convert_to_dict(request_dict)
|
5875
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
5876
|
+
|
5877
|
+
response = self._api_client.request(
|
5878
|
+
'post', path, request_dict, http_options
|
5879
|
+
)
|
5880
|
+
|
5881
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
5882
|
+
|
5883
|
+
if self._api_client.vertexai:
|
5884
|
+
response_dict = _SegmentImageResponse_from_vertex(response_dict)
|
5885
|
+
|
5886
|
+
return_value = types.SegmentImageResponse._from_response(
|
5887
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
5888
|
+
)
|
5889
|
+
|
5890
|
+
self._api_client._verify_response(return_value)
|
5891
|
+
return return_value
|
5892
|
+
|
5514
5893
|
def get(
|
5515
5894
|
self, *, model: str, config: Optional[types.GetModelConfigOrDict] = None
|
5516
5895
|
) -> types.Model:
|
@@ -5762,7 +6141,9 @@ class Models(_api_module.BaseModule):
|
|
5762
6141
|
return_value = types.DeleteModelResponse._from_response(
|
5763
6142
|
response=response_dict, kwargs=parameter_model.model_dump()
|
5764
6143
|
)
|
5765
|
-
|
6144
|
+
return_value.sdk_http_response = types.HttpResponse(
|
6145
|
+
headers=response.headers
|
6146
|
+
)
|
5766
6147
|
self._api_client._verify_response(return_value)
|
5767
6148
|
return return_value
|
5768
6149
|
|
@@ -5947,6 +6328,7 @@ class Models(_api_module.BaseModule):
|
|
5947
6328
|
prompt: Optional[str] = None,
|
5948
6329
|
image: Optional[types.ImageOrDict] = None,
|
5949
6330
|
video: Optional[types.VideoOrDict] = None,
|
6331
|
+
source: Optional[types.GenerateVideosSourceOrDict] = None,
|
5950
6332
|
config: Optional[types.GenerateVideosConfigOrDict] = None,
|
5951
6333
|
) -> types.GenerateVideosOperation:
|
5952
6334
|
"""Generates videos based on an input (text, image, or video) and configuration.
|
@@ -5988,6 +6370,7 @@ class Models(_api_module.BaseModule):
|
|
5988
6370
|
prompt=prompt,
|
5989
6371
|
image=image,
|
5990
6372
|
video=video,
|
6373
|
+
source=source,
|
5991
6374
|
config=config,
|
5992
6375
|
)
|
5993
6376
|
|
@@ -6506,6 +6889,7 @@ class Models(_api_module.BaseModule):
|
|
6506
6889
|
config_dct = dict(config)
|
6507
6890
|
api_config = types._UpscaleImageAPIConfigDict(
|
6508
6891
|
http_options=config_dct.get('http_options', None),
|
6892
|
+
output_gcs_uri=config_dct.get('output_gcs_uri', None),
|
6509
6893
|
include_rai_reason=config_dct.get('include_rai_reason', None),
|
6510
6894
|
output_mime_type=config_dct.get('output_mime_type', None),
|
6511
6895
|
output_compression_quality=config_dct.get(
|
@@ -6535,6 +6919,7 @@ class Models(_api_module.BaseModule):
|
|
6535
6919
|
prompt: Optional[str] = None,
|
6536
6920
|
image: Optional[types.ImageOrDict] = None,
|
6537
6921
|
video: Optional[types.VideoOrDict] = None,
|
6922
|
+
source: Optional[types.GenerateVideosSourceOrDict] = None,
|
6538
6923
|
config: Optional[types.GenerateVideosConfigOrDict] = None,
|
6539
6924
|
) -> types.GenerateVideosOperation:
|
6540
6925
|
"""Generates videos based on an input (text, image, or video) and configuration.
|
@@ -6549,11 +6934,15 @@ class Models(_api_module.BaseModule):
|
|
6549
6934
|
Args:
|
6550
6935
|
model: The model to use.
|
6551
6936
|
prompt: The text prompt for generating the videos. Optional for image to
|
6552
|
-
video and video extension use cases.
|
6937
|
+
video and video extension use cases. This argument is deprecated, please
|
6938
|
+
use source instead.
|
6553
6939
|
image: The input image for generating the videos. Optional if prompt is
|
6554
|
-
provided.
|
6940
|
+
provided. This argument is deprecated, please use source instead.
|
6555
6941
|
video: The input video for video extension use cases. Optional if prompt
|
6556
|
-
or image is provided.
|
6942
|
+
or image is provided. This argument is deprecated, please use source
|
6943
|
+
instead.
|
6944
|
+
source: The input source for generating the videos (prompt, image, and/or
|
6945
|
+
video)
|
6557
6946
|
config: Configuration for generation.
|
6558
6947
|
|
6559
6948
|
Usage:
|
@@ -6561,7 +6950,9 @@ class Models(_api_module.BaseModule):
|
|
6561
6950
|
```
|
6562
6951
|
operation = client.models.generate_videos(
|
6563
6952
|
model="veo-2.0-generate-001",
|
6564
|
-
|
6953
|
+
source=types.GenerateVideosSource(
|
6954
|
+
prompt="A neon hologram of a cat driving at top speed",
|
6955
|
+
),
|
6565
6956
|
)
|
6566
6957
|
while not operation.done:
|
6567
6958
|
time.sleep(10)
|
@@ -6570,11 +6961,17 @@ class Models(_api_module.BaseModule):
|
|
6570
6961
|
operation.result.generated_videos[0].video.uri
|
6571
6962
|
```
|
6572
6963
|
"""
|
6964
|
+
if (prompt or image or video) and source:
|
6965
|
+
raise ValueError(
|
6966
|
+
'Source and prompt/image/video are mutually exclusive.'
|
6967
|
+
+ ' Please only use source.'
|
6968
|
+
)
|
6573
6969
|
return self._generate_videos(
|
6574
6970
|
model=model,
|
6575
6971
|
prompt=prompt,
|
6576
6972
|
image=image,
|
6577
6973
|
video=video,
|
6974
|
+
source=source,
|
6578
6975
|
config=config,
|
6579
6976
|
)
|
6580
6977
|
|
@@ -7240,6 +7637,92 @@ class AsyncModels(_api_module.BaseModule):
|
|
7240
7637
|
self._api_client._verify_response(return_value)
|
7241
7638
|
return return_value
|
7242
7639
|
|
7640
|
+
async def segment_image(
|
7641
|
+
self,
|
7642
|
+
*,
|
7643
|
+
model: str,
|
7644
|
+
source: types.SegmentImageSourceOrDict,
|
7645
|
+
config: Optional[types.SegmentImageConfigOrDict] = None,
|
7646
|
+
) -> types.SegmentImageResponse:
|
7647
|
+
"""Segments an image, creating a mask of a specified area.
|
7648
|
+
|
7649
|
+
Args:
|
7650
|
+
model (str): The model to use.
|
7651
|
+
source (SegmentImageSource): An object containing the source inputs
|
7652
|
+
(prompt, image, scribble_image) for image segmentation. The prompt is
|
7653
|
+
required for prompt mode and semantic mode, disallowed for other modes.
|
7654
|
+
scribble_image is required for the interactive mode, disallowed for
|
7655
|
+
other modes.
|
7656
|
+
config (SegmentImageConfig): Configuration for segmentation.
|
7657
|
+
|
7658
|
+
Usage:
|
7659
|
+
|
7660
|
+
```
|
7661
|
+
response = client.models.segment_image(
|
7662
|
+
model="image-segmentation-001",
|
7663
|
+
source=types.SegmentImageSource(
|
7664
|
+
image=types.Image.from_file(IMAGE_FILE_PATH),
|
7665
|
+
),
|
7666
|
+
config=types.SegmentImageConfig(
|
7667
|
+
mode=types.SegmentMode.foreground,
|
7668
|
+
),
|
7669
|
+
)
|
7670
|
+
|
7671
|
+
mask_image = response.generated_masks[0].mask
|
7672
|
+
```
|
7673
|
+
"""
|
7674
|
+
|
7675
|
+
parameter_model = types._SegmentImageParameters(
|
7676
|
+
model=model,
|
7677
|
+
source=source,
|
7678
|
+
config=config,
|
7679
|
+
)
|
7680
|
+
|
7681
|
+
request_url_dict: Optional[dict[str, str]]
|
7682
|
+
if not self._api_client.vertexai:
|
7683
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
7684
|
+
else:
|
7685
|
+
request_dict = _SegmentImageParameters_to_vertex(
|
7686
|
+
self._api_client, parameter_model
|
7687
|
+
)
|
7688
|
+
request_url_dict = request_dict.get('_url')
|
7689
|
+
if request_url_dict:
|
7690
|
+
path = '{model}:predict'.format_map(request_url_dict)
|
7691
|
+
else:
|
7692
|
+
path = '{model}:predict'
|
7693
|
+
|
7694
|
+
query_params = request_dict.get('_query')
|
7695
|
+
if query_params:
|
7696
|
+
path = f'{path}?{urlencode(query_params)}'
|
7697
|
+
# TODO: remove the hack that pops config.
|
7698
|
+
request_dict.pop('config', None)
|
7699
|
+
|
7700
|
+
http_options: Optional[types.HttpOptions] = None
|
7701
|
+
if (
|
7702
|
+
parameter_model.config is not None
|
7703
|
+
and parameter_model.config.http_options is not None
|
7704
|
+
):
|
7705
|
+
http_options = parameter_model.config.http_options
|
7706
|
+
|
7707
|
+
request_dict = _common.convert_to_dict(request_dict)
|
7708
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
7709
|
+
|
7710
|
+
response = await self._api_client.async_request(
|
7711
|
+
'post', path, request_dict, http_options
|
7712
|
+
)
|
7713
|
+
|
7714
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
7715
|
+
|
7716
|
+
if self._api_client.vertexai:
|
7717
|
+
response_dict = _SegmentImageResponse_from_vertex(response_dict)
|
7718
|
+
|
7719
|
+
return_value = types.SegmentImageResponse._from_response(
|
7720
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
7721
|
+
)
|
7722
|
+
|
7723
|
+
self._api_client._verify_response(return_value)
|
7724
|
+
return return_value
|
7725
|
+
|
7243
7726
|
async def get(
|
7244
7727
|
self, *, model: str, config: Optional[types.GetModelConfigOrDict] = None
|
7245
7728
|
) -> types.Model:
|
@@ -7495,7 +7978,9 @@ class AsyncModels(_api_module.BaseModule):
|
|
7495
7978
|
return_value = types.DeleteModelResponse._from_response(
|
7496
7979
|
response=response_dict, kwargs=parameter_model.model_dump()
|
7497
7980
|
)
|
7498
|
-
|
7981
|
+
return_value.sdk_http_response = types.HttpResponse(
|
7982
|
+
headers=response.headers
|
7983
|
+
)
|
7499
7984
|
self._api_client._verify_response(return_value)
|
7500
7985
|
return return_value
|
7501
7986
|
|
@@ -7679,6 +8164,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
7679
8164
|
prompt: Optional[str] = None,
|
7680
8165
|
image: Optional[types.ImageOrDict] = None,
|
7681
8166
|
video: Optional[types.VideoOrDict] = None,
|
8167
|
+
source: Optional[types.GenerateVideosSourceOrDict] = None,
|
7682
8168
|
config: Optional[types.GenerateVideosConfigOrDict] = None,
|
7683
8169
|
) -> types.GenerateVideosOperation:
|
7684
8170
|
"""Generates videos based on an input (text, image, or video) and configuration.
|
@@ -7720,6 +8206,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
7720
8206
|
prompt=prompt,
|
7721
8207
|
image=image,
|
7722
8208
|
video=video,
|
8209
|
+
source=source,
|
7723
8210
|
config=config,
|
7724
8211
|
)
|
7725
8212
|
|
@@ -8271,6 +8758,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
8271
8758
|
config_dct = dict(config)
|
8272
8759
|
api_config = types._UpscaleImageAPIConfigDict(
|
8273
8760
|
http_options=config_dct.get('http_options', None),
|
8761
|
+
output_gcs_uri=config_dct.get('output_gcs_uri', None),
|
8274
8762
|
include_rai_reason=config_dct.get('include_rai_reason', None),
|
8275
8763
|
output_mime_type=config_dct.get('output_mime_type', None),
|
8276
8764
|
output_compression_quality=config_dct.get(
|
@@ -8300,6 +8788,7 @@ class AsyncModels(_api_module.BaseModule):
|
|
8300
8788
|
prompt: Optional[str] = None,
|
8301
8789
|
image: Optional[types.ImageOrDict] = None,
|
8302
8790
|
video: Optional[types.VideoOrDict] = None,
|
8791
|
+
source: Optional[types.GenerateVideosSourceOrDict] = None,
|
8303
8792
|
config: Optional[types.GenerateVideosConfigOrDict] = None,
|
8304
8793
|
) -> types.GenerateVideosOperation:
|
8305
8794
|
"""Generates videos based on an input (text, image, or video) and configuration.
|
@@ -8314,11 +8803,15 @@ class AsyncModels(_api_module.BaseModule):
|
|
8314
8803
|
Args:
|
8315
8804
|
model: The model to use.
|
8316
8805
|
prompt: The text prompt for generating the videos. Optional for image to
|
8317
|
-
video and video extension use cases.
|
8806
|
+
video and video extension use cases. This argument is deprecated, please
|
8807
|
+
use source instead.
|
8318
8808
|
image: The input image for generating the videos. Optional if prompt is
|
8319
|
-
provided.
|
8809
|
+
provided. This argument is deprecated, please use source instead.
|
8320
8810
|
video: The input video for video extension use cases. Optional if prompt
|
8321
|
-
or image is provided.
|
8811
|
+
or image is provided. This argument is deprecated, please use source
|
8812
|
+
instead.
|
8813
|
+
source: The input source for generating the videos (prompt, image, and/or
|
8814
|
+
video)
|
8322
8815
|
config: Configuration for generation.
|
8323
8816
|
|
8324
8817
|
Usage:
|
@@ -8326,7 +8819,9 @@ class AsyncModels(_api_module.BaseModule):
|
|
8326
8819
|
```
|
8327
8820
|
operation = client.models.generate_videos(
|
8328
8821
|
model="veo-2.0-generate-001",
|
8329
|
-
|
8822
|
+
source=types.GenerateVideosSource(
|
8823
|
+
prompt="A neon hologram of a cat driving at top speed",
|
8824
|
+
),
|
8330
8825
|
)
|
8331
8826
|
while not operation.done:
|
8332
8827
|
time.sleep(10)
|
@@ -8335,10 +8830,16 @@ class AsyncModels(_api_module.BaseModule):
|
|
8335
8830
|
operation.result.generated_videos[0].video.uri
|
8336
8831
|
```
|
8337
8832
|
"""
|
8833
|
+
if (prompt or image or video) and source:
|
8834
|
+
raise ValueError(
|
8835
|
+
'Source and prompt/image/video are mutually exclusive.'
|
8836
|
+
+ ' Please only use source.'
|
8837
|
+
)
|
8338
8838
|
return await self._generate_videos(
|
8339
8839
|
model=model,
|
8340
8840
|
prompt=prompt,
|
8341
8841
|
image=image,
|
8342
8842
|
video=video,
|
8843
|
+
source=source,
|
8343
8844
|
config=config,
|
8344
8845
|
)
|