google-genai 1.7.0__py3-none-any.whl → 1.53.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/__init__.py +4 -2
- google/genai/_adapters.py +55 -0
- google/genai/_api_client.py +1301 -299
- google/genai/_api_module.py +1 -1
- google/genai/_automatic_function_calling_util.py +54 -33
- google/genai/_base_transformers.py +26 -0
- google/genai/_base_url.py +50 -0
- google/genai/_common.py +560 -59
- google/genai/_extra_utils.py +371 -38
- google/genai/_live_converters.py +1467 -0
- google/genai/_local_tokenizer_loader.py +214 -0
- google/genai/_mcp_utils.py +117 -0
- google/genai/_operations_converters.py +394 -0
- google/genai/_replay_api_client.py +204 -92
- google/genai/_test_api_client.py +1 -1
- google/genai/_tokens_converters.py +520 -0
- google/genai/_transformers.py +633 -233
- google/genai/batches.py +1733 -538
- google/genai/caches.py +678 -1012
- google/genai/chats.py +48 -38
- google/genai/client.py +142 -15
- google/genai/documents.py +532 -0
- google/genai/errors.py +141 -35
- google/genai/file_search_stores.py +1296 -0
- google/genai/files.py +312 -744
- google/genai/live.py +617 -367
- google/genai/live_music.py +197 -0
- google/genai/local_tokenizer.py +395 -0
- google/genai/models.py +3598 -3116
- google/genai/operations.py +201 -362
- google/genai/pagers.py +23 -7
- google/genai/py.typed +1 -0
- google/genai/tokens.py +362 -0
- google/genai/tunings.py +1274 -496
- google/genai/types.py +14535 -5454
- google/genai/version.py +2 -2
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/METADATA +736 -234
- google_genai-1.53.0.dist-info/RECORD +41 -0
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/WHEEL +1 -1
- google_genai-1.7.0.dist-info/RECORD +0 -27
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info/licenses}/LICENSE +0 -0
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/top_level.txt +0 -0
google/genai/files.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -16,521 +16,135 @@
|
|
|
16
16
|
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
17
17
|
|
|
18
18
|
import io
|
|
19
|
+
import json
|
|
19
20
|
import logging
|
|
20
|
-
import mimetypes
|
|
21
21
|
import os
|
|
22
|
-
import pathlib
|
|
23
22
|
from typing import Any, Optional, Union
|
|
24
23
|
from urllib.parse import urlencode
|
|
24
|
+
|
|
25
25
|
from . import _api_module
|
|
26
26
|
from . import _common
|
|
27
|
+
from . import _extra_utils
|
|
27
28
|
from . import _transformers as t
|
|
28
29
|
from . import types
|
|
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
|
|
33
33
|
|
|
34
|
-
logger = logging.getLogger('google_genai.files')
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def _ListFilesConfig_to_mldev(
|
|
38
|
-
api_client: BaseApiClient,
|
|
39
|
-
from_object: Union[dict, object],
|
|
40
|
-
parent_object: Optional[dict] = None,
|
|
41
|
-
) -> dict:
|
|
42
|
-
to_object: dict[str, Any] = {}
|
|
43
|
-
|
|
44
|
-
if getv(from_object, ['page_size']) is not None:
|
|
45
|
-
setv(
|
|
46
|
-
parent_object, ['_query', 'pageSize'], getv(from_object, ['page_size'])
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
if getv(from_object, ['page_token']) is not None:
|
|
50
|
-
setv(
|
|
51
|
-
parent_object,
|
|
52
|
-
['_query', 'pageToken'],
|
|
53
|
-
getv(from_object, ['page_token']),
|
|
54
|
-
)
|
|
55
34
|
|
|
56
|
-
|
|
35
|
+
logger = logging.getLogger('google_genai.files')
|
|
57
36
|
|
|
58
37
|
|
|
59
|
-
def
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
) -> dict:
|
|
38
|
+
def _CreateFileParameters_to_mldev(
|
|
39
|
+
from_object: Union[dict[str, Any], object],
|
|
40
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
41
|
+
) -> dict[str, Any]:
|
|
64
42
|
to_object: dict[str, Any] = {}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
setv(
|
|
68
|
-
parent_object, ['_query', 'pageSize'], getv(from_object, ['page_size'])
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
if getv(from_object, ['page_token']) is not None:
|
|
72
|
-
setv(
|
|
73
|
-
parent_object,
|
|
74
|
-
['_query', 'pageToken'],
|
|
75
|
-
getv(from_object, ['page_token']),
|
|
76
|
-
)
|
|
43
|
+
if getv(from_object, ['file']) is not None:
|
|
44
|
+
setv(to_object, ['file'], getv(from_object, ['file']))
|
|
77
45
|
|
|
78
46
|
return to_object
|
|
79
47
|
|
|
80
48
|
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
) -> dict:
|
|
49
|
+
def _CreateFileResponse_from_mldev(
|
|
50
|
+
from_object: Union[dict[str, Any], object],
|
|
51
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
52
|
+
) -> dict[str, Any]:
|
|
86
53
|
to_object: dict[str, Any] = {}
|
|
87
|
-
if getv(from_object, ['
|
|
54
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
88
55
|
setv(
|
|
89
|
-
to_object,
|
|
90
|
-
['config'],
|
|
91
|
-
_ListFilesConfig_to_mldev(
|
|
92
|
-
api_client, getv(from_object, ['config']), to_object
|
|
93
|
-
),
|
|
56
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
94
57
|
)
|
|
95
58
|
|
|
96
59
|
return to_object
|
|
97
60
|
|
|
98
61
|
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
) -> dict:
|
|
104
|
-
to_object: dict[str, Any] = {}
|
|
105
|
-
if getv(from_object, ['config']) is not None:
|
|
106
|
-
raise ValueError('config parameter is not supported in Vertex AI.')
|
|
107
|
-
|
|
108
|
-
return to_object
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def _FileStatus_to_mldev(
|
|
112
|
-
api_client: BaseApiClient,
|
|
113
|
-
from_object: Union[dict, object],
|
|
114
|
-
parent_object: Optional[dict] = None,
|
|
115
|
-
) -> dict:
|
|
116
|
-
to_object: dict[str, Any] = {}
|
|
117
|
-
if getv(from_object, ['details']) is not None:
|
|
118
|
-
setv(to_object, ['details'], getv(from_object, ['details']))
|
|
119
|
-
|
|
120
|
-
if getv(from_object, ['message']) is not None:
|
|
121
|
-
setv(to_object, ['message'], getv(from_object, ['message']))
|
|
122
|
-
|
|
123
|
-
if getv(from_object, ['code']) is not None:
|
|
124
|
-
setv(to_object, ['code'], getv(from_object, ['code']))
|
|
125
|
-
|
|
126
|
-
return to_object
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def _FileStatus_to_vertex(
|
|
130
|
-
api_client: BaseApiClient,
|
|
131
|
-
from_object: Union[dict, object],
|
|
132
|
-
parent_object: Optional[dict] = None,
|
|
133
|
-
) -> dict:
|
|
134
|
-
to_object: dict[str, Any] = {}
|
|
135
|
-
if getv(from_object, ['details']) is not None:
|
|
136
|
-
raise ValueError('details parameter is not supported in Vertex AI.')
|
|
137
|
-
|
|
138
|
-
if getv(from_object, ['message']) is not None:
|
|
139
|
-
raise ValueError('message parameter is not supported in Vertex AI.')
|
|
140
|
-
|
|
141
|
-
if getv(from_object, ['code']) is not None:
|
|
142
|
-
raise ValueError('code parameter is not supported in Vertex AI.')
|
|
143
|
-
|
|
144
|
-
return to_object
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
def _File_to_mldev(
|
|
148
|
-
api_client: BaseApiClient,
|
|
149
|
-
from_object: Union[dict, object],
|
|
150
|
-
parent_object: Optional[dict] = None,
|
|
151
|
-
) -> dict:
|
|
62
|
+
def _DeleteFileParameters_to_mldev(
|
|
63
|
+
from_object: Union[dict[str, Any], object],
|
|
64
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
65
|
+
) -> dict[str, Any]:
|
|
152
66
|
to_object: dict[str, Any] = {}
|
|
153
67
|
if getv(from_object, ['name']) is not None:
|
|
154
|
-
setv(to_object, ['name'], getv(from_object, ['name']))
|
|
155
|
-
|
|
156
|
-
if getv(from_object, ['display_name']) is not None:
|
|
157
|
-
setv(to_object, ['displayName'], getv(from_object, ['display_name']))
|
|
158
|
-
|
|
159
|
-
if getv(from_object, ['mime_type']) is not None:
|
|
160
|
-
setv(to_object, ['mimeType'], getv(from_object, ['mime_type']))
|
|
161
|
-
|
|
162
|
-
if getv(from_object, ['size_bytes']) is not None:
|
|
163
|
-
setv(to_object, ['sizeBytes'], getv(from_object, ['size_bytes']))
|
|
164
|
-
|
|
165
|
-
if getv(from_object, ['create_time']) is not None:
|
|
166
|
-
setv(to_object, ['createTime'], getv(from_object, ['create_time']))
|
|
167
|
-
|
|
168
|
-
if getv(from_object, ['expiration_time']) is not None:
|
|
169
|
-
setv(to_object, ['expirationTime'], getv(from_object, ['expiration_time']))
|
|
170
|
-
|
|
171
|
-
if getv(from_object, ['update_time']) is not None:
|
|
172
|
-
setv(to_object, ['updateTime'], getv(from_object, ['update_time']))
|
|
173
|
-
|
|
174
|
-
if getv(from_object, ['sha256_hash']) is not None:
|
|
175
|
-
setv(to_object, ['sha256Hash'], getv(from_object, ['sha256_hash']))
|
|
176
|
-
|
|
177
|
-
if getv(from_object, ['uri']) is not None:
|
|
178
|
-
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
|
179
|
-
|
|
180
|
-
if getv(from_object, ['download_uri']) is not None:
|
|
181
|
-
setv(to_object, ['downloadUri'], getv(from_object, ['download_uri']))
|
|
182
|
-
|
|
183
|
-
if getv(from_object, ['state']) is not None:
|
|
184
|
-
setv(to_object, ['state'], getv(from_object, ['state']))
|
|
185
|
-
|
|
186
|
-
if getv(from_object, ['source']) is not None:
|
|
187
|
-
setv(to_object, ['source'], getv(from_object, ['source']))
|
|
188
|
-
|
|
189
|
-
if getv(from_object, ['video_metadata']) is not None:
|
|
190
|
-
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
|
|
191
|
-
|
|
192
|
-
if getv(from_object, ['error']) is not None:
|
|
193
68
|
setv(
|
|
194
|
-
to_object,
|
|
195
|
-
['error'],
|
|
196
|
-
_FileStatus_to_mldev(
|
|
197
|
-
api_client, getv(from_object, ['error']), to_object
|
|
198
|
-
),
|
|
69
|
+
to_object, ['_url', 'file'], t.t_file_name(getv(from_object, ['name']))
|
|
199
70
|
)
|
|
200
71
|
|
|
201
72
|
return to_object
|
|
202
73
|
|
|
203
74
|
|
|
204
|
-
def
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
) -> dict:
|
|
209
|
-
to_object: dict[str, Any] = {}
|
|
210
|
-
if getv(from_object, ['name']) is not None:
|
|
211
|
-
raise ValueError('name parameter is not supported in Vertex AI.')
|
|
212
|
-
|
|
213
|
-
if getv(from_object, ['display_name']) is not None:
|
|
214
|
-
raise ValueError('display_name parameter is not supported in Vertex AI.')
|
|
215
|
-
|
|
216
|
-
if getv(from_object, ['mime_type']) is not None:
|
|
217
|
-
raise ValueError('mime_type parameter is not supported in Vertex AI.')
|
|
218
|
-
|
|
219
|
-
if getv(from_object, ['size_bytes']) is not None:
|
|
220
|
-
raise ValueError('size_bytes parameter is not supported in Vertex AI.')
|
|
221
|
-
|
|
222
|
-
if getv(from_object, ['create_time']) is not None:
|
|
223
|
-
raise ValueError('create_time parameter is not supported in Vertex AI.')
|
|
224
|
-
|
|
225
|
-
if getv(from_object, ['expiration_time']) is not None:
|
|
226
|
-
raise ValueError('expiration_time parameter is not supported in Vertex AI.')
|
|
227
|
-
|
|
228
|
-
if getv(from_object, ['update_time']) is not None:
|
|
229
|
-
raise ValueError('update_time parameter is not supported in Vertex AI.')
|
|
230
|
-
|
|
231
|
-
if getv(from_object, ['sha256_hash']) is not None:
|
|
232
|
-
raise ValueError('sha256_hash parameter is not supported in Vertex AI.')
|
|
233
|
-
|
|
234
|
-
if getv(from_object, ['uri']) is not None:
|
|
235
|
-
raise ValueError('uri parameter is not supported in Vertex AI.')
|
|
236
|
-
|
|
237
|
-
if getv(from_object, ['download_uri']) is not None:
|
|
238
|
-
raise ValueError('download_uri parameter is not supported in Vertex AI.')
|
|
239
|
-
|
|
240
|
-
if getv(from_object, ['state']) is not None:
|
|
241
|
-
raise ValueError('state parameter is not supported in Vertex AI.')
|
|
242
|
-
|
|
243
|
-
if getv(from_object, ['source']) is not None:
|
|
244
|
-
raise ValueError('source parameter is not supported in Vertex AI.')
|
|
245
|
-
|
|
246
|
-
if getv(from_object, ['video_metadata']) is not None:
|
|
247
|
-
raise ValueError('video_metadata parameter is not supported in Vertex AI.')
|
|
248
|
-
|
|
249
|
-
if getv(from_object, ['error']) is not None:
|
|
250
|
-
raise ValueError('error parameter is not supported in Vertex AI.')
|
|
251
|
-
|
|
252
|
-
return to_object
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
def _CreateFileParameters_to_mldev(
|
|
256
|
-
api_client: BaseApiClient,
|
|
257
|
-
from_object: Union[dict, object],
|
|
258
|
-
parent_object: Optional[dict] = None,
|
|
259
|
-
) -> dict:
|
|
75
|
+
def _DeleteFileResponse_from_mldev(
|
|
76
|
+
from_object: Union[dict[str, Any], object],
|
|
77
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
78
|
+
) -> dict[str, Any]:
|
|
260
79
|
to_object: dict[str, Any] = {}
|
|
261
|
-
if getv(from_object, ['
|
|
80
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
262
81
|
setv(
|
|
263
|
-
to_object,
|
|
264
|
-
['file'],
|
|
265
|
-
_File_to_mldev(api_client, getv(from_object, ['file']), to_object),
|
|
82
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
266
83
|
)
|
|
267
84
|
|
|
268
|
-
if getv(from_object, ['config']) is not None:
|
|
269
|
-
setv(to_object, ['config'], getv(from_object, ['config']))
|
|
270
|
-
|
|
271
|
-
return to_object
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
def _CreateFileParameters_to_vertex(
|
|
275
|
-
api_client: BaseApiClient,
|
|
276
|
-
from_object: Union[dict, object],
|
|
277
|
-
parent_object: Optional[dict] = None,
|
|
278
|
-
) -> dict:
|
|
279
|
-
to_object: dict[str, Any] = {}
|
|
280
|
-
if getv(from_object, ['file']) is not None:
|
|
281
|
-
raise ValueError('file parameter is not supported in Vertex AI.')
|
|
282
|
-
|
|
283
|
-
if getv(from_object, ['config']) is not None:
|
|
284
|
-
raise ValueError('config parameter is not supported in Vertex AI.')
|
|
285
|
-
|
|
286
85
|
return to_object
|
|
287
86
|
|
|
288
87
|
|
|
289
88
|
def _GetFileParameters_to_mldev(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
) -> dict:
|
|
89
|
+
from_object: Union[dict[str, Any], object],
|
|
90
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
91
|
+
) -> dict[str, Any]:
|
|
294
92
|
to_object: dict[str, Any] = {}
|
|
295
93
|
if getv(from_object, ['name']) is not None:
|
|
296
94
|
setv(
|
|
297
|
-
to_object,
|
|
298
|
-
['_url', 'file'],
|
|
299
|
-
t.t_file_name(api_client, getv(from_object, ['name'])),
|
|
95
|
+
to_object, ['_url', 'file'], t.t_file_name(getv(from_object, ['name']))
|
|
300
96
|
)
|
|
301
97
|
|
|
302
|
-
if getv(from_object, ['config']) is not None:
|
|
303
|
-
setv(to_object, ['config'], getv(from_object, ['config']))
|
|
304
|
-
|
|
305
98
|
return to_object
|
|
306
99
|
|
|
307
100
|
|
|
308
|
-
def
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
) -> dict:
|
|
101
|
+
def _ListFilesConfig_to_mldev(
|
|
102
|
+
from_object: Union[dict[str, Any], object],
|
|
103
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
104
|
+
) -> dict[str, Any]:
|
|
313
105
|
to_object: dict[str, Any] = {}
|
|
314
|
-
if getv(from_object, ['name']) is not None:
|
|
315
|
-
raise ValueError('name parameter is not supported in Vertex AI.')
|
|
316
106
|
|
|
317
|
-
if getv(from_object, ['
|
|
318
|
-
raise ValueError('config parameter is not supported in Vertex AI.')
|
|
319
|
-
|
|
320
|
-
return to_object
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
def _DeleteFileParameters_to_mldev(
|
|
324
|
-
api_client: BaseApiClient,
|
|
325
|
-
from_object: Union[dict, object],
|
|
326
|
-
parent_object: Optional[dict] = None,
|
|
327
|
-
) -> dict:
|
|
328
|
-
to_object: dict[str, Any] = {}
|
|
329
|
-
if getv(from_object, ['name']) is not None:
|
|
107
|
+
if getv(from_object, ['page_size']) is not None:
|
|
330
108
|
setv(
|
|
331
|
-
|
|
332
|
-
['_url', 'file'],
|
|
333
|
-
t.t_file_name(api_client, getv(from_object, ['name'])),
|
|
109
|
+
parent_object, ['_query', 'pageSize'], getv(from_object, ['page_size'])
|
|
334
110
|
)
|
|
335
111
|
|
|
336
|
-
if getv(from_object, ['
|
|
337
|
-
setv(
|
|
112
|
+
if getv(from_object, ['page_token']) is not None:
|
|
113
|
+
setv(
|
|
114
|
+
parent_object,
|
|
115
|
+
['_query', 'pageToken'],
|
|
116
|
+
getv(from_object, ['page_token']),
|
|
117
|
+
)
|
|
338
118
|
|
|
339
119
|
return to_object
|
|
340
120
|
|
|
341
121
|
|
|
342
|
-
def
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
) -> dict:
|
|
122
|
+
def _ListFilesParameters_to_mldev(
|
|
123
|
+
from_object: Union[dict[str, Any], object],
|
|
124
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
125
|
+
) -> dict[str, Any]:
|
|
347
126
|
to_object: dict[str, Any] = {}
|
|
348
|
-
if getv(from_object, ['name']) is not None:
|
|
349
|
-
raise ValueError('name parameter is not supported in Vertex AI.')
|
|
350
|
-
|
|
351
127
|
if getv(from_object, ['config']) is not None:
|
|
352
|
-
|
|
128
|
+
_ListFilesConfig_to_mldev(getv(from_object, ['config']), to_object)
|
|
353
129
|
|
|
354
130
|
return to_object
|
|
355
131
|
|
|
356
132
|
|
|
357
|
-
def
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
def _FileSource_to_vertex_enum_validate(enum_value: Any):
|
|
363
|
-
if enum_value in set(['SOURCE_UNSPECIFIED', 'UPLOADED', 'GENERATED']):
|
|
364
|
-
raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
def _FileStatus_from_mldev(
|
|
368
|
-
api_client: BaseApiClient,
|
|
369
|
-
from_object: Union[dict, object],
|
|
370
|
-
parent_object: Optional[dict] = None,
|
|
371
|
-
) -> dict:
|
|
372
|
-
to_object: dict[str, Any] = {}
|
|
373
|
-
if getv(from_object, ['details']) is not None:
|
|
374
|
-
setv(to_object, ['details'], getv(from_object, ['details']))
|
|
375
|
-
|
|
376
|
-
if getv(from_object, ['message']) is not None:
|
|
377
|
-
setv(to_object, ['message'], getv(from_object, ['message']))
|
|
378
|
-
|
|
379
|
-
if getv(from_object, ['code']) is not None:
|
|
380
|
-
setv(to_object, ['code'], getv(from_object, ['code']))
|
|
381
|
-
|
|
382
|
-
return to_object
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
def _FileStatus_from_vertex(
|
|
386
|
-
api_client: BaseApiClient,
|
|
387
|
-
from_object: Union[dict, object],
|
|
388
|
-
parent_object: Optional[dict] = None,
|
|
389
|
-
) -> dict:
|
|
390
|
-
to_object: dict[str, Any] = {}
|
|
391
|
-
|
|
392
|
-
return to_object
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
def _File_from_mldev(
|
|
396
|
-
api_client: BaseApiClient,
|
|
397
|
-
from_object: Union[dict, object],
|
|
398
|
-
parent_object: Optional[dict] = None,
|
|
399
|
-
) -> dict:
|
|
133
|
+
def _ListFilesResponse_from_mldev(
|
|
134
|
+
from_object: Union[dict[str, Any], object],
|
|
135
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
136
|
+
) -> dict[str, Any]:
|
|
400
137
|
to_object: dict[str, Any] = {}
|
|
401
|
-
if getv(from_object, ['
|
|
402
|
-
setv(to_object, ['name'], getv(from_object, ['name']))
|
|
403
|
-
|
|
404
|
-
if getv(from_object, ['displayName']) is not None:
|
|
405
|
-
setv(to_object, ['display_name'], getv(from_object, ['displayName']))
|
|
406
|
-
|
|
407
|
-
if getv(from_object, ['mimeType']) is not None:
|
|
408
|
-
setv(to_object, ['mime_type'], getv(from_object, ['mimeType']))
|
|
409
|
-
|
|
410
|
-
if getv(from_object, ['sizeBytes']) is not None:
|
|
411
|
-
setv(to_object, ['size_bytes'], getv(from_object, ['sizeBytes']))
|
|
412
|
-
|
|
413
|
-
if getv(from_object, ['createTime']) is not None:
|
|
414
|
-
setv(to_object, ['create_time'], getv(from_object, ['createTime']))
|
|
415
|
-
|
|
416
|
-
if getv(from_object, ['expirationTime']) is not None:
|
|
417
|
-
setv(to_object, ['expiration_time'], getv(from_object, ['expirationTime']))
|
|
418
|
-
|
|
419
|
-
if getv(from_object, ['updateTime']) is not None:
|
|
420
|
-
setv(to_object, ['update_time'], getv(from_object, ['updateTime']))
|
|
421
|
-
|
|
422
|
-
if getv(from_object, ['sha256Hash']) is not None:
|
|
423
|
-
setv(to_object, ['sha256_hash'], getv(from_object, ['sha256Hash']))
|
|
424
|
-
|
|
425
|
-
if getv(from_object, ['uri']) is not None:
|
|
426
|
-
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
|
427
|
-
|
|
428
|
-
if getv(from_object, ['downloadUri']) is not None:
|
|
429
|
-
setv(to_object, ['download_uri'], getv(from_object, ['downloadUri']))
|
|
430
|
-
|
|
431
|
-
if getv(from_object, ['state']) is not None:
|
|
432
|
-
setv(to_object, ['state'], getv(from_object, ['state']))
|
|
433
|
-
|
|
434
|
-
if getv(from_object, ['source']) is not None:
|
|
435
|
-
setv(to_object, ['source'], getv(from_object, ['source']))
|
|
436
|
-
|
|
437
|
-
if getv(from_object, ['videoMetadata']) is not None:
|
|
438
|
-
setv(to_object, ['video_metadata'], getv(from_object, ['videoMetadata']))
|
|
439
|
-
|
|
440
|
-
if getv(from_object, ['error']) is not None:
|
|
138
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
441
139
|
setv(
|
|
442
|
-
to_object,
|
|
443
|
-
['error'],
|
|
444
|
-
_FileStatus_from_mldev(
|
|
445
|
-
api_client, getv(from_object, ['error']), to_object
|
|
446
|
-
),
|
|
140
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
447
141
|
)
|
|
448
142
|
|
|
449
|
-
return to_object
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
def _File_from_vertex(
|
|
453
|
-
api_client: BaseApiClient,
|
|
454
|
-
from_object: Union[dict, object],
|
|
455
|
-
parent_object: Optional[dict] = None,
|
|
456
|
-
) -> dict:
|
|
457
|
-
to_object: dict[str, Any] = {}
|
|
458
|
-
|
|
459
|
-
return to_object
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
def _ListFilesResponse_from_mldev(
|
|
463
|
-
api_client: BaseApiClient,
|
|
464
|
-
from_object: Union[dict, object],
|
|
465
|
-
parent_object: Optional[dict] = None,
|
|
466
|
-
) -> dict:
|
|
467
|
-
to_object: dict[str, Any] = {}
|
|
468
143
|
if getv(from_object, ['nextPageToken']) is not None:
|
|
469
144
|
setv(to_object, ['next_page_token'], getv(from_object, ['nextPageToken']))
|
|
470
145
|
|
|
471
146
|
if getv(from_object, ['files']) is not None:
|
|
472
|
-
setv(
|
|
473
|
-
to_object,
|
|
474
|
-
['files'],
|
|
475
|
-
[
|
|
476
|
-
_File_from_mldev(api_client, item, to_object)
|
|
477
|
-
for item in getv(from_object, ['files'])
|
|
478
|
-
],
|
|
479
|
-
)
|
|
480
|
-
|
|
481
|
-
return to_object
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
def _ListFilesResponse_from_vertex(
|
|
485
|
-
api_client: BaseApiClient,
|
|
486
|
-
from_object: Union[dict, object],
|
|
487
|
-
parent_object: Optional[dict] = None,
|
|
488
|
-
) -> dict:
|
|
489
|
-
to_object: dict[str, Any] = {}
|
|
490
|
-
|
|
491
|
-
return to_object
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
def _CreateFileResponse_from_mldev(
|
|
495
|
-
api_client: BaseApiClient,
|
|
496
|
-
from_object: Union[dict, object],
|
|
497
|
-
parent_object: Optional[dict] = None,
|
|
498
|
-
) -> dict:
|
|
499
|
-
to_object: dict[str, Any] = {}
|
|
500
|
-
if getv(from_object, ['httpHeaders']) is not None:
|
|
501
|
-
setv(to_object, ['http_headers'], getv(from_object, ['httpHeaders']))
|
|
502
|
-
|
|
503
|
-
return to_object
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
def _CreateFileResponse_from_vertex(
|
|
507
|
-
api_client: BaseApiClient,
|
|
508
|
-
from_object: Union[dict, object],
|
|
509
|
-
parent_object: Optional[dict] = None,
|
|
510
|
-
) -> dict:
|
|
511
|
-
to_object: dict[str, Any] = {}
|
|
512
|
-
if getv(from_object, ['httpHeaders']) is not None:
|
|
513
|
-
setv(to_object, ['http_headers'], getv(from_object, ['httpHeaders']))
|
|
514
|
-
|
|
515
|
-
return to_object
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
def _DeleteFileResponse_from_mldev(
|
|
519
|
-
api_client: BaseApiClient,
|
|
520
|
-
from_object: Union[dict, object],
|
|
521
|
-
parent_object: Optional[dict] = None,
|
|
522
|
-
) -> dict:
|
|
523
|
-
to_object: dict[str, Any] = {}
|
|
524
|
-
|
|
525
|
-
return to_object
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
def _DeleteFileResponse_from_vertex(
|
|
529
|
-
api_client: BaseApiClient,
|
|
530
|
-
from_object: Union[dict, object],
|
|
531
|
-
parent_object: Optional[dict] = None,
|
|
532
|
-
) -> dict:
|
|
533
|
-
to_object: dict[str, Any] = {}
|
|
147
|
+
setv(to_object, ['files'], [item for item in getv(from_object, ['files'])])
|
|
534
148
|
|
|
535
149
|
return to_object
|
|
536
150
|
|
|
@@ -540,34 +154,17 @@ class Files(_api_module.BaseModule):
|
|
|
540
154
|
def _list(
|
|
541
155
|
self, *, config: Optional[types.ListFilesConfigOrDict] = None
|
|
542
156
|
) -> types.ListFilesResponse:
|
|
543
|
-
"""Lists all files from the service.
|
|
544
|
-
|
|
545
|
-
Args:
|
|
546
|
-
config (ListFilesConfig): Optional, configuration for the list method.
|
|
547
|
-
|
|
548
|
-
Returns:
|
|
549
|
-
ListFilesResponse: The response for the list method.
|
|
550
|
-
|
|
551
|
-
Usage:
|
|
552
|
-
|
|
553
|
-
.. code-block:: python
|
|
554
|
-
|
|
555
|
-
pager = client.files.list(config={'page_size': 10})
|
|
556
|
-
for file in pager.page:
|
|
557
|
-
print(file.name)
|
|
558
|
-
"""
|
|
559
|
-
|
|
560
157
|
parameter_model = types._ListFilesParameters(
|
|
561
158
|
config=config,
|
|
562
159
|
)
|
|
563
160
|
|
|
564
161
|
request_url_dict: Optional[dict[str, str]]
|
|
565
162
|
if self._api_client.vertexai:
|
|
566
|
-
raise ValueError(
|
|
567
|
-
|
|
568
|
-
request_dict = _ListFilesParameters_to_mldev(
|
|
569
|
-
self._api_client, parameter_model
|
|
163
|
+
raise ValueError(
|
|
164
|
+
'This method is only supported in the Gemini Developer client.'
|
|
570
165
|
)
|
|
166
|
+
else:
|
|
167
|
+
request_dict = _ListFilesParameters_to_mldev(parameter_model)
|
|
571
168
|
request_url_dict = request_dict.get('_url')
|
|
572
169
|
if request_url_dict:
|
|
573
170
|
path = 'files'.format_map(request_url_dict)
|
|
@@ -580,31 +177,29 @@ class Files(_api_module.BaseModule):
|
|
|
580
177
|
# TODO: remove the hack that pops config.
|
|
581
178
|
request_dict.pop('config', None)
|
|
582
179
|
|
|
583
|
-
http_options: Optional[types.
|
|
584
|
-
if
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
180
|
+
http_options: Optional[types.HttpOptions] = None
|
|
181
|
+
if (
|
|
182
|
+
parameter_model.config is not None
|
|
183
|
+
and parameter_model.config.http_options is not None
|
|
184
|
+
):
|
|
185
|
+
http_options = parameter_model.config.http_options
|
|
588
186
|
|
|
589
187
|
request_dict = _common.convert_to_dict(request_dict)
|
|
590
188
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
591
189
|
|
|
592
|
-
|
|
593
|
-
'get', path, request_dict, http_options
|
|
594
|
-
)
|
|
190
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
|
595
191
|
|
|
596
|
-
if
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
)
|
|
600
|
-
else:
|
|
601
|
-
response_dict = _ListFilesResponse_from_mldev(
|
|
602
|
-
self._api_client, response_dict
|
|
603
|
-
)
|
|
192
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
193
|
+
|
|
194
|
+
if not self._api_client.vertexai:
|
|
195
|
+
response_dict = _ListFilesResponse_from_mldev(response_dict)
|
|
604
196
|
|
|
605
197
|
return_value = types.ListFilesResponse._from_response(
|
|
606
198
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
607
199
|
)
|
|
200
|
+
return_value.sdk_http_response = types.HttpResponse(
|
|
201
|
+
headers=response.headers
|
|
202
|
+
)
|
|
608
203
|
self._api_client._verify_response(return_value)
|
|
609
204
|
return return_value
|
|
610
205
|
|
|
@@ -621,11 +216,11 @@ class Files(_api_module.BaseModule):
|
|
|
621
216
|
|
|
622
217
|
request_url_dict: Optional[dict[str, str]]
|
|
623
218
|
if self._api_client.vertexai:
|
|
624
|
-
raise ValueError(
|
|
625
|
-
|
|
626
|
-
request_dict = _CreateFileParameters_to_mldev(
|
|
627
|
-
self._api_client, parameter_model
|
|
219
|
+
raise ValueError(
|
|
220
|
+
'This method is only supported in the Gemini Developer client.'
|
|
628
221
|
)
|
|
222
|
+
else:
|
|
223
|
+
request_dict = _CreateFileParameters_to_mldev(parameter_model)
|
|
629
224
|
request_url_dict = request_dict.get('_url')
|
|
630
225
|
if request_url_dict:
|
|
631
226
|
path = 'upload/v1beta/files'.format_map(request_url_dict)
|
|
@@ -638,31 +233,36 @@ class Files(_api_module.BaseModule):
|
|
|
638
233
|
# TODO: remove the hack that pops config.
|
|
639
234
|
request_dict.pop('config', None)
|
|
640
235
|
|
|
641
|
-
http_options: Optional[types.
|
|
642
|
-
if
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
236
|
+
http_options: Optional[types.HttpOptions] = None
|
|
237
|
+
if (
|
|
238
|
+
parameter_model.config is not None
|
|
239
|
+
and parameter_model.config.http_options is not None
|
|
240
|
+
):
|
|
241
|
+
http_options = parameter_model.config.http_options
|
|
646
242
|
|
|
647
243
|
request_dict = _common.convert_to_dict(request_dict)
|
|
648
244
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
649
245
|
|
|
650
|
-
|
|
246
|
+
response = self._api_client.request(
|
|
651
247
|
'post', path, request_dict, http_options
|
|
652
248
|
)
|
|
653
249
|
|
|
654
|
-
if
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
)
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
250
|
+
if config is not None and getattr(
|
|
251
|
+
config, 'should_return_http_response', None
|
|
252
|
+
):
|
|
253
|
+
return_value = types.CreateFileResponse(sdk_http_response=response)
|
|
254
|
+
self._api_client._verify_response(return_value)
|
|
255
|
+
return return_value
|
|
256
|
+
|
|
257
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
258
|
+
|
|
259
|
+
if not self._api_client.vertexai:
|
|
260
|
+
response_dict = _CreateFileResponse_from_mldev(response_dict)
|
|
662
261
|
|
|
663
262
|
return_value = types.CreateFileResponse._from_response(
|
|
664
263
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
665
264
|
)
|
|
265
|
+
|
|
666
266
|
self._api_client._verify_response(return_value)
|
|
667
267
|
return return_value
|
|
668
268
|
|
|
@@ -693,11 +293,11 @@ class Files(_api_module.BaseModule):
|
|
|
693
293
|
|
|
694
294
|
request_url_dict: Optional[dict[str, str]]
|
|
695
295
|
if self._api_client.vertexai:
|
|
696
|
-
raise ValueError(
|
|
697
|
-
|
|
698
|
-
request_dict = _GetFileParameters_to_mldev(
|
|
699
|
-
self._api_client, parameter_model
|
|
296
|
+
raise ValueError(
|
|
297
|
+
'This method is only supported in the Gemini Developer client.'
|
|
700
298
|
)
|
|
299
|
+
else:
|
|
300
|
+
request_dict = _GetFileParameters_to_mldev(parameter_model)
|
|
701
301
|
request_url_dict = request_dict.get('_url')
|
|
702
302
|
if request_url_dict:
|
|
703
303
|
path = 'files/{file}'.format_map(request_url_dict)
|
|
@@ -710,34 +310,31 @@ class Files(_api_module.BaseModule):
|
|
|
710
310
|
# TODO: remove the hack that pops config.
|
|
711
311
|
request_dict.pop('config', None)
|
|
712
312
|
|
|
713
|
-
http_options: Optional[types.
|
|
714
|
-
if
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
313
|
+
http_options: Optional[types.HttpOptions] = None
|
|
314
|
+
if (
|
|
315
|
+
parameter_model.config is not None
|
|
316
|
+
and parameter_model.config.http_options is not None
|
|
317
|
+
):
|
|
318
|
+
http_options = parameter_model.config.http_options
|
|
718
319
|
|
|
719
320
|
request_dict = _common.convert_to_dict(request_dict)
|
|
720
321
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
721
322
|
|
|
722
|
-
|
|
723
|
-
'get', path, request_dict, http_options
|
|
724
|
-
)
|
|
323
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
|
725
324
|
|
|
726
|
-
if
|
|
727
|
-
response_dict = _File_from_vertex(self._api_client, response_dict)
|
|
728
|
-
else:
|
|
729
|
-
response_dict = _File_from_mldev(self._api_client, response_dict)
|
|
325
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
730
326
|
|
|
731
327
|
return_value = types.File._from_response(
|
|
732
328
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
733
329
|
)
|
|
330
|
+
|
|
734
331
|
self._api_client._verify_response(return_value)
|
|
735
332
|
return return_value
|
|
736
333
|
|
|
737
334
|
def delete(
|
|
738
335
|
self, *, name: str, config: Optional[types.DeleteFileConfigOrDict] = None
|
|
739
336
|
) -> types.DeleteFileResponse:
|
|
740
|
-
"""Deletes
|
|
337
|
+
"""Deletes a remotely stored file.
|
|
741
338
|
|
|
742
339
|
Args:
|
|
743
340
|
name (str): The name identifier for the file to delete.
|
|
@@ -760,11 +357,11 @@ class Files(_api_module.BaseModule):
|
|
|
760
357
|
|
|
761
358
|
request_url_dict: Optional[dict[str, str]]
|
|
762
359
|
if self._api_client.vertexai:
|
|
763
|
-
raise ValueError(
|
|
764
|
-
|
|
765
|
-
request_dict = _DeleteFileParameters_to_mldev(
|
|
766
|
-
self._api_client, parameter_model
|
|
360
|
+
raise ValueError(
|
|
361
|
+
'This method is only supported in the Gemini Developer client.'
|
|
767
362
|
)
|
|
363
|
+
else:
|
|
364
|
+
request_dict = _DeleteFileParameters_to_mldev(parameter_model)
|
|
768
365
|
request_url_dict = request_dict.get('_url')
|
|
769
366
|
if request_url_dict:
|
|
770
367
|
path = 'files/{file}'.format_map(request_url_dict)
|
|
@@ -777,38 +374,66 @@ class Files(_api_module.BaseModule):
|
|
|
777
374
|
# TODO: remove the hack that pops config.
|
|
778
375
|
request_dict.pop('config', None)
|
|
779
376
|
|
|
780
|
-
http_options: Optional[types.
|
|
781
|
-
if
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
377
|
+
http_options: Optional[types.HttpOptions] = None
|
|
378
|
+
if (
|
|
379
|
+
parameter_model.config is not None
|
|
380
|
+
and parameter_model.config.http_options is not None
|
|
381
|
+
):
|
|
382
|
+
http_options = parameter_model.config.http_options
|
|
785
383
|
|
|
786
384
|
request_dict = _common.convert_to_dict(request_dict)
|
|
787
385
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
788
386
|
|
|
789
|
-
|
|
387
|
+
response = self._api_client.request(
|
|
790
388
|
'delete', path, request_dict, http_options
|
|
791
389
|
)
|
|
792
390
|
|
|
793
|
-
if
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
)
|
|
797
|
-
else:
|
|
798
|
-
response_dict = _DeleteFileResponse_from_mldev(
|
|
799
|
-
self._api_client, response_dict
|
|
800
|
-
)
|
|
391
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
392
|
+
|
|
393
|
+
if not self._api_client.vertexai:
|
|
394
|
+
response_dict = _DeleteFileResponse_from_mldev(response_dict)
|
|
801
395
|
|
|
802
396
|
return_value = types.DeleteFileResponse._from_response(
|
|
803
397
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
804
398
|
)
|
|
399
|
+
return_value.sdk_http_response = types.HttpResponse(
|
|
400
|
+
headers=response.headers
|
|
401
|
+
)
|
|
805
402
|
self._api_client._verify_response(return_value)
|
|
806
403
|
return return_value
|
|
807
404
|
|
|
405
|
+
def list(
|
|
406
|
+
self, *, config: Optional[types.ListFilesConfigOrDict] = None
|
|
407
|
+
) -> Pager[types.File]:
|
|
408
|
+
"""Lists all files from the service.
|
|
409
|
+
|
|
410
|
+
Args:
|
|
411
|
+
config (ListFilesConfig): Optional, configuration for the list method.
|
|
412
|
+
|
|
413
|
+
Returns:
|
|
414
|
+
A Pager object that contains one page of files. When iterating over
|
|
415
|
+
the pager, it automatically fetches the next page if there are more.
|
|
416
|
+
|
|
417
|
+
Usage:
|
|
418
|
+
|
|
419
|
+
.. code-block:: python
|
|
420
|
+
|
|
421
|
+
for file in client.files.list(config={'page_size': 10}):
|
|
422
|
+
print(file.name)
|
|
423
|
+
"""
|
|
424
|
+
|
|
425
|
+
list_request = self._list
|
|
426
|
+
return Pager(
|
|
427
|
+
'files',
|
|
428
|
+
list_request,
|
|
429
|
+
self._list(config=config),
|
|
430
|
+
config,
|
|
431
|
+
)
|
|
432
|
+
|
|
808
433
|
def upload(
|
|
809
434
|
self,
|
|
810
435
|
*,
|
|
811
|
-
file: Union[str,
|
|
436
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
|
812
437
|
config: Optional[types.UploadFileConfigOrDict] = None,
|
|
813
438
|
) -> types.File:
|
|
814
439
|
"""Calls the API to upload a file using a supported file service.
|
|
@@ -823,8 +448,7 @@ class Files(_api_module.BaseModule):
|
|
|
823
448
|
"""
|
|
824
449
|
if self._api_client.vertexai:
|
|
825
450
|
raise ValueError(
|
|
826
|
-
'
|
|
827
|
-
' GCS files instead.'
|
|
451
|
+
'This method is only supported in the Gemini Developer client.'
|
|
828
452
|
)
|
|
829
453
|
config_model = types.UploadFileConfig()
|
|
830
454
|
if config:
|
|
@@ -842,84 +466,46 @@ class Files(_api_module.BaseModule):
|
|
|
842
466
|
if file_obj.name is not None and not file_obj.name.startswith('files/'):
|
|
843
467
|
file_obj.name = f'files/{file_obj.name}'
|
|
844
468
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
if 'b' not in file.mode:
|
|
853
|
-
raise ValueError('The file must be opened in binary mode.')
|
|
854
|
-
offset = file.tell()
|
|
855
|
-
file.seek(0, os.SEEK_END)
|
|
856
|
-
file_obj.size_bytes = file.tell() - offset
|
|
857
|
-
file.seek(offset, os.SEEK_SET)
|
|
858
|
-
else:
|
|
859
|
-
fs_path = os.fspath(file)
|
|
860
|
-
if not fs_path or not os.path.isfile(fs_path):
|
|
861
|
-
raise FileNotFoundError(f'{file} is not a valid file path.')
|
|
862
|
-
file_obj.size_bytes = os.path.getsize(fs_path)
|
|
863
|
-
if file_obj.mime_type is None:
|
|
864
|
-
file_obj.mime_type, _ = mimetypes.guess_type(fs_path)
|
|
865
|
-
if file_obj.mime_type is None:
|
|
866
|
-
raise ValueError(
|
|
867
|
-
'Unknown mime type: Could not determine the mimetype for your'
|
|
868
|
-
' file\n please set the `mime_type` argument'
|
|
869
|
-
)
|
|
870
|
-
|
|
871
|
-
http_options: types.HttpOptions
|
|
872
|
-
if config_model and config_model.http_options:
|
|
873
|
-
http_options = config_model.http_options
|
|
874
|
-
else:
|
|
875
|
-
http_options = types.HttpOptions(
|
|
876
|
-
api_version='',
|
|
877
|
-
headers={
|
|
878
|
-
'Content-Type': 'application/json',
|
|
879
|
-
'X-Goog-Upload-Protocol': 'resumable',
|
|
880
|
-
'X-Goog-Upload-Command': 'start',
|
|
881
|
-
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
|
882
|
-
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
|
883
|
-
},
|
|
884
|
-
)
|
|
469
|
+
http_options, size_bytes, mime_type = _extra_utils.prepare_resumable_upload(
|
|
470
|
+
file,
|
|
471
|
+
user_http_options=config_model.http_options,
|
|
472
|
+
user_mime_type=config_model.mime_type,
|
|
473
|
+
)
|
|
474
|
+
file_obj.size_bytes = size_bytes
|
|
475
|
+
file_obj.mime_type = mime_type
|
|
885
476
|
response = self._create(
|
|
886
|
-
file=file_obj,
|
|
477
|
+
file=file_obj,
|
|
478
|
+
config=types.CreateFileConfig(
|
|
479
|
+
http_options=http_options, should_return_http_response=True
|
|
480
|
+
),
|
|
887
481
|
)
|
|
888
482
|
|
|
889
483
|
if (
|
|
890
|
-
response.
|
|
891
|
-
or
|
|
484
|
+
response.sdk_http_response is None
|
|
485
|
+
or response.sdk_http_response.headers is None
|
|
486
|
+
or 'x-goog-upload-url' not in response.sdk_http_response.headers
|
|
892
487
|
):
|
|
893
488
|
raise KeyError(
|
|
894
489
|
'Failed to create file. Upload URL did not returned from the create'
|
|
895
490
|
' file request.'
|
|
896
491
|
)
|
|
897
|
-
upload_url = response.
|
|
492
|
+
upload_url = response.sdk_http_response.headers['x-goog-upload-url']
|
|
898
493
|
|
|
899
494
|
if isinstance(file, io.IOBase):
|
|
900
495
|
return_file = self._api_client.upload_file(
|
|
901
|
-
file, upload_url, file_obj.size_bytes
|
|
496
|
+
file, upload_url, file_obj.size_bytes, http_options=http_options
|
|
902
497
|
)
|
|
903
498
|
else:
|
|
499
|
+
fs_path = os.fspath(file)
|
|
904
500
|
return_file = self._api_client.upload_file(
|
|
905
|
-
fs_path, upload_url, file_obj.size_bytes
|
|
501
|
+
fs_path, upload_url, file_obj.size_bytes, http_options=http_options
|
|
906
502
|
)
|
|
907
503
|
|
|
908
504
|
return types.File._from_response(
|
|
909
|
-
response=
|
|
505
|
+
response=return_file.json['file'],
|
|
910
506
|
kwargs=config_model.model_dump() if config else {},
|
|
911
507
|
)
|
|
912
508
|
|
|
913
|
-
def list(
|
|
914
|
-
self, *, config: Optional[types.ListFilesConfigOrDict] = None
|
|
915
|
-
) -> Pager[types.File]:
|
|
916
|
-
return Pager(
|
|
917
|
-
'files',
|
|
918
|
-
self._list,
|
|
919
|
-
self._list(config=config),
|
|
920
|
-
config,
|
|
921
|
-
)
|
|
922
|
-
|
|
923
509
|
def download(
|
|
924
510
|
self,
|
|
925
511
|
*,
|
|
@@ -963,7 +549,7 @@ class Files(_api_module.BaseModule):
|
|
|
963
549
|
"""
|
|
964
550
|
if self._api_client.vertexai:
|
|
965
551
|
raise ValueError(
|
|
966
|
-
'
|
|
552
|
+
'This method is only supported in the Gemini Developer client.'
|
|
967
553
|
)
|
|
968
554
|
|
|
969
555
|
config_model = None
|
|
@@ -979,7 +565,7 @@ class Files(_api_module.BaseModule):
|
|
|
979
565
|
'downloaded. You can tell which files are downloadable by checking '
|
|
980
566
|
'the `source` or `download_uri` property.'
|
|
981
567
|
)
|
|
982
|
-
name = t.t_file_name(
|
|
568
|
+
name = t.t_file_name(file)
|
|
983
569
|
|
|
984
570
|
path = f'files/{name}:download'
|
|
985
571
|
|
|
@@ -991,7 +577,7 @@ class Files(_api_module.BaseModule):
|
|
|
991
577
|
|
|
992
578
|
data = self._api_client.download_file(
|
|
993
579
|
path,
|
|
994
|
-
http_options,
|
|
580
|
+
http_options=http_options,
|
|
995
581
|
)
|
|
996
582
|
|
|
997
583
|
if isinstance(file, types.Video):
|
|
@@ -1007,34 +593,17 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1007
593
|
async def _list(
|
|
1008
594
|
self, *, config: Optional[types.ListFilesConfigOrDict] = None
|
|
1009
595
|
) -> types.ListFilesResponse:
|
|
1010
|
-
"""Lists all files from the service.
|
|
1011
|
-
|
|
1012
|
-
Args:
|
|
1013
|
-
config (ListFilesConfig): Optional, configuration for the list method.
|
|
1014
|
-
|
|
1015
|
-
Returns:
|
|
1016
|
-
ListFilesResponse: The response for the list method.
|
|
1017
|
-
|
|
1018
|
-
Usage:
|
|
1019
|
-
|
|
1020
|
-
.. code-block:: python
|
|
1021
|
-
|
|
1022
|
-
pager = await client.aio.files.list(config={'page_size': 10})
|
|
1023
|
-
for file in pager.page:
|
|
1024
|
-
print(file.name)
|
|
1025
|
-
"""
|
|
1026
|
-
|
|
1027
596
|
parameter_model = types._ListFilesParameters(
|
|
1028
597
|
config=config,
|
|
1029
598
|
)
|
|
1030
599
|
|
|
1031
600
|
request_url_dict: Optional[dict[str, str]]
|
|
1032
601
|
if self._api_client.vertexai:
|
|
1033
|
-
raise ValueError(
|
|
1034
|
-
|
|
1035
|
-
request_dict = _ListFilesParameters_to_mldev(
|
|
1036
|
-
self._api_client, parameter_model
|
|
602
|
+
raise ValueError(
|
|
603
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1037
604
|
)
|
|
605
|
+
else:
|
|
606
|
+
request_dict = _ListFilesParameters_to_mldev(parameter_model)
|
|
1038
607
|
request_url_dict = request_dict.get('_url')
|
|
1039
608
|
if request_url_dict:
|
|
1040
609
|
path = 'files'.format_map(request_url_dict)
|
|
@@ -1047,31 +616,31 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1047
616
|
# TODO: remove the hack that pops config.
|
|
1048
617
|
request_dict.pop('config', None)
|
|
1049
618
|
|
|
1050
|
-
http_options: Optional[types.
|
|
1051
|
-
if
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
619
|
+
http_options: Optional[types.HttpOptions] = None
|
|
620
|
+
if (
|
|
621
|
+
parameter_model.config is not None
|
|
622
|
+
and parameter_model.config.http_options is not None
|
|
623
|
+
):
|
|
624
|
+
http_options = parameter_model.config.http_options
|
|
1055
625
|
|
|
1056
626
|
request_dict = _common.convert_to_dict(request_dict)
|
|
1057
627
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1058
628
|
|
|
1059
|
-
|
|
629
|
+
response = await self._api_client.async_request(
|
|
1060
630
|
'get', path, request_dict, http_options
|
|
1061
631
|
)
|
|
1062
632
|
|
|
1063
|
-
if
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
)
|
|
1067
|
-
else:
|
|
1068
|
-
response_dict = _ListFilesResponse_from_mldev(
|
|
1069
|
-
self._api_client, response_dict
|
|
1070
|
-
)
|
|
633
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
634
|
+
|
|
635
|
+
if not self._api_client.vertexai:
|
|
636
|
+
response_dict = _ListFilesResponse_from_mldev(response_dict)
|
|
1071
637
|
|
|
1072
638
|
return_value = types.ListFilesResponse._from_response(
|
|
1073
639
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1074
640
|
)
|
|
641
|
+
return_value.sdk_http_response = types.HttpResponse(
|
|
642
|
+
headers=response.headers
|
|
643
|
+
)
|
|
1075
644
|
self._api_client._verify_response(return_value)
|
|
1076
645
|
return return_value
|
|
1077
646
|
|
|
@@ -1088,11 +657,11 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1088
657
|
|
|
1089
658
|
request_url_dict: Optional[dict[str, str]]
|
|
1090
659
|
if self._api_client.vertexai:
|
|
1091
|
-
raise ValueError(
|
|
1092
|
-
|
|
1093
|
-
request_dict = _CreateFileParameters_to_mldev(
|
|
1094
|
-
self._api_client, parameter_model
|
|
660
|
+
raise ValueError(
|
|
661
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1095
662
|
)
|
|
663
|
+
else:
|
|
664
|
+
request_dict = _CreateFileParameters_to_mldev(parameter_model)
|
|
1096
665
|
request_url_dict = request_dict.get('_url')
|
|
1097
666
|
if request_url_dict:
|
|
1098
667
|
path = 'upload/v1beta/files'.format_map(request_url_dict)
|
|
@@ -1105,31 +674,36 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1105
674
|
# TODO: remove the hack that pops config.
|
|
1106
675
|
request_dict.pop('config', None)
|
|
1107
676
|
|
|
1108
|
-
http_options: Optional[types.
|
|
1109
|
-
if
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
677
|
+
http_options: Optional[types.HttpOptions] = None
|
|
678
|
+
if (
|
|
679
|
+
parameter_model.config is not None
|
|
680
|
+
and parameter_model.config.http_options is not None
|
|
681
|
+
):
|
|
682
|
+
http_options = parameter_model.config.http_options
|
|
1113
683
|
|
|
1114
684
|
request_dict = _common.convert_to_dict(request_dict)
|
|
1115
685
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1116
686
|
|
|
1117
|
-
|
|
687
|
+
response = await self._api_client.async_request(
|
|
1118
688
|
'post', path, request_dict, http_options
|
|
1119
689
|
)
|
|
1120
690
|
|
|
1121
|
-
if
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
)
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
691
|
+
if config is not None and getattr(
|
|
692
|
+
config, 'should_return_http_response', None
|
|
693
|
+
):
|
|
694
|
+
return_value = types.CreateFileResponse(sdk_http_response=response)
|
|
695
|
+
self._api_client._verify_response(return_value)
|
|
696
|
+
return return_value
|
|
697
|
+
|
|
698
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
699
|
+
|
|
700
|
+
if not self._api_client.vertexai:
|
|
701
|
+
response_dict = _CreateFileResponse_from_mldev(response_dict)
|
|
1129
702
|
|
|
1130
703
|
return_value = types.CreateFileResponse._from_response(
|
|
1131
704
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1132
705
|
)
|
|
706
|
+
|
|
1133
707
|
self._api_client._verify_response(return_value)
|
|
1134
708
|
return return_value
|
|
1135
709
|
|
|
@@ -1160,11 +734,11 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1160
734
|
|
|
1161
735
|
request_url_dict: Optional[dict[str, str]]
|
|
1162
736
|
if self._api_client.vertexai:
|
|
1163
|
-
raise ValueError(
|
|
1164
|
-
|
|
1165
|
-
request_dict = _GetFileParameters_to_mldev(
|
|
1166
|
-
self._api_client, parameter_model
|
|
737
|
+
raise ValueError(
|
|
738
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1167
739
|
)
|
|
740
|
+
else:
|
|
741
|
+
request_dict = _GetFileParameters_to_mldev(parameter_model)
|
|
1168
742
|
request_url_dict = request_dict.get('_url')
|
|
1169
743
|
if request_url_dict:
|
|
1170
744
|
path = 'files/{file}'.format_map(request_url_dict)
|
|
@@ -1177,34 +751,33 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1177
751
|
# TODO: remove the hack that pops config.
|
|
1178
752
|
request_dict.pop('config', None)
|
|
1179
753
|
|
|
1180
|
-
http_options: Optional[types.
|
|
1181
|
-
if
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
754
|
+
http_options: Optional[types.HttpOptions] = None
|
|
755
|
+
if (
|
|
756
|
+
parameter_model.config is not None
|
|
757
|
+
and parameter_model.config.http_options is not None
|
|
758
|
+
):
|
|
759
|
+
http_options = parameter_model.config.http_options
|
|
1185
760
|
|
|
1186
761
|
request_dict = _common.convert_to_dict(request_dict)
|
|
1187
762
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1188
763
|
|
|
1189
|
-
|
|
764
|
+
response = await self._api_client.async_request(
|
|
1190
765
|
'get', path, request_dict, http_options
|
|
1191
766
|
)
|
|
1192
767
|
|
|
1193
|
-
if
|
|
1194
|
-
response_dict = _File_from_vertex(self._api_client, response_dict)
|
|
1195
|
-
else:
|
|
1196
|
-
response_dict = _File_from_mldev(self._api_client, response_dict)
|
|
768
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1197
769
|
|
|
1198
770
|
return_value = types.File._from_response(
|
|
1199
771
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1200
772
|
)
|
|
773
|
+
|
|
1201
774
|
self._api_client._verify_response(return_value)
|
|
1202
775
|
return return_value
|
|
1203
776
|
|
|
1204
777
|
async def delete(
|
|
1205
778
|
self, *, name: str, config: Optional[types.DeleteFileConfigOrDict] = None
|
|
1206
779
|
) -> types.DeleteFileResponse:
|
|
1207
|
-
"""Deletes
|
|
780
|
+
"""Deletes a remotely stored file.
|
|
1208
781
|
|
|
1209
782
|
Args:
|
|
1210
783
|
name (str): The name identifier for the file to delete.
|
|
@@ -1227,11 +800,11 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1227
800
|
|
|
1228
801
|
request_url_dict: Optional[dict[str, str]]
|
|
1229
802
|
if self._api_client.vertexai:
|
|
1230
|
-
raise ValueError(
|
|
1231
|
-
|
|
1232
|
-
request_dict = _DeleteFileParameters_to_mldev(
|
|
1233
|
-
self._api_client, parameter_model
|
|
803
|
+
raise ValueError(
|
|
804
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1234
805
|
)
|
|
806
|
+
else:
|
|
807
|
+
request_dict = _DeleteFileParameters_to_mldev(parameter_model)
|
|
1235
808
|
request_url_dict = request_dict.get('_url')
|
|
1236
809
|
if request_url_dict:
|
|
1237
810
|
path = 'files/{file}'.format_map(request_url_dict)
|
|
@@ -1244,38 +817,66 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1244
817
|
# TODO: remove the hack that pops config.
|
|
1245
818
|
request_dict.pop('config', None)
|
|
1246
819
|
|
|
1247
|
-
http_options: Optional[types.
|
|
1248
|
-
if
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
820
|
+
http_options: Optional[types.HttpOptions] = None
|
|
821
|
+
if (
|
|
822
|
+
parameter_model.config is not None
|
|
823
|
+
and parameter_model.config.http_options is not None
|
|
824
|
+
):
|
|
825
|
+
http_options = parameter_model.config.http_options
|
|
1252
826
|
|
|
1253
827
|
request_dict = _common.convert_to_dict(request_dict)
|
|
1254
828
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1255
829
|
|
|
1256
|
-
|
|
830
|
+
response = await self._api_client.async_request(
|
|
1257
831
|
'delete', path, request_dict, http_options
|
|
1258
832
|
)
|
|
1259
833
|
|
|
1260
|
-
if
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
)
|
|
1264
|
-
else:
|
|
1265
|
-
response_dict = _DeleteFileResponse_from_mldev(
|
|
1266
|
-
self._api_client, response_dict
|
|
1267
|
-
)
|
|
834
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
835
|
+
|
|
836
|
+
if not self._api_client.vertexai:
|
|
837
|
+
response_dict = _DeleteFileResponse_from_mldev(response_dict)
|
|
1268
838
|
|
|
1269
839
|
return_value = types.DeleteFileResponse._from_response(
|
|
1270
840
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1271
841
|
)
|
|
842
|
+
return_value.sdk_http_response = types.HttpResponse(
|
|
843
|
+
headers=response.headers
|
|
844
|
+
)
|
|
1272
845
|
self._api_client._verify_response(return_value)
|
|
1273
846
|
return return_value
|
|
1274
847
|
|
|
848
|
+
async def list(
|
|
849
|
+
self, *, config: Optional[types.ListFilesConfigOrDict] = None
|
|
850
|
+
) -> AsyncPager[types.File]:
|
|
851
|
+
"""Lists all files from the service asynchronously.
|
|
852
|
+
|
|
853
|
+
Args:
|
|
854
|
+
config (ListFilesConfig): Optional, configuration for the list method.
|
|
855
|
+
|
|
856
|
+
Returns:
|
|
857
|
+
A Pager object that contains one page of files. When iterating over
|
|
858
|
+
the pager, it automatically fetches the next page if there are more.
|
|
859
|
+
|
|
860
|
+
Usage:
|
|
861
|
+
|
|
862
|
+
.. code-block:: python
|
|
863
|
+
|
|
864
|
+
async for file in await client.aio.files.list(config={'page_size': 10}):
|
|
865
|
+
print(file.name)
|
|
866
|
+
"""
|
|
867
|
+
|
|
868
|
+
list_request = self._list
|
|
869
|
+
return AsyncPager(
|
|
870
|
+
'files',
|
|
871
|
+
list_request,
|
|
872
|
+
await self._list(config=config),
|
|
873
|
+
config,
|
|
874
|
+
)
|
|
875
|
+
|
|
1275
876
|
async def upload(
|
|
1276
877
|
self,
|
|
1277
878
|
*,
|
|
1278
|
-
file: Union[str,
|
|
879
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
|
1279
880
|
config: Optional[types.UploadFileConfigOrDict] = None,
|
|
1280
881
|
) -> types.File:
|
|
1281
882
|
"""Calls the API to upload a file asynchronously using a supported file service.
|
|
@@ -1290,8 +891,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1290
891
|
"""
|
|
1291
892
|
if self._api_client.vertexai:
|
|
1292
893
|
raise ValueError(
|
|
1293
|
-
'
|
|
1294
|
-
' GCS files instead.'
|
|
894
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1295
895
|
)
|
|
1296
896
|
config_model = types.UploadFileConfig()
|
|
1297
897
|
if config:
|
|
@@ -1309,83 +909,51 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1309
909
|
if file_obj.name is not None and not file_obj.name.startswith('files/'):
|
|
1310
910
|
file_obj.name = f'files/{file_obj.name}'
|
|
1311
911
|
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
if 'b' not in file.mode:
|
|
1320
|
-
raise ValueError('The file must be opened in binary mode.')
|
|
1321
|
-
offset = file.tell()
|
|
1322
|
-
file.seek(0, os.SEEK_END)
|
|
1323
|
-
file_obj.size_bytes = file.tell() - offset
|
|
1324
|
-
file.seek(offset, os.SEEK_SET)
|
|
1325
|
-
else:
|
|
1326
|
-
fs_path = os.fspath(file)
|
|
1327
|
-
if not fs_path or not os.path.isfile(fs_path):
|
|
1328
|
-
raise FileNotFoundError(f'{file} is not a valid file path.')
|
|
1329
|
-
file_obj.size_bytes = os.path.getsize(fs_path)
|
|
1330
|
-
if file_obj.mime_type is None:
|
|
1331
|
-
file_obj.mime_type, _ = mimetypes.guess_type(fs_path)
|
|
1332
|
-
if file_obj.mime_type is None:
|
|
1333
|
-
raise ValueError(
|
|
1334
|
-
'Unknown mime type: Could not determine the mimetype for your'
|
|
1335
|
-
' file\n please set the `mime_type` argument'
|
|
1336
|
-
)
|
|
1337
|
-
|
|
1338
|
-
http_options: types.HttpOptions
|
|
1339
|
-
if config_model and config_model.http_options:
|
|
1340
|
-
http_options = config_model.http_options
|
|
1341
|
-
else:
|
|
1342
|
-
http_options = types.HttpOptions(
|
|
1343
|
-
api_version='',
|
|
1344
|
-
headers={
|
|
1345
|
-
'Content-Type': 'application/json',
|
|
1346
|
-
'X-Goog-Upload-Protocol': 'resumable',
|
|
1347
|
-
'X-Goog-Upload-Command': 'start',
|
|
1348
|
-
'X-Goog-Upload-Header-Content-Length': f'{file_obj.size_bytes}',
|
|
1349
|
-
'X-Goog-Upload-Header-Content-Type': f'{file_obj.mime_type}',
|
|
1350
|
-
},
|
|
1351
|
-
)
|
|
912
|
+
http_options, size_bytes, mime_type = _extra_utils.prepare_resumable_upload(
|
|
913
|
+
file,
|
|
914
|
+
user_http_options=config_model.http_options,
|
|
915
|
+
user_mime_type=config_model.mime_type,
|
|
916
|
+
)
|
|
917
|
+
file_obj.size_bytes = size_bytes
|
|
918
|
+
file_obj.mime_type = mime_type
|
|
1352
919
|
response = await self._create(
|
|
1353
|
-
file=file_obj,
|
|
920
|
+
file=file_obj,
|
|
921
|
+
config=types.CreateFileConfig(
|
|
922
|
+
http_options=http_options, should_return_http_response=True
|
|
923
|
+
),
|
|
1354
924
|
)
|
|
1355
925
|
if (
|
|
1356
|
-
response.
|
|
1357
|
-
or
|
|
926
|
+
response.sdk_http_response is None
|
|
927
|
+
or response.sdk_http_response.headers is None
|
|
928
|
+
or (
|
|
929
|
+
'x-goog-upload-url' not in response.sdk_http_response.headers
|
|
930
|
+
and 'X-Goog-Upload-URL' not in response.sdk_http_response.headers
|
|
931
|
+
)
|
|
1358
932
|
):
|
|
1359
933
|
raise KeyError(
|
|
1360
934
|
'Failed to create file. Upload URL did not returned from the create'
|
|
1361
935
|
' file request.'
|
|
1362
936
|
)
|
|
1363
|
-
|
|
937
|
+
elif 'x-goog-upload-url' in response.sdk_http_response.headers:
|
|
938
|
+
upload_url = response.sdk_http_response.headers['x-goog-upload-url']
|
|
939
|
+
else:
|
|
940
|
+
upload_url = response.sdk_http_response.headers['X-Goog-Upload-URL']
|
|
1364
941
|
|
|
1365
942
|
if isinstance(file, io.IOBase):
|
|
1366
943
|
return_file = await self._api_client.async_upload_file(
|
|
1367
|
-
file, upload_url, file_obj.size_bytes
|
|
944
|
+
file, upload_url, file_obj.size_bytes, http_options=http_options
|
|
1368
945
|
)
|
|
1369
946
|
else:
|
|
947
|
+
fs_path = os.fspath(file)
|
|
1370
948
|
return_file = await self._api_client.async_upload_file(
|
|
1371
|
-
fs_path, upload_url, file_obj.size_bytes
|
|
949
|
+
fs_path, upload_url, file_obj.size_bytes, http_options=http_options
|
|
1372
950
|
)
|
|
1373
951
|
|
|
1374
952
|
return types.File._from_response(
|
|
1375
|
-
response=
|
|
953
|
+
response=return_file.json['file'],
|
|
1376
954
|
kwargs=config_model.model_dump() if config else {},
|
|
1377
955
|
)
|
|
1378
956
|
|
|
1379
|
-
async def list(
|
|
1380
|
-
self, *, config: Optional[types.ListFilesConfigOrDict] = None
|
|
1381
|
-
) -> AsyncPager[types.File]:
|
|
1382
|
-
return AsyncPager(
|
|
1383
|
-
'files',
|
|
1384
|
-
self._list,
|
|
1385
|
-
await self._list(config=config),
|
|
1386
|
-
config,
|
|
1387
|
-
)
|
|
1388
|
-
|
|
1389
957
|
async def download(
|
|
1390
958
|
self,
|
|
1391
959
|
*,
|
|
@@ -1423,7 +991,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1423
991
|
"""
|
|
1424
992
|
if self._api_client.vertexai:
|
|
1425
993
|
raise ValueError(
|
|
1426
|
-
'
|
|
994
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1427
995
|
)
|
|
1428
996
|
|
|
1429
997
|
config_model = None
|
|
@@ -1433,7 +1001,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1433
1001
|
else:
|
|
1434
1002
|
config_model = config
|
|
1435
1003
|
|
|
1436
|
-
name = t.t_file_name(
|
|
1004
|
+
name = t.t_file_name(file)
|
|
1437
1005
|
|
|
1438
1006
|
path = f'files/{name}:download'
|
|
1439
1007
|
|
|
@@ -1447,7 +1015,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
|
1447
1015
|
|
|
1448
1016
|
data = await self._api_client.async_download_file(
|
|
1449
1017
|
path,
|
|
1450
|
-
http_options,
|
|
1018
|
+
http_options=http_options,
|
|
1451
1019
|
)
|
|
1452
1020
|
|
|
1453
1021
|
return data
|