google-genai 1.3.0__py3-none-any.whl → 1.5.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 +143 -69
- google/genai/_api_module.py +1 -1
- google/genai/_automatic_function_calling_util.py +15 -15
- google/genai/_common.py +6 -3
- google/genai/_extra_utils.py +62 -46
- google/genai/_replay_api_client.py +73 -4
- google/genai/_test_api_client.py +8 -8
- google/genai/_transformers.py +194 -66
- google/genai/batches.py +180 -134
- google/genai/caches.py +316 -216
- google/genai/chats.py +179 -35
- google/genai/client.py +3 -3
- google/genai/errors.py +1 -2
- google/genai/files.py +175 -119
- google/genai/live.py +73 -64
- google/genai/models.py +898 -637
- google/genai/operations.py +96 -66
- google/genai/pagers.py +16 -7
- google/genai/tunings.py +172 -112
- google/genai/types.py +228 -178
- google/genai/version.py +1 -1
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/METADATA +8 -1
- google_genai-1.5.0.dist-info/RECORD +27 -0
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/WHEEL +1 -1
- google_genai-1.3.0.dist-info/RECORD +0 -27
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/LICENSE +0 -0
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/top_level.txt +0 -0
google/genai/files.py
CHANGED
@@ -26,7 +26,7 @@ from . import _api_module
|
|
26
26
|
from . import _common
|
27
27
|
from . import _transformers as t
|
28
28
|
from . import types
|
29
|
-
from ._api_client import
|
29
|
+
from ._api_client import BaseApiClient
|
30
30
|
from ._common import get_value_by_path as getv
|
31
31
|
from ._common import set_value_by_path as setv
|
32
32
|
from .pagers import AsyncPager, Pager
|
@@ -35,11 +35,11 @@ logger = logging.getLogger('google_genai.files')
|
|
35
35
|
|
36
36
|
|
37
37
|
def _ListFilesConfig_to_mldev(
|
38
|
-
api_client:
|
38
|
+
api_client: BaseApiClient,
|
39
39
|
from_object: Union[dict, object],
|
40
|
-
parent_object: dict = None,
|
40
|
+
parent_object: Optional[dict] = None,
|
41
41
|
) -> dict:
|
42
|
-
to_object = {}
|
42
|
+
to_object: dict[str, Any] = {}
|
43
43
|
|
44
44
|
if getv(from_object, ['page_size']) is not None:
|
45
45
|
setv(
|
@@ -57,11 +57,11 @@ def _ListFilesConfig_to_mldev(
|
|
57
57
|
|
58
58
|
|
59
59
|
def _ListFilesConfig_to_vertex(
|
60
|
-
api_client:
|
60
|
+
api_client: BaseApiClient,
|
61
61
|
from_object: Union[dict, object],
|
62
|
-
parent_object: dict = None,
|
62
|
+
parent_object: Optional[dict] = None,
|
63
63
|
) -> dict:
|
64
|
-
to_object = {}
|
64
|
+
to_object: dict[str, Any] = {}
|
65
65
|
|
66
66
|
if getv(from_object, ['page_size']) is not None:
|
67
67
|
setv(
|
@@ -79,11 +79,11 @@ def _ListFilesConfig_to_vertex(
|
|
79
79
|
|
80
80
|
|
81
81
|
def _ListFilesParameters_to_mldev(
|
82
|
-
api_client:
|
82
|
+
api_client: BaseApiClient,
|
83
83
|
from_object: Union[dict, object],
|
84
|
-
parent_object: dict = None,
|
84
|
+
parent_object: Optional[dict] = None,
|
85
85
|
) -> dict:
|
86
|
-
to_object = {}
|
86
|
+
to_object: dict[str, Any] = {}
|
87
87
|
if getv(from_object, ['config']) is not None:
|
88
88
|
setv(
|
89
89
|
to_object,
|
@@ -97,11 +97,11 @@ def _ListFilesParameters_to_mldev(
|
|
97
97
|
|
98
98
|
|
99
99
|
def _ListFilesParameters_to_vertex(
|
100
|
-
api_client:
|
100
|
+
api_client: BaseApiClient,
|
101
101
|
from_object: Union[dict, object],
|
102
|
-
parent_object: dict = None,
|
102
|
+
parent_object: Optional[dict] = None,
|
103
103
|
) -> dict:
|
104
|
-
to_object = {}
|
104
|
+
to_object: dict[str, Any] = {}
|
105
105
|
if getv(from_object, ['config']) is not None:
|
106
106
|
raise ValueError('config parameter is not supported in Vertex AI.')
|
107
107
|
|
@@ -109,11 +109,11 @@ def _ListFilesParameters_to_vertex(
|
|
109
109
|
|
110
110
|
|
111
111
|
def _FileStatus_to_mldev(
|
112
|
-
api_client:
|
112
|
+
api_client: BaseApiClient,
|
113
113
|
from_object: Union[dict, object],
|
114
|
-
parent_object: dict = None,
|
114
|
+
parent_object: Optional[dict] = None,
|
115
115
|
) -> dict:
|
116
|
-
to_object = {}
|
116
|
+
to_object: dict[str, Any] = {}
|
117
117
|
if getv(from_object, ['details']) is not None:
|
118
118
|
setv(to_object, ['details'], getv(from_object, ['details']))
|
119
119
|
|
@@ -127,11 +127,11 @@ def _FileStatus_to_mldev(
|
|
127
127
|
|
128
128
|
|
129
129
|
def _FileStatus_to_vertex(
|
130
|
-
api_client:
|
130
|
+
api_client: BaseApiClient,
|
131
131
|
from_object: Union[dict, object],
|
132
|
-
parent_object: dict = None,
|
132
|
+
parent_object: Optional[dict] = None,
|
133
133
|
) -> dict:
|
134
|
-
to_object = {}
|
134
|
+
to_object: dict[str, Any] = {}
|
135
135
|
if getv(from_object, ['details']) is not None:
|
136
136
|
raise ValueError('details parameter is not supported in Vertex AI.')
|
137
137
|
|
@@ -145,11 +145,11 @@ def _FileStatus_to_vertex(
|
|
145
145
|
|
146
146
|
|
147
147
|
def _File_to_mldev(
|
148
|
-
api_client:
|
148
|
+
api_client: BaseApiClient,
|
149
149
|
from_object: Union[dict, object],
|
150
|
-
parent_object: dict = None,
|
150
|
+
parent_object: Optional[dict] = None,
|
151
151
|
) -> dict:
|
152
|
-
to_object = {}
|
152
|
+
to_object: dict[str, Any] = {}
|
153
153
|
if getv(from_object, ['name']) is not None:
|
154
154
|
setv(to_object, ['name'], getv(from_object, ['name']))
|
155
155
|
|
@@ -202,11 +202,11 @@ def _File_to_mldev(
|
|
202
202
|
|
203
203
|
|
204
204
|
def _File_to_vertex(
|
205
|
-
api_client:
|
205
|
+
api_client: BaseApiClient,
|
206
206
|
from_object: Union[dict, object],
|
207
|
-
parent_object: dict = None,
|
207
|
+
parent_object: Optional[dict] = None,
|
208
208
|
) -> dict:
|
209
|
-
to_object = {}
|
209
|
+
to_object: dict[str, Any] = {}
|
210
210
|
if getv(from_object, ['name']) is not None:
|
211
211
|
raise ValueError('name parameter is not supported in Vertex AI.')
|
212
212
|
|
@@ -253,11 +253,11 @@ def _File_to_vertex(
|
|
253
253
|
|
254
254
|
|
255
255
|
def _CreateFileParameters_to_mldev(
|
256
|
-
api_client:
|
256
|
+
api_client: BaseApiClient,
|
257
257
|
from_object: Union[dict, object],
|
258
|
-
parent_object: dict = None,
|
258
|
+
parent_object: Optional[dict] = None,
|
259
259
|
) -> dict:
|
260
|
-
to_object = {}
|
260
|
+
to_object: dict[str, Any] = {}
|
261
261
|
if getv(from_object, ['file']) is not None:
|
262
262
|
setv(
|
263
263
|
to_object,
|
@@ -272,11 +272,11 @@ def _CreateFileParameters_to_mldev(
|
|
272
272
|
|
273
273
|
|
274
274
|
def _CreateFileParameters_to_vertex(
|
275
|
-
api_client:
|
275
|
+
api_client: BaseApiClient,
|
276
276
|
from_object: Union[dict, object],
|
277
|
-
parent_object: dict = None,
|
277
|
+
parent_object: Optional[dict] = None,
|
278
278
|
) -> dict:
|
279
|
-
to_object = {}
|
279
|
+
to_object: dict[str, Any] = {}
|
280
280
|
if getv(from_object, ['file']) is not None:
|
281
281
|
raise ValueError('file parameter is not supported in Vertex AI.')
|
282
282
|
|
@@ -287,11 +287,11 @@ def _CreateFileParameters_to_vertex(
|
|
287
287
|
|
288
288
|
|
289
289
|
def _GetFileParameters_to_mldev(
|
290
|
-
api_client:
|
290
|
+
api_client: BaseApiClient,
|
291
291
|
from_object: Union[dict, object],
|
292
|
-
parent_object: dict = None,
|
292
|
+
parent_object: Optional[dict] = None,
|
293
293
|
) -> dict:
|
294
|
-
to_object = {}
|
294
|
+
to_object: dict[str, Any] = {}
|
295
295
|
if getv(from_object, ['name']) is not None:
|
296
296
|
setv(
|
297
297
|
to_object,
|
@@ -306,11 +306,11 @@ def _GetFileParameters_to_mldev(
|
|
306
306
|
|
307
307
|
|
308
308
|
def _GetFileParameters_to_vertex(
|
309
|
-
api_client:
|
309
|
+
api_client: BaseApiClient,
|
310
310
|
from_object: Union[dict, object],
|
311
|
-
parent_object: dict = None,
|
311
|
+
parent_object: Optional[dict] = None,
|
312
312
|
) -> dict:
|
313
|
-
to_object = {}
|
313
|
+
to_object: dict[str, Any] = {}
|
314
314
|
if getv(from_object, ['name']) is not None:
|
315
315
|
raise ValueError('name parameter is not supported in Vertex AI.')
|
316
316
|
|
@@ -321,11 +321,11 @@ def _GetFileParameters_to_vertex(
|
|
321
321
|
|
322
322
|
|
323
323
|
def _DeleteFileParameters_to_mldev(
|
324
|
-
api_client:
|
324
|
+
api_client: BaseApiClient,
|
325
325
|
from_object: Union[dict, object],
|
326
|
-
parent_object: dict = None,
|
326
|
+
parent_object: Optional[dict] = None,
|
327
327
|
) -> dict:
|
328
|
-
to_object = {}
|
328
|
+
to_object: dict[str, Any] = {}
|
329
329
|
if getv(from_object, ['name']) is not None:
|
330
330
|
setv(
|
331
331
|
to_object,
|
@@ -340,11 +340,11 @@ def _DeleteFileParameters_to_mldev(
|
|
340
340
|
|
341
341
|
|
342
342
|
def _DeleteFileParameters_to_vertex(
|
343
|
-
api_client:
|
343
|
+
api_client: BaseApiClient,
|
344
344
|
from_object: Union[dict, object],
|
345
|
-
parent_object: dict = None,
|
345
|
+
parent_object: Optional[dict] = None,
|
346
346
|
) -> dict:
|
347
|
-
to_object = {}
|
347
|
+
to_object: dict[str, Any] = {}
|
348
348
|
if getv(from_object, ['name']) is not None:
|
349
349
|
raise ValueError('name parameter is not supported in Vertex AI.')
|
350
350
|
|
@@ -365,11 +365,11 @@ def _FileSource_to_vertex_enum_validate(enum_value: Any):
|
|
365
365
|
|
366
366
|
|
367
367
|
def _FileStatus_from_mldev(
|
368
|
-
api_client:
|
368
|
+
api_client: BaseApiClient,
|
369
369
|
from_object: Union[dict, object],
|
370
|
-
parent_object: dict = None,
|
370
|
+
parent_object: Optional[dict] = None,
|
371
371
|
) -> dict:
|
372
|
-
to_object = {}
|
372
|
+
to_object: dict[str, Any] = {}
|
373
373
|
if getv(from_object, ['details']) is not None:
|
374
374
|
setv(to_object, ['details'], getv(from_object, ['details']))
|
375
375
|
|
@@ -383,21 +383,21 @@ def _FileStatus_from_mldev(
|
|
383
383
|
|
384
384
|
|
385
385
|
def _FileStatus_from_vertex(
|
386
|
-
api_client:
|
386
|
+
api_client: BaseApiClient,
|
387
387
|
from_object: Union[dict, object],
|
388
|
-
parent_object: dict = None,
|
388
|
+
parent_object: Optional[dict] = None,
|
389
389
|
) -> dict:
|
390
|
-
to_object = {}
|
390
|
+
to_object: dict[str, Any] = {}
|
391
391
|
|
392
392
|
return to_object
|
393
393
|
|
394
394
|
|
395
395
|
def _File_from_mldev(
|
396
|
-
api_client:
|
396
|
+
api_client: BaseApiClient,
|
397
397
|
from_object: Union[dict, object],
|
398
|
-
parent_object: dict = None,
|
398
|
+
parent_object: Optional[dict] = None,
|
399
399
|
) -> dict:
|
400
|
-
to_object = {}
|
400
|
+
to_object: dict[str, Any] = {}
|
401
401
|
if getv(from_object, ['name']) is not None:
|
402
402
|
setv(to_object, ['name'], getv(from_object, ['name']))
|
403
403
|
|
@@ -450,21 +450,21 @@ def _File_from_mldev(
|
|
450
450
|
|
451
451
|
|
452
452
|
def _File_from_vertex(
|
453
|
-
api_client:
|
453
|
+
api_client: BaseApiClient,
|
454
454
|
from_object: Union[dict, object],
|
455
|
-
parent_object: dict = None,
|
455
|
+
parent_object: Optional[dict] = None,
|
456
456
|
) -> dict:
|
457
|
-
to_object = {}
|
457
|
+
to_object: dict[str, Any] = {}
|
458
458
|
|
459
459
|
return to_object
|
460
460
|
|
461
461
|
|
462
462
|
def _ListFilesResponse_from_mldev(
|
463
|
-
api_client:
|
463
|
+
api_client: BaseApiClient,
|
464
464
|
from_object: Union[dict, object],
|
465
|
-
parent_object: dict = None,
|
465
|
+
parent_object: Optional[dict] = None,
|
466
466
|
) -> dict:
|
467
|
-
to_object = {}
|
467
|
+
to_object: dict[str, Any] = {}
|
468
468
|
if getv(from_object, ['nextPageToken']) is not None:
|
469
469
|
setv(to_object, ['next_page_token'], getv(from_object, ['nextPageToken']))
|
470
470
|
|
@@ -482,21 +482,21 @@ def _ListFilesResponse_from_mldev(
|
|
482
482
|
|
483
483
|
|
484
484
|
def _ListFilesResponse_from_vertex(
|
485
|
-
api_client:
|
485
|
+
api_client: BaseApiClient,
|
486
486
|
from_object: Union[dict, object],
|
487
|
-
parent_object: dict = None,
|
487
|
+
parent_object: Optional[dict] = None,
|
488
488
|
) -> dict:
|
489
|
-
to_object = {}
|
489
|
+
to_object: dict[str, Any] = {}
|
490
490
|
|
491
491
|
return to_object
|
492
492
|
|
493
493
|
|
494
494
|
def _CreateFileResponse_from_mldev(
|
495
|
-
api_client:
|
495
|
+
api_client: BaseApiClient,
|
496
496
|
from_object: Union[dict, object],
|
497
|
-
parent_object: dict = None,
|
497
|
+
parent_object: Optional[dict] = None,
|
498
498
|
) -> dict:
|
499
|
-
to_object = {}
|
499
|
+
to_object: dict[str, Any] = {}
|
500
500
|
if getv(from_object, ['httpHeaders']) is not None:
|
501
501
|
setv(to_object, ['http_headers'], getv(from_object, ['httpHeaders']))
|
502
502
|
|
@@ -504,11 +504,11 @@ def _CreateFileResponse_from_mldev(
|
|
504
504
|
|
505
505
|
|
506
506
|
def _CreateFileResponse_from_vertex(
|
507
|
-
api_client:
|
507
|
+
api_client: BaseApiClient,
|
508
508
|
from_object: Union[dict, object],
|
509
|
-
parent_object: dict = None,
|
509
|
+
parent_object: Optional[dict] = None,
|
510
510
|
) -> dict:
|
511
|
-
to_object = {}
|
511
|
+
to_object: dict[str, Any] = {}
|
512
512
|
if getv(from_object, ['httpHeaders']) is not None:
|
513
513
|
setv(to_object, ['http_headers'], getv(from_object, ['httpHeaders']))
|
514
514
|
|
@@ -516,21 +516,21 @@ def _CreateFileResponse_from_vertex(
|
|
516
516
|
|
517
517
|
|
518
518
|
def _DeleteFileResponse_from_mldev(
|
519
|
-
api_client:
|
519
|
+
api_client: BaseApiClient,
|
520
520
|
from_object: Union[dict, object],
|
521
|
-
parent_object: dict = None,
|
521
|
+
parent_object: Optional[dict] = None,
|
522
522
|
) -> dict:
|
523
|
-
to_object = {}
|
523
|
+
to_object: dict[str, Any] = {}
|
524
524
|
|
525
525
|
return to_object
|
526
526
|
|
527
527
|
|
528
528
|
def _DeleteFileResponse_from_vertex(
|
529
|
-
api_client:
|
529
|
+
api_client: BaseApiClient,
|
530
530
|
from_object: Union[dict, object],
|
531
|
-
parent_object: dict = None,
|
531
|
+
parent_object: Optional[dict] = None,
|
532
532
|
) -> dict:
|
533
|
-
to_object = {}
|
533
|
+
to_object: dict[str, Any] = {}
|
534
534
|
|
535
535
|
return to_object
|
536
536
|
|
@@ -561,13 +561,18 @@ class Files(_api_module.BaseModule):
|
|
561
561
|
config=config,
|
562
562
|
)
|
563
563
|
|
564
|
+
request_url_dict: Optional[dict[str, str]]
|
564
565
|
if self._api_client.vertexai:
|
565
566
|
raise ValueError('This method is only supported in the default client.')
|
566
567
|
else:
|
567
568
|
request_dict = _ListFilesParameters_to_mldev(
|
568
569
|
self._api_client, parameter_model
|
569
570
|
)
|
570
|
-
|
571
|
+
request_url_dict = request_dict.get('_url')
|
572
|
+
if request_url_dict:
|
573
|
+
path = 'files'.format_map(request_url_dict)
|
574
|
+
else:
|
575
|
+
path = 'files'
|
571
576
|
|
572
577
|
query_params = request_dict.get('_query')
|
573
578
|
if query_params:
|
@@ -575,10 +580,10 @@ class Files(_api_module.BaseModule):
|
|
575
580
|
# TODO: remove the hack that pops config.
|
576
581
|
request_dict.pop('config', None)
|
577
582
|
|
578
|
-
http_options = None
|
583
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
579
584
|
if isinstance(config, dict):
|
580
585
|
http_options = config.get('http_options', None)
|
581
|
-
elif hasattr(config, 'http_options'):
|
586
|
+
elif hasattr(config, 'http_options') and config is not None:
|
582
587
|
http_options = config.http_options
|
583
588
|
|
584
589
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -598,7 +603,7 @@ class Files(_api_module.BaseModule):
|
|
598
603
|
)
|
599
604
|
|
600
605
|
return_value = types.ListFilesResponse._from_response(
|
601
|
-
response=response_dict, kwargs=parameter_model
|
606
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
602
607
|
)
|
603
608
|
self._api_client._verify_response(return_value)
|
604
609
|
return return_value
|
@@ -614,13 +619,18 @@ class Files(_api_module.BaseModule):
|
|
614
619
|
config=config,
|
615
620
|
)
|
616
621
|
|
622
|
+
request_url_dict: Optional[dict[str, str]]
|
617
623
|
if self._api_client.vertexai:
|
618
624
|
raise ValueError('This method is only supported in the default client.')
|
619
625
|
else:
|
620
626
|
request_dict = _CreateFileParameters_to_mldev(
|
621
627
|
self._api_client, parameter_model
|
622
628
|
)
|
623
|
-
|
629
|
+
request_url_dict = request_dict.get('_url')
|
630
|
+
if request_url_dict:
|
631
|
+
path = 'upload/v1beta/files'.format_map(request_url_dict)
|
632
|
+
else:
|
633
|
+
path = 'upload/v1beta/files'
|
624
634
|
|
625
635
|
query_params = request_dict.get('_query')
|
626
636
|
if query_params:
|
@@ -628,10 +638,10 @@ class Files(_api_module.BaseModule):
|
|
628
638
|
# TODO: remove the hack that pops config.
|
629
639
|
request_dict.pop('config', None)
|
630
640
|
|
631
|
-
http_options = None
|
641
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
632
642
|
if isinstance(config, dict):
|
633
643
|
http_options = config.get('http_options', None)
|
634
|
-
elif hasattr(config, 'http_options'):
|
644
|
+
elif hasattr(config, 'http_options') and config is not None:
|
635
645
|
http_options = config.http_options
|
636
646
|
|
637
647
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -651,7 +661,7 @@ class Files(_api_module.BaseModule):
|
|
651
661
|
)
|
652
662
|
|
653
663
|
return_value = types.CreateFileResponse._from_response(
|
654
|
-
response=response_dict, kwargs=parameter_model
|
664
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
655
665
|
)
|
656
666
|
self._api_client._verify_response(return_value)
|
657
667
|
return return_value
|
@@ -681,13 +691,18 @@ class Files(_api_module.BaseModule):
|
|
681
691
|
config=config,
|
682
692
|
)
|
683
693
|
|
694
|
+
request_url_dict: Optional[dict[str, str]]
|
684
695
|
if self._api_client.vertexai:
|
685
696
|
raise ValueError('This method is only supported in the default client.')
|
686
697
|
else:
|
687
698
|
request_dict = _GetFileParameters_to_mldev(
|
688
699
|
self._api_client, parameter_model
|
689
700
|
)
|
690
|
-
|
701
|
+
request_url_dict = request_dict.get('_url')
|
702
|
+
if request_url_dict:
|
703
|
+
path = 'files/{file}'.format_map(request_url_dict)
|
704
|
+
else:
|
705
|
+
path = 'files/{file}'
|
691
706
|
|
692
707
|
query_params = request_dict.get('_query')
|
693
708
|
if query_params:
|
@@ -695,10 +710,10 @@ class Files(_api_module.BaseModule):
|
|
695
710
|
# TODO: remove the hack that pops config.
|
696
711
|
request_dict.pop('config', None)
|
697
712
|
|
698
|
-
http_options = None
|
713
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
699
714
|
if isinstance(config, dict):
|
700
715
|
http_options = config.get('http_options', None)
|
701
|
-
elif hasattr(config, 'http_options'):
|
716
|
+
elif hasattr(config, 'http_options') and config is not None:
|
702
717
|
http_options = config.http_options
|
703
718
|
|
704
719
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -714,7 +729,7 @@ class Files(_api_module.BaseModule):
|
|
714
729
|
response_dict = _File_from_mldev(self._api_client, response_dict)
|
715
730
|
|
716
731
|
return_value = types.File._from_response(
|
717
|
-
response=response_dict, kwargs=parameter_model
|
732
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
718
733
|
)
|
719
734
|
self._api_client._verify_response(return_value)
|
720
735
|
return return_value
|
@@ -743,13 +758,18 @@ class Files(_api_module.BaseModule):
|
|
743
758
|
config=config,
|
744
759
|
)
|
745
760
|
|
761
|
+
request_url_dict: Optional[dict[str, str]]
|
746
762
|
if self._api_client.vertexai:
|
747
763
|
raise ValueError('This method is only supported in the default client.')
|
748
764
|
else:
|
749
765
|
request_dict = _DeleteFileParameters_to_mldev(
|
750
766
|
self._api_client, parameter_model
|
751
767
|
)
|
752
|
-
|
768
|
+
request_url_dict = request_dict.get('_url')
|
769
|
+
if request_url_dict:
|
770
|
+
path = 'files/{file}'.format_map(request_url_dict)
|
771
|
+
else:
|
772
|
+
path = 'files/{file}'
|
753
773
|
|
754
774
|
query_params = request_dict.get('_query')
|
755
775
|
if query_params:
|
@@ -757,10 +777,10 @@ class Files(_api_module.BaseModule):
|
|
757
777
|
# TODO: remove the hack that pops config.
|
758
778
|
request_dict.pop('config', None)
|
759
779
|
|
760
|
-
http_options = None
|
780
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
761
781
|
if isinstance(config, dict):
|
762
782
|
http_options = config.get('http_options', None)
|
763
|
-
elif hasattr(config, 'http_options'):
|
783
|
+
elif hasattr(config, 'http_options') and config is not None:
|
764
784
|
http_options = config.http_options
|
765
785
|
|
766
786
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -780,7 +800,7 @@ class Files(_api_module.BaseModule):
|
|
780
800
|
)
|
781
801
|
|
782
802
|
return_value = types.DeleteFileResponse._from_response(
|
783
|
-
response=response_dict, kwargs=parameter_model
|
803
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
784
804
|
)
|
785
805
|
self._api_client._verify_response(return_value)
|
786
806
|
return return_value
|
@@ -848,21 +868,22 @@ class Files(_api_module.BaseModule):
|
|
848
868
|
' file\n please set the `mime_type` argument'
|
849
869
|
)
|
850
870
|
|
871
|
+
http_options: types.HttpOptions
|
851
872
|
if config_model and config_model.http_options:
|
852
873
|
http_options = config_model.http_options
|
853
874
|
else:
|
854
|
-
http_options =
|
855
|
-
|
856
|
-
|
875
|
+
http_options = types.HttpOptions(
|
876
|
+
api_version='',
|
877
|
+
headers={
|
857
878
|
'Content-Type': 'application/json',
|
858
879
|
'X-Goog-Upload-Protocol': 'resumable',
|
859
880
|
'X-Goog-Upload-Command': 'start',
|
860
881
|
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
861
882
|
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
862
883
|
},
|
863
|
-
|
884
|
+
)
|
864
885
|
response = self._create(
|
865
|
-
file=file_obj, config=
|
886
|
+
file=file_obj, config=types.CreateFileConfig(http_options=http_options)
|
866
887
|
)
|
867
888
|
|
868
889
|
if (
|
@@ -885,7 +906,8 @@ class Files(_api_module.BaseModule):
|
|
885
906
|
)
|
886
907
|
|
887
908
|
return types.File._from_response(
|
888
|
-
_File_from_mldev(self._api_client, return_file['file']),
|
909
|
+
response=_File_from_mldev(self._api_client, return_file['file']),
|
910
|
+
kwargs=None,
|
889
911
|
)
|
890
912
|
|
891
913
|
def list(
|
@@ -901,7 +923,7 @@ class Files(_api_module.BaseModule):
|
|
901
923
|
def download(
|
902
924
|
self,
|
903
925
|
*,
|
904
|
-
file: Union[str, types.File],
|
926
|
+
file: Union[str, types.File, types.Video, types.GeneratedVideo],
|
905
927
|
config: Optional[types.DownloadFileConfigOrDict] = None,
|
906
928
|
) -> bytes:
|
907
929
|
"""Downloads a file's data from storage.
|
@@ -909,6 +931,10 @@ class Files(_api_module.BaseModule):
|
|
909
931
|
Files created by `upload` can't be downloaded. You can tell which files are
|
910
932
|
downloadable by checking the `source` or `download_uri` property.
|
911
933
|
|
934
|
+
Note: This method returns the data as bytes. For `Video` and
|
935
|
+
`GeneratedVideo` objects there is an additional side effect, that it also
|
936
|
+
sets the `video_bytes` property on the `Video` object.
|
937
|
+
|
912
938
|
Args:
|
913
939
|
file (str): A file name, uri, or file object. Identifying which file to
|
914
940
|
download.
|
@@ -930,6 +956,10 @@ class Files(_api_module.BaseModule):
|
|
930
956
|
data = client.files.download(file=file)
|
931
957
|
# data = client.files.download(file=file.name)
|
932
958
|
# data = client.files.download(file=file.download_uri)
|
959
|
+
|
960
|
+
video = types.Video(uri=file.uri)
|
961
|
+
video_bytes = client.files.download(file=video)
|
962
|
+
video.video_bytes
|
933
963
|
"""
|
934
964
|
if self._api_client.vertexai:
|
935
965
|
raise ValueError(
|
@@ -964,6 +994,11 @@ class Files(_api_module.BaseModule):
|
|
964
994
|
http_options,
|
965
995
|
)
|
966
996
|
|
997
|
+
if isinstance(file, types.Video):
|
998
|
+
file.video_bytes = data
|
999
|
+
elif isinstance(file, types.GeneratedVideo):
|
1000
|
+
file.video.video_bytes = data
|
1001
|
+
|
967
1002
|
return data
|
968
1003
|
|
969
1004
|
|
@@ -993,13 +1028,18 @@ class AsyncFiles(_api_module.BaseModule):
|
|
993
1028
|
config=config,
|
994
1029
|
)
|
995
1030
|
|
1031
|
+
request_url_dict: Optional[dict[str, str]]
|
996
1032
|
if self._api_client.vertexai:
|
997
1033
|
raise ValueError('This method is only supported in the default client.')
|
998
1034
|
else:
|
999
1035
|
request_dict = _ListFilesParameters_to_mldev(
|
1000
1036
|
self._api_client, parameter_model
|
1001
1037
|
)
|
1002
|
-
|
1038
|
+
request_url_dict = request_dict.get('_url')
|
1039
|
+
if request_url_dict:
|
1040
|
+
path = 'files'.format_map(request_url_dict)
|
1041
|
+
else:
|
1042
|
+
path = 'files'
|
1003
1043
|
|
1004
1044
|
query_params = request_dict.get('_query')
|
1005
1045
|
if query_params:
|
@@ -1007,10 +1047,10 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1007
1047
|
# TODO: remove the hack that pops config.
|
1008
1048
|
request_dict.pop('config', None)
|
1009
1049
|
|
1010
|
-
http_options = None
|
1050
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
1011
1051
|
if isinstance(config, dict):
|
1012
1052
|
http_options = config.get('http_options', None)
|
1013
|
-
elif hasattr(config, 'http_options'):
|
1053
|
+
elif hasattr(config, 'http_options') and config is not None:
|
1014
1054
|
http_options = config.http_options
|
1015
1055
|
|
1016
1056
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -1030,7 +1070,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1030
1070
|
)
|
1031
1071
|
|
1032
1072
|
return_value = types.ListFilesResponse._from_response(
|
1033
|
-
response=response_dict, kwargs=parameter_model
|
1073
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
1034
1074
|
)
|
1035
1075
|
self._api_client._verify_response(return_value)
|
1036
1076
|
return return_value
|
@@ -1046,13 +1086,18 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1046
1086
|
config=config,
|
1047
1087
|
)
|
1048
1088
|
|
1089
|
+
request_url_dict: Optional[dict[str, str]]
|
1049
1090
|
if self._api_client.vertexai:
|
1050
1091
|
raise ValueError('This method is only supported in the default client.')
|
1051
1092
|
else:
|
1052
1093
|
request_dict = _CreateFileParameters_to_mldev(
|
1053
1094
|
self._api_client, parameter_model
|
1054
1095
|
)
|
1055
|
-
|
1096
|
+
request_url_dict = request_dict.get('_url')
|
1097
|
+
if request_url_dict:
|
1098
|
+
path = 'upload/v1beta/files'.format_map(request_url_dict)
|
1099
|
+
else:
|
1100
|
+
path = 'upload/v1beta/files'
|
1056
1101
|
|
1057
1102
|
query_params = request_dict.get('_query')
|
1058
1103
|
if query_params:
|
@@ -1060,10 +1105,10 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1060
1105
|
# TODO: remove the hack that pops config.
|
1061
1106
|
request_dict.pop('config', None)
|
1062
1107
|
|
1063
|
-
http_options = None
|
1108
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
1064
1109
|
if isinstance(config, dict):
|
1065
1110
|
http_options = config.get('http_options', None)
|
1066
|
-
elif hasattr(config, 'http_options'):
|
1111
|
+
elif hasattr(config, 'http_options') and config is not None:
|
1067
1112
|
http_options = config.http_options
|
1068
1113
|
|
1069
1114
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -1083,7 +1128,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1083
1128
|
)
|
1084
1129
|
|
1085
1130
|
return_value = types.CreateFileResponse._from_response(
|
1086
|
-
response=response_dict, kwargs=parameter_model
|
1131
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
1087
1132
|
)
|
1088
1133
|
self._api_client._verify_response(return_value)
|
1089
1134
|
return return_value
|
@@ -1113,13 +1158,18 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1113
1158
|
config=config,
|
1114
1159
|
)
|
1115
1160
|
|
1161
|
+
request_url_dict: Optional[dict[str, str]]
|
1116
1162
|
if self._api_client.vertexai:
|
1117
1163
|
raise ValueError('This method is only supported in the default client.')
|
1118
1164
|
else:
|
1119
1165
|
request_dict = _GetFileParameters_to_mldev(
|
1120
1166
|
self._api_client, parameter_model
|
1121
1167
|
)
|
1122
|
-
|
1168
|
+
request_url_dict = request_dict.get('_url')
|
1169
|
+
if request_url_dict:
|
1170
|
+
path = 'files/{file}'.format_map(request_url_dict)
|
1171
|
+
else:
|
1172
|
+
path = 'files/{file}'
|
1123
1173
|
|
1124
1174
|
query_params = request_dict.get('_query')
|
1125
1175
|
if query_params:
|
@@ -1127,10 +1177,10 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1127
1177
|
# TODO: remove the hack that pops config.
|
1128
1178
|
request_dict.pop('config', None)
|
1129
1179
|
|
1130
|
-
http_options = None
|
1180
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
1131
1181
|
if isinstance(config, dict):
|
1132
1182
|
http_options = config.get('http_options', None)
|
1133
|
-
elif hasattr(config, 'http_options'):
|
1183
|
+
elif hasattr(config, 'http_options') and config is not None:
|
1134
1184
|
http_options = config.http_options
|
1135
1185
|
|
1136
1186
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -1146,7 +1196,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1146
1196
|
response_dict = _File_from_mldev(self._api_client, response_dict)
|
1147
1197
|
|
1148
1198
|
return_value = types.File._from_response(
|
1149
|
-
response=response_dict, kwargs=parameter_model
|
1199
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
1150
1200
|
)
|
1151
1201
|
self._api_client._verify_response(return_value)
|
1152
1202
|
return return_value
|
@@ -1175,13 +1225,18 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1175
1225
|
config=config,
|
1176
1226
|
)
|
1177
1227
|
|
1228
|
+
request_url_dict: Optional[dict[str, str]]
|
1178
1229
|
if self._api_client.vertexai:
|
1179
1230
|
raise ValueError('This method is only supported in the default client.')
|
1180
1231
|
else:
|
1181
1232
|
request_dict = _DeleteFileParameters_to_mldev(
|
1182
1233
|
self._api_client, parameter_model
|
1183
1234
|
)
|
1184
|
-
|
1235
|
+
request_url_dict = request_dict.get('_url')
|
1236
|
+
if request_url_dict:
|
1237
|
+
path = 'files/{file}'.format_map(request_url_dict)
|
1238
|
+
else:
|
1239
|
+
path = 'files/{file}'
|
1185
1240
|
|
1186
1241
|
query_params = request_dict.get('_query')
|
1187
1242
|
if query_params:
|
@@ -1189,10 +1244,10 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1189
1244
|
# TODO: remove the hack that pops config.
|
1190
1245
|
request_dict.pop('config', None)
|
1191
1246
|
|
1192
|
-
http_options = None
|
1247
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
1193
1248
|
if isinstance(config, dict):
|
1194
1249
|
http_options = config.get('http_options', None)
|
1195
|
-
elif hasattr(config, 'http_options'):
|
1250
|
+
elif hasattr(config, 'http_options') and config is not None:
|
1196
1251
|
http_options = config.http_options
|
1197
1252
|
|
1198
1253
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -1212,7 +1267,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1212
1267
|
)
|
1213
1268
|
|
1214
1269
|
return_value = types.DeleteFileResponse._from_response(
|
1215
|
-
response=response_dict, kwargs=parameter_model
|
1270
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
1216
1271
|
)
|
1217
1272
|
self._api_client._verify_response(return_value)
|
1218
1273
|
return return_value
|
@@ -1280,23 +1335,23 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1280
1335
|
' file\n please set the `mime_type` argument'
|
1281
1336
|
)
|
1282
1337
|
|
1338
|
+
http_options: types.HttpOptions
|
1283
1339
|
if config_model and config_model.http_options:
|
1284
1340
|
http_options = config_model.http_options
|
1285
1341
|
else:
|
1286
|
-
http_options =
|
1287
|
-
|
1288
|
-
|
1342
|
+
http_options = types.HttpOptions(
|
1343
|
+
api_version='',
|
1344
|
+
headers={
|
1289
1345
|
'Content-Type': 'application/json',
|
1290
1346
|
'X-Goog-Upload-Protocol': 'resumable',
|
1291
1347
|
'X-Goog-Upload-Command': 'start',
|
1292
1348
|
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
1293
1349
|
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
1294
1350
|
},
|
1295
|
-
|
1351
|
+
)
|
1296
1352
|
response = await self._create(
|
1297
|
-
file=file_obj, config=
|
1353
|
+
file=file_obj, config=types.CreateFileConfig(http_options=http_options)
|
1298
1354
|
)
|
1299
|
-
|
1300
1355
|
if (
|
1301
1356
|
response.http_headers is None
|
1302
1357
|
or 'x-goog-upload-url' not in response.http_headers
|
@@ -1317,7 +1372,8 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1317
1372
|
)
|
1318
1373
|
|
1319
1374
|
return types.File._from_response(
|
1320
|
-
_File_from_mldev(self._api_client, return_file['file']),
|
1375
|
+
response=_File_from_mldev(self._api_client, return_file['file']),
|
1376
|
+
kwargs=None,
|
1321
1377
|
)
|
1322
1378
|
|
1323
1379
|
async def list(
|