google-genai 1.28.0__py3-none-any.whl → 1.30.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 +144 -55
- google/genai/_automatic_function_calling_util.py +35 -7
- google/genai/_live_converters.py +64 -6
- google/genai/_tokens_converters.py +25 -3
- google/genai/_transformers.py +51 -0
- google/genai/batches.py +44 -5
- google/genai/caches.py +50 -6
- google/genai/chats.py +1 -0
- google/genai/errors.py +5 -2
- google/genai/live.py +92 -88
- google/genai/models.py +443 -36
- google/genai/tokens.py +1 -0
- google/genai/tunings.py +314 -43
- google/genai/types.py +1398 -293
- google/genai/version.py +1 -1
- {google_genai-1.28.0.dist-info → google_genai-1.30.0.dist-info}/METADATA +2 -2
- google_genai-1.30.0.dist-info/RECORD +35 -0
- google_genai-1.28.0.dist-info/RECORD +0 -35
- {google_genai-1.28.0.dist-info → google_genai-1.30.0.dist-info}/WHEEL +0 -0
- {google_genai-1.28.0.dist-info → google_genai-1.30.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.28.0.dist-info → google_genai-1.30.0.dist-info}/top_level.txt +0 -0
google/genai/models.py
CHANGED
@@ -340,6 +340,11 @@ def _GoogleSearch_to_mldev(
|
|
340
340
|
_Interval_to_mldev(getv(from_object, ['time_range_filter']), to_object),
|
341
341
|
)
|
342
342
|
|
343
|
+
if getv(from_object, ['exclude_domains']) is not None:
|
344
|
+
raise ValueError(
|
345
|
+
'exclude_domains parameter is not supported in Gemini API.'
|
346
|
+
)
|
347
|
+
|
343
348
|
return to_object
|
344
349
|
|
345
350
|
|
@@ -387,6 +392,17 @@ def _UrlContext_to_mldev(
|
|
387
392
|
return to_object
|
388
393
|
|
389
394
|
|
395
|
+
def _ToolComputerUse_to_mldev(
|
396
|
+
from_object: Union[dict[str, Any], object],
|
397
|
+
parent_object: Optional[dict[str, Any]] = None,
|
398
|
+
) -> dict[str, Any]:
|
399
|
+
to_object: dict[str, Any] = {}
|
400
|
+
if getv(from_object, ['environment']) is not None:
|
401
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
402
|
+
|
403
|
+
return to_object
|
404
|
+
|
405
|
+
|
390
406
|
def _Tool_to_mldev(
|
391
407
|
from_object: Union[dict[str, Any], object],
|
392
408
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -436,12 +452,18 @@ def _Tool_to_mldev(
|
|
436
452
|
_UrlContext_to_mldev(getv(from_object, ['url_context']), to_object),
|
437
453
|
)
|
438
454
|
|
455
|
+
if getv(from_object, ['computer_use']) is not None:
|
456
|
+
setv(
|
457
|
+
to_object,
|
458
|
+
['computerUse'],
|
459
|
+
_ToolComputerUse_to_mldev(
|
460
|
+
getv(from_object, ['computer_use']), to_object
|
461
|
+
),
|
462
|
+
)
|
463
|
+
|
439
464
|
if getv(from_object, ['code_execution']) is not None:
|
440
465
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
441
466
|
|
442
|
-
if getv(from_object, ['computer_use']) is not None:
|
443
|
-
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
444
|
-
|
445
467
|
return to_object
|
446
468
|
|
447
469
|
|
@@ -997,7 +1019,11 @@ def _GenerateImagesConfig_to_mldev(
|
|
997
1019
|
raise ValueError('add_watermark parameter is not supported in Gemini API.')
|
998
1020
|
|
999
1021
|
if getv(from_object, ['image_size']) is not None:
|
1000
|
-
|
1022
|
+
setv(
|
1023
|
+
parent_object,
|
1024
|
+
['parameters', 'sampleImageSize'],
|
1025
|
+
getv(from_object, ['image_size']),
|
1026
|
+
)
|
1001
1027
|
|
1002
1028
|
if getv(from_object, ['enhance_prompt']) is not None:
|
1003
1029
|
raise ValueError('enhance_prompt parameter is not supported in Gemini API.')
|
@@ -1242,15 +1268,6 @@ def _Image_to_mldev(
|
|
1242
1268
|
return to_object
|
1243
1269
|
|
1244
1270
|
|
1245
|
-
def _GenerateVideosSource_to_mldev(
|
1246
|
-
from_object: Union[dict[str, Any], object],
|
1247
|
-
parent_object: Optional[dict[str, Any]] = None,
|
1248
|
-
) -> dict[str, Any]:
|
1249
|
-
to_object: dict[str, Any] = {}
|
1250
|
-
|
1251
|
-
return to_object
|
1252
|
-
|
1253
|
-
|
1254
1271
|
def _GenerateVideosConfig_to_mldev(
|
1255
1272
|
from_object: Union[dict[str, Any], object],
|
1256
1273
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1690,6 +1707,9 @@ def _GoogleSearch_to_vertex(
|
|
1690
1707
|
),
|
1691
1708
|
)
|
1692
1709
|
|
1710
|
+
if getv(from_object, ['exclude_domains']) is not None:
|
1711
|
+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
|
1712
|
+
|
1693
1713
|
return to_object
|
1694
1714
|
|
1695
1715
|
|
@@ -1733,6 +1753,8 @@ def _EnterpriseWebSearch_to_vertex(
|
|
1733
1753
|
parent_object: Optional[dict[str, Any]] = None,
|
1734
1754
|
) -> dict[str, Any]:
|
1735
1755
|
to_object: dict[str, Any] = {}
|
1756
|
+
if getv(from_object, ['exclude_domains']) is not None:
|
1757
|
+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
|
1736
1758
|
|
1737
1759
|
return to_object
|
1738
1760
|
|
@@ -1812,6 +1834,17 @@ def _UrlContext_to_vertex(
|
|
1812
1834
|
return to_object
|
1813
1835
|
|
1814
1836
|
|
1837
|
+
def _ToolComputerUse_to_vertex(
|
1838
|
+
from_object: Union[dict[str, Any], object],
|
1839
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1840
|
+
) -> dict[str, Any]:
|
1841
|
+
to_object: dict[str, Any] = {}
|
1842
|
+
if getv(from_object, ['environment']) is not None:
|
1843
|
+
setv(to_object, ['environment'], getv(from_object, ['environment']))
|
1844
|
+
|
1845
|
+
return to_object
|
1846
|
+
|
1847
|
+
|
1815
1848
|
def _Tool_to_vertex(
|
1816
1849
|
from_object: Union[dict[str, Any], object],
|
1817
1850
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1871,12 +1904,18 @@ def _Tool_to_vertex(
|
|
1871
1904
|
_UrlContext_to_vertex(getv(from_object, ['url_context']), to_object),
|
1872
1905
|
)
|
1873
1906
|
|
1907
|
+
if getv(from_object, ['computer_use']) is not None:
|
1908
|
+
setv(
|
1909
|
+
to_object,
|
1910
|
+
['computerUse'],
|
1911
|
+
_ToolComputerUse_to_vertex(
|
1912
|
+
getv(from_object, ['computer_use']), to_object
|
1913
|
+
),
|
1914
|
+
)
|
1915
|
+
|
1874
1916
|
if getv(from_object, ['code_execution']) is not None:
|
1875
1917
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
1876
1918
|
|
1877
|
-
if getv(from_object, ['computer_use']) is not None:
|
1878
|
-
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
1879
|
-
|
1880
1919
|
return to_object
|
1881
1920
|
|
1882
1921
|
|
@@ -2839,6 +2878,153 @@ def _UpscaleImageAPIParameters_to_vertex(
|
|
2839
2878
|
return to_object
|
2840
2879
|
|
2841
2880
|
|
2881
|
+
def _ProductImage_to_vertex(
|
2882
|
+
from_object: Union[dict[str, Any], object],
|
2883
|
+
parent_object: Optional[dict[str, Any]] = None,
|
2884
|
+
) -> dict[str, Any]:
|
2885
|
+
to_object: dict[str, Any] = {}
|
2886
|
+
if getv(from_object, ['product_image']) is not None:
|
2887
|
+
setv(
|
2888
|
+
to_object,
|
2889
|
+
['image'],
|
2890
|
+
_Image_to_vertex(getv(from_object, ['product_image']), to_object),
|
2891
|
+
)
|
2892
|
+
|
2893
|
+
return to_object
|
2894
|
+
|
2895
|
+
|
2896
|
+
def _RecontextImageSource_to_vertex(
|
2897
|
+
from_object: Union[dict[str, Any], object],
|
2898
|
+
parent_object: Optional[dict[str, Any]] = None,
|
2899
|
+
) -> dict[str, Any]:
|
2900
|
+
to_object: dict[str, Any] = {}
|
2901
|
+
if getv(from_object, ['prompt']) is not None:
|
2902
|
+
setv(
|
2903
|
+
parent_object, ['instances[0]', 'prompt'], getv(from_object, ['prompt'])
|
2904
|
+
)
|
2905
|
+
|
2906
|
+
if getv(from_object, ['person_image']) is not None:
|
2907
|
+
setv(
|
2908
|
+
parent_object,
|
2909
|
+
['instances[0]', 'personImage', 'image'],
|
2910
|
+
_Image_to_vertex(getv(from_object, ['person_image']), to_object),
|
2911
|
+
)
|
2912
|
+
|
2913
|
+
if getv(from_object, ['product_images']) is not None:
|
2914
|
+
setv(
|
2915
|
+
parent_object,
|
2916
|
+
['instances[0]', 'productImages'],
|
2917
|
+
[
|
2918
|
+
_ProductImage_to_vertex(item, to_object)
|
2919
|
+
for item in getv(from_object, ['product_images'])
|
2920
|
+
],
|
2921
|
+
)
|
2922
|
+
|
2923
|
+
return to_object
|
2924
|
+
|
2925
|
+
|
2926
|
+
def _RecontextImageConfig_to_vertex(
|
2927
|
+
from_object: Union[dict[str, Any], object],
|
2928
|
+
parent_object: Optional[dict[str, Any]] = None,
|
2929
|
+
) -> dict[str, Any]:
|
2930
|
+
to_object: dict[str, Any] = {}
|
2931
|
+
|
2932
|
+
if getv(from_object, ['number_of_images']) is not None:
|
2933
|
+
setv(
|
2934
|
+
parent_object,
|
2935
|
+
['parameters', 'sampleCount'],
|
2936
|
+
getv(from_object, ['number_of_images']),
|
2937
|
+
)
|
2938
|
+
|
2939
|
+
if getv(from_object, ['base_steps']) is not None:
|
2940
|
+
setv(
|
2941
|
+
parent_object,
|
2942
|
+
['parameters', 'editConfig', 'baseSteps'],
|
2943
|
+
getv(from_object, ['base_steps']),
|
2944
|
+
)
|
2945
|
+
|
2946
|
+
if getv(from_object, ['output_gcs_uri']) is not None:
|
2947
|
+
setv(
|
2948
|
+
parent_object,
|
2949
|
+
['parameters', 'storageUri'],
|
2950
|
+
getv(from_object, ['output_gcs_uri']),
|
2951
|
+
)
|
2952
|
+
|
2953
|
+
if getv(from_object, ['seed']) is not None:
|
2954
|
+
setv(parent_object, ['parameters', 'seed'], getv(from_object, ['seed']))
|
2955
|
+
|
2956
|
+
if getv(from_object, ['safety_filter_level']) is not None:
|
2957
|
+
setv(
|
2958
|
+
parent_object,
|
2959
|
+
['parameters', 'safetySetting'],
|
2960
|
+
getv(from_object, ['safety_filter_level']),
|
2961
|
+
)
|
2962
|
+
|
2963
|
+
if getv(from_object, ['person_generation']) is not None:
|
2964
|
+
setv(
|
2965
|
+
parent_object,
|
2966
|
+
['parameters', 'personGeneration'],
|
2967
|
+
getv(from_object, ['person_generation']),
|
2968
|
+
)
|
2969
|
+
|
2970
|
+
if getv(from_object, ['output_mime_type']) is not None:
|
2971
|
+
setv(
|
2972
|
+
parent_object,
|
2973
|
+
['parameters', 'outputOptions', 'mimeType'],
|
2974
|
+
getv(from_object, ['output_mime_type']),
|
2975
|
+
)
|
2976
|
+
|
2977
|
+
if getv(from_object, ['output_compression_quality']) is not None:
|
2978
|
+
setv(
|
2979
|
+
parent_object,
|
2980
|
+
['parameters', 'outputOptions', 'compressionQuality'],
|
2981
|
+
getv(from_object, ['output_compression_quality']),
|
2982
|
+
)
|
2983
|
+
|
2984
|
+
if getv(from_object, ['enhance_prompt']) is not None:
|
2985
|
+
setv(
|
2986
|
+
parent_object,
|
2987
|
+
['parameters', 'enhancePrompt'],
|
2988
|
+
getv(from_object, ['enhance_prompt']),
|
2989
|
+
)
|
2990
|
+
|
2991
|
+
return to_object
|
2992
|
+
|
2993
|
+
|
2994
|
+
def _RecontextImageParameters_to_vertex(
|
2995
|
+
api_client: BaseApiClient,
|
2996
|
+
from_object: Union[dict[str, Any], object],
|
2997
|
+
parent_object: Optional[dict[str, Any]] = None,
|
2998
|
+
) -> dict[str, Any]:
|
2999
|
+
to_object: dict[str, Any] = {}
|
3000
|
+
if getv(from_object, ['model']) is not None:
|
3001
|
+
setv(
|
3002
|
+
to_object,
|
3003
|
+
['_url', 'model'],
|
3004
|
+
t.t_model(api_client, getv(from_object, ['model'])),
|
3005
|
+
)
|
3006
|
+
|
3007
|
+
if getv(from_object, ['source']) is not None:
|
3008
|
+
setv(
|
3009
|
+
to_object,
|
3010
|
+
['config'],
|
3011
|
+
_RecontextImageSource_to_vertex(
|
3012
|
+
getv(from_object, ['source']), to_object
|
3013
|
+
),
|
3014
|
+
)
|
3015
|
+
|
3016
|
+
if getv(from_object, ['config']) is not None:
|
3017
|
+
setv(
|
3018
|
+
to_object,
|
3019
|
+
['config'],
|
3020
|
+
_RecontextImageConfig_to_vertex(
|
3021
|
+
getv(from_object, ['config']), to_object
|
3022
|
+
),
|
3023
|
+
)
|
3024
|
+
|
3025
|
+
return to_object
|
3026
|
+
|
3027
|
+
|
2842
3028
|
def _GetModelParameters_to_vertex(
|
2843
3029
|
api_client: BaseApiClient,
|
2844
3030
|
from_object: Union[dict[str, Any], object],
|
@@ -3090,15 +3276,6 @@ def _Video_to_vertex(
|
|
3090
3276
|
return to_object
|
3091
3277
|
|
3092
3278
|
|
3093
|
-
def _GenerateVideosSource_to_vertex(
|
3094
|
-
from_object: Union[dict[str, Any], object],
|
3095
|
-
parent_object: Optional[dict[str, Any]] = None,
|
3096
|
-
) -> dict[str, Any]:
|
3097
|
-
to_object: dict[str, Any] = {}
|
3098
|
-
|
3099
|
-
return to_object
|
3100
|
-
|
3101
|
-
|
3102
3279
|
def _GenerateVideosConfig_to_vertex(
|
3103
3280
|
from_object: Union[dict[str, Any], object],
|
3104
3281
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -3518,6 +3695,9 @@ def _GenerateContentResponse_from_mldev(
|
|
3518
3695
|
if getv(from_object, ['promptFeedback']) is not None:
|
3519
3696
|
setv(to_object, ['prompt_feedback'], getv(from_object, ['promptFeedback']))
|
3520
3697
|
|
3698
|
+
if getv(from_object, ['responseId']) is not None:
|
3699
|
+
setv(to_object, ['response_id'], getv(from_object, ['responseId']))
|
3700
|
+
|
3521
3701
|
if getv(from_object, ['usageMetadata']) is not None:
|
3522
3702
|
setv(to_object, ['usage_metadata'], getv(from_object, ['usageMetadata']))
|
3523
3703
|
|
@@ -4170,15 +4350,15 @@ def _GenerateContentResponse_from_vertex(
|
|
4170
4350
|
if getv(from_object, ['createTime']) is not None:
|
4171
4351
|
setv(to_object, ['create_time'], getv(from_object, ['createTime']))
|
4172
4352
|
|
4173
|
-
if getv(from_object, ['responseId']) is not None:
|
4174
|
-
setv(to_object, ['response_id'], getv(from_object, ['responseId']))
|
4175
|
-
|
4176
4353
|
if getv(from_object, ['modelVersion']) is not None:
|
4177
4354
|
setv(to_object, ['model_version'], getv(from_object, ['modelVersion']))
|
4178
4355
|
|
4179
4356
|
if getv(from_object, ['promptFeedback']) is not None:
|
4180
4357
|
setv(to_object, ['prompt_feedback'], getv(from_object, ['promptFeedback']))
|
4181
4358
|
|
4359
|
+
if getv(from_object, ['responseId']) is not None:
|
4360
|
+
setv(to_object, ['response_id'], getv(from_object, ['responseId']))
|
4361
|
+
|
4182
4362
|
if getv(from_object, ['usageMetadata']) is not None:
|
4183
4363
|
setv(to_object, ['usage_metadata'], getv(from_object, ['usageMetadata']))
|
4184
4364
|
|
@@ -4420,6 +4600,24 @@ def _UpscaleImageResponse_from_vertex(
|
|
4420
4600
|
return to_object
|
4421
4601
|
|
4422
4602
|
|
4603
|
+
def _RecontextImageResponse_from_vertex(
|
4604
|
+
from_object: Union[dict[str, Any], object],
|
4605
|
+
parent_object: Optional[dict[str, Any]] = None,
|
4606
|
+
) -> dict[str, Any]:
|
4607
|
+
to_object: dict[str, Any] = {}
|
4608
|
+
if getv(from_object, ['predictions']) is not None:
|
4609
|
+
setv(
|
4610
|
+
to_object,
|
4611
|
+
['generated_images'],
|
4612
|
+
[
|
4613
|
+
_GeneratedImage_from_vertex(item, to_object)
|
4614
|
+
for item in getv(from_object, ['predictions'])
|
4615
|
+
],
|
4616
|
+
)
|
4617
|
+
|
4618
|
+
return to_object
|
4619
|
+
|
4620
|
+
|
4423
4621
|
def _Endpoint_from_vertex(
|
4424
4622
|
from_object: Union[dict[str, Any], object],
|
4425
4623
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -5207,6 +5405,112 @@ class Models(_api_module.BaseModule):
|
|
5207
5405
|
self._api_client._verify_response(return_value)
|
5208
5406
|
return return_value
|
5209
5407
|
|
5408
|
+
def recontext_image(
|
5409
|
+
self,
|
5410
|
+
*,
|
5411
|
+
model: str,
|
5412
|
+
source: types.RecontextImageSourceOrDict,
|
5413
|
+
config: Optional[types.RecontextImageConfigOrDict] = None,
|
5414
|
+
) -> types.RecontextImageResponse:
|
5415
|
+
"""Recontextualizes an image.
|
5416
|
+
|
5417
|
+
There are two types of recontextualization currently supported:
|
5418
|
+
1) Imagen Product Recontext - Generate images of products in new scenes
|
5419
|
+
and contexts.
|
5420
|
+
2) Virtual Try-On: Generate images of persons modeling fashion products.
|
5421
|
+
|
5422
|
+
Args:
|
5423
|
+
model (str): The model to use.
|
5424
|
+
source (RecontextImageSource): An object containing the source inputs
|
5425
|
+
(prompt, person_image, product_images) for image recontext. prompt is
|
5426
|
+
optional for product recontext and disallowed for virtual try-on.
|
5427
|
+
person_image is required for virtual try-on, disallowed for product
|
5428
|
+
recontext. product_images is required for both product recontext and
|
5429
|
+
virtual try-on. Only one product image is supported for virtual try-on,
|
5430
|
+
and up to 3 product images (different angles of the same product) are
|
5431
|
+
supported for product recontext.
|
5432
|
+
config (RecontextImageConfig): Configuration for recontextualization.
|
5433
|
+
|
5434
|
+
Usage:
|
5435
|
+
|
5436
|
+
```
|
5437
|
+
product_recontext_response = client.models.recontext_image(
|
5438
|
+
model="imagen-product-recontext-preview-06-30",
|
5439
|
+
source=types.RecontextImageSource(
|
5440
|
+
prompt="In a modern kitchen setting.",
|
5441
|
+
product_images=[types.ProductImage.from_file(IMAGE_FILE_PATH)],
|
5442
|
+
),
|
5443
|
+
config=types.RecontextImageConfig(
|
5444
|
+
number_of_images=1,
|
5445
|
+
),
|
5446
|
+
)
|
5447
|
+
image = product_recontext_response.generated_images[0].image
|
5448
|
+
|
5449
|
+
virtual_try_on_response = client.models.recontext_image(
|
5450
|
+
model="virtual-try-on-preview-08-04",
|
5451
|
+
source=types.RecontextImageSource(
|
5452
|
+
person_image=types.Image.from_file(IMAGE1_FILE_PATH),
|
5453
|
+
product_images=[types.ProductImage.from_file(IMAGE2_FILE_PATH)],
|
5454
|
+
),
|
5455
|
+
config=types.RecontextImageConfig(
|
5456
|
+
number_of_images=1,
|
5457
|
+
),
|
5458
|
+
)
|
5459
|
+
image = virtual_try_on_response.generated_images[0].image
|
5460
|
+
```
|
5461
|
+
"""
|
5462
|
+
|
5463
|
+
parameter_model = types._RecontextImageParameters(
|
5464
|
+
model=model,
|
5465
|
+
source=source,
|
5466
|
+
config=config,
|
5467
|
+
)
|
5468
|
+
|
5469
|
+
request_url_dict: Optional[dict[str, str]]
|
5470
|
+
if not self._api_client.vertexai:
|
5471
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
5472
|
+
else:
|
5473
|
+
request_dict = _RecontextImageParameters_to_vertex(
|
5474
|
+
self._api_client, parameter_model
|
5475
|
+
)
|
5476
|
+
request_url_dict = request_dict.get('_url')
|
5477
|
+
if request_url_dict:
|
5478
|
+
path = '{model}:predict'.format_map(request_url_dict)
|
5479
|
+
else:
|
5480
|
+
path = '{model}:predict'
|
5481
|
+
|
5482
|
+
query_params = request_dict.get('_query')
|
5483
|
+
if query_params:
|
5484
|
+
path = f'{path}?{urlencode(query_params)}'
|
5485
|
+
# TODO: remove the hack that pops config.
|
5486
|
+
request_dict.pop('config', None)
|
5487
|
+
|
5488
|
+
http_options: Optional[types.HttpOptions] = None
|
5489
|
+
if (
|
5490
|
+
parameter_model.config is not None
|
5491
|
+
and parameter_model.config.http_options is not None
|
5492
|
+
):
|
5493
|
+
http_options = parameter_model.config.http_options
|
5494
|
+
|
5495
|
+
request_dict = _common.convert_to_dict(request_dict)
|
5496
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
5497
|
+
|
5498
|
+
response = self._api_client.request(
|
5499
|
+
'post', path, request_dict, http_options
|
5500
|
+
)
|
5501
|
+
|
5502
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
5503
|
+
|
5504
|
+
if self._api_client.vertexai:
|
5505
|
+
response_dict = _RecontextImageResponse_from_vertex(response_dict)
|
5506
|
+
|
5507
|
+
return_value = types.RecontextImageResponse._from_response(
|
5508
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
5509
|
+
)
|
5510
|
+
|
5511
|
+
self._api_client._verify_response(return_value)
|
5512
|
+
return return_value
|
5513
|
+
|
5210
5514
|
def get(
|
5211
5515
|
self, *, model: str, config: Optional[types.GetModelConfigOrDict] = None
|
5212
5516
|
) -> types.Model:
|
@@ -5746,7 +6050,7 @@ class Models(_api_module.BaseModule):
|
|
5746
6050
|
self,
|
5747
6051
|
*,
|
5748
6052
|
model: str,
|
5749
|
-
contents:
|
6053
|
+
contents: types.ContentListUnionDict,
|
5750
6054
|
config: Optional[types.GenerateContentConfigOrDict] = None,
|
5751
6055
|
) -> types.GenerateContentResponse:
|
5752
6056
|
"""Makes an API request to generate content using a model.
|
@@ -5757,9 +6061,8 @@ class Models(_api_module.BaseModule):
|
|
5757
6061
|
'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-2.0-flash'
|
5758
6062
|
- The partial resource name with 'publishers/', for example:
|
5759
6063
|
'publishers/google/models/gemini-2.0-flash' or
|
5760
|
-
'publishers/meta/models/llama-3.1-405b-instruct-maas'
|
5761
6064
|
- `/` separated publisher and model name, for example:
|
5762
|
-
'google/gemini-2.0-flash'
|
6065
|
+
'google/gemini-2.0-flash'
|
5763
6066
|
|
5764
6067
|
For the `model` parameter, supported formats for Gemini API include:
|
5765
6068
|
- The Gemini model ID, for example: 'gemini-2.0-flash'
|
@@ -5882,7 +6185,7 @@ class Models(_api_module.BaseModule):
|
|
5882
6185
|
self,
|
5883
6186
|
*,
|
5884
6187
|
model: str,
|
5885
|
-
contents:
|
6188
|
+
contents: types.ContentListUnionDict,
|
5886
6189
|
config: Optional[types.GenerateContentConfigOrDict] = None,
|
5887
6190
|
) -> Iterator[types.GenerateContentResponse]:
|
5888
6191
|
"""Makes an API request to generate content using a model and yields the model's response in chunks.
|
@@ -5893,9 +6196,8 @@ class Models(_api_module.BaseModule):
|
|
5893
6196
|
'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-2.0-flash'
|
5894
6197
|
- The partial resource name with 'publishers/', for example:
|
5895
6198
|
'publishers/google/models/gemini-2.0-flash' or
|
5896
|
-
'publishers/meta/models/llama-3.1-405b-instruct-maas'
|
5897
6199
|
- `/` separated publisher and model name, for example:
|
5898
|
-
'google/gemini-2.0-flash'
|
6200
|
+
'google/gemini-2.0-flash'
|
5899
6201
|
|
5900
6202
|
For the `model` parameter, supported formats for Gemini API include:
|
5901
6203
|
- The Gemini model ID, for example: 'gemini-2.0-flash'
|
@@ -6832,6 +7134,112 @@ class AsyncModels(_api_module.BaseModule):
|
|
6832
7134
|
self._api_client._verify_response(return_value)
|
6833
7135
|
return return_value
|
6834
7136
|
|
7137
|
+
async def recontext_image(
|
7138
|
+
self,
|
7139
|
+
*,
|
7140
|
+
model: str,
|
7141
|
+
source: types.RecontextImageSourceOrDict,
|
7142
|
+
config: Optional[types.RecontextImageConfigOrDict] = None,
|
7143
|
+
) -> types.RecontextImageResponse:
|
7144
|
+
"""Recontextualizes an image.
|
7145
|
+
|
7146
|
+
There are two types of recontextualization currently supported:
|
7147
|
+
1) Imagen Product Recontext - Generate images of products in new scenes
|
7148
|
+
and contexts.
|
7149
|
+
2) Virtual Try-On: Generate images of persons modeling fashion products.
|
7150
|
+
|
7151
|
+
Args:
|
7152
|
+
model (str): The model to use.
|
7153
|
+
source (RecontextImageSource): An object containing the source inputs
|
7154
|
+
(prompt, person_image, product_images) for image recontext. prompt is
|
7155
|
+
optional for product recontext and disallowed for virtual try-on.
|
7156
|
+
person_image is required for virtual try-on, disallowed for product
|
7157
|
+
recontext. product_images is required for both product recontext and
|
7158
|
+
virtual try-on. Only one product image is supported for virtual try-on,
|
7159
|
+
and up to 3 product images (different angles of the same product) are
|
7160
|
+
supported for product recontext.
|
7161
|
+
config (RecontextImageConfig): Configuration for recontextualization.
|
7162
|
+
|
7163
|
+
Usage:
|
7164
|
+
|
7165
|
+
```
|
7166
|
+
product_recontext_response = client.models.recontext_image(
|
7167
|
+
model="imagen-product-recontext-preview-06-30",
|
7168
|
+
source=types.RecontextImageSource(
|
7169
|
+
prompt="In a modern kitchen setting.",
|
7170
|
+
product_images=[types.ProductImage.from_file(IMAGE_FILE_PATH)],
|
7171
|
+
),
|
7172
|
+
config=types.RecontextImageConfig(
|
7173
|
+
number_of_images=1,
|
7174
|
+
),
|
7175
|
+
)
|
7176
|
+
image = product_recontext_response.generated_images[0].image
|
7177
|
+
|
7178
|
+
virtual_try_on_response = client.models.recontext_image(
|
7179
|
+
model="virtual-try-on-preview-08-04",
|
7180
|
+
source=types.RecontextImageSource(
|
7181
|
+
person_image=types.Image.from_file(IMAGE1_FILE_PATH),
|
7182
|
+
product_images=[types.ProductImage.from_file(IMAGE2_FILE_PATH)],
|
7183
|
+
),
|
7184
|
+
config=types.RecontextImageConfig(
|
7185
|
+
number_of_images=1,
|
7186
|
+
),
|
7187
|
+
)
|
7188
|
+
image = virtual_try_on_response.generated_images[0].image
|
7189
|
+
```
|
7190
|
+
"""
|
7191
|
+
|
7192
|
+
parameter_model = types._RecontextImageParameters(
|
7193
|
+
model=model,
|
7194
|
+
source=source,
|
7195
|
+
config=config,
|
7196
|
+
)
|
7197
|
+
|
7198
|
+
request_url_dict: Optional[dict[str, str]]
|
7199
|
+
if not self._api_client.vertexai:
|
7200
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
7201
|
+
else:
|
7202
|
+
request_dict = _RecontextImageParameters_to_vertex(
|
7203
|
+
self._api_client, parameter_model
|
7204
|
+
)
|
7205
|
+
request_url_dict = request_dict.get('_url')
|
7206
|
+
if request_url_dict:
|
7207
|
+
path = '{model}:predict'.format_map(request_url_dict)
|
7208
|
+
else:
|
7209
|
+
path = '{model}:predict'
|
7210
|
+
|
7211
|
+
query_params = request_dict.get('_query')
|
7212
|
+
if query_params:
|
7213
|
+
path = f'{path}?{urlencode(query_params)}'
|
7214
|
+
# TODO: remove the hack that pops config.
|
7215
|
+
request_dict.pop('config', None)
|
7216
|
+
|
7217
|
+
http_options: Optional[types.HttpOptions] = None
|
7218
|
+
if (
|
7219
|
+
parameter_model.config is not None
|
7220
|
+
and parameter_model.config.http_options is not None
|
7221
|
+
):
|
7222
|
+
http_options = parameter_model.config.http_options
|
7223
|
+
|
7224
|
+
request_dict = _common.convert_to_dict(request_dict)
|
7225
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
7226
|
+
|
7227
|
+
response = await self._api_client.async_request(
|
7228
|
+
'post', path, request_dict, http_options
|
7229
|
+
)
|
7230
|
+
|
7231
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
7232
|
+
|
7233
|
+
if self._api_client.vertexai:
|
7234
|
+
response_dict = _RecontextImageResponse_from_vertex(response_dict)
|
7235
|
+
|
7236
|
+
return_value = types.RecontextImageResponse._from_response(
|
7237
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
7238
|
+
)
|
7239
|
+
|
7240
|
+
self._api_client._verify_response(return_value)
|
7241
|
+
return return_value
|
7242
|
+
|
6835
7243
|
async def get(
|
6836
7244
|
self, *, model: str, config: Optional[types.GetModelConfigOrDict] = None
|
6837
7245
|
) -> types.Model:
|
@@ -7490,9 +7898,8 @@ class AsyncModels(_api_module.BaseModule):
|
|
7490
7898
|
'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-2.0-flash'
|
7491
7899
|
- The partial resource name with 'publishers/', for example:
|
7492
7900
|
'publishers/google/models/gemini-2.0-flash' or
|
7493
|
-
'publishers/meta/models/llama-3.1-405b-instruct-maas'
|
7494
7901
|
- `/` separated publisher and model name, for example:
|
7495
|
-
'google/gemini-2.0-flash'
|
7902
|
+
'google/gemini-2.0-flash'
|
7496
7903
|
|
7497
7904
|
For the `model` parameter, supported formats for Gemini API include:
|
7498
7905
|
- The Gemini model ID, for example: 'gemini-2.0-flash'
|