google-genai 1.47.0__py3-none-any.whl → 1.49.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 +5 -1
- google/genai/_extra_utils.py +36 -3
- google/genai/_live_converters.py +28 -17
- google/genai/_operations_converters.py +96 -0
- google/genai/_replay_api_client.py +24 -39
- google/genai/_tokens_converters.py +15 -7
- google/genai/batches.py +20 -7
- google/genai/caches.py +21 -10
- google/genai/client.py +11 -0
- google/genai/documents.py +549 -0
- google/genai/errors.py +1 -1
- google/genai/file_search_stores.py +1312 -0
- google/genai/models.py +139 -23
- google/genai/pagers.py +7 -1
- google/genai/tunings.py +313 -2
- google/genai/types.py +1705 -393
- google/genai/version.py +1 -1
- {google_genai-1.47.0.dist-info → google_genai-1.49.0.dist-info}/METADATA +2 -3
- google_genai-1.49.0.dist-info/RECORD +41 -0
- google_genai-1.47.0.dist-info/RECORD +0 -39
- {google_genai-1.47.0.dist-info → google_genai-1.49.0.dist-info}/WHEEL +0 -0
- {google_genai-1.47.0.dist-info → google_genai-1.49.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.47.0.dist-info → google_genai-1.49.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,1312 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
17
|
+
|
|
18
|
+
from functools import cached_property
|
|
19
|
+
import io
|
|
20
|
+
import json
|
|
21
|
+
import logging
|
|
22
|
+
import os
|
|
23
|
+
from typing import Any, Optional, Union
|
|
24
|
+
from urllib.parse import urlencode
|
|
25
|
+
|
|
26
|
+
from . import _api_module
|
|
27
|
+
from . import _common
|
|
28
|
+
from . import _extra_utils
|
|
29
|
+
from . import types
|
|
30
|
+
from ._common import get_value_by_path as getv
|
|
31
|
+
from ._common import set_value_by_path as setv
|
|
32
|
+
from ._operations_converters import _UploadToFileSearchStoreOperation_from_mldev
|
|
33
|
+
from .documents import AsyncDocuments, Documents
|
|
34
|
+
from .pagers import AsyncPager, Pager
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger('google_genai.filesearchstores')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _CreateFileSearchStoreConfig_to_mldev(
|
|
41
|
+
from_object: Union[dict[str, Any], object],
|
|
42
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
43
|
+
) -> dict[str, Any]:
|
|
44
|
+
to_object: dict[str, Any] = {}
|
|
45
|
+
|
|
46
|
+
if getv(from_object, ['display_name']) is not None:
|
|
47
|
+
setv(parent_object, ['displayName'], getv(from_object, ['display_name']))
|
|
48
|
+
|
|
49
|
+
return to_object
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _CreateFileSearchStoreParameters_to_mldev(
|
|
53
|
+
from_object: Union[dict[str, Any], object],
|
|
54
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
55
|
+
) -> dict[str, Any]:
|
|
56
|
+
to_object: dict[str, Any] = {}
|
|
57
|
+
if getv(from_object, ['config']) is not None:
|
|
58
|
+
_CreateFileSearchStoreConfig_to_mldev(
|
|
59
|
+
getv(from_object, ['config']), to_object
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return to_object
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _DeleteFileSearchStoreConfig_to_mldev(
|
|
66
|
+
from_object: Union[dict[str, Any], object],
|
|
67
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
68
|
+
) -> dict[str, Any]:
|
|
69
|
+
to_object: dict[str, Any] = {}
|
|
70
|
+
|
|
71
|
+
if getv(from_object, ['force']) is not None:
|
|
72
|
+
setv(parent_object, ['_query', 'force'], getv(from_object, ['force']))
|
|
73
|
+
|
|
74
|
+
return to_object
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _DeleteFileSearchStoreParameters_to_mldev(
|
|
78
|
+
from_object: Union[dict[str, Any], object],
|
|
79
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
80
|
+
) -> dict[str, Any]:
|
|
81
|
+
to_object: dict[str, Any] = {}
|
|
82
|
+
if getv(from_object, ['name']) is not None:
|
|
83
|
+
setv(to_object, ['_url', 'name'], getv(from_object, ['name']))
|
|
84
|
+
|
|
85
|
+
if getv(from_object, ['config']) is not None:
|
|
86
|
+
_DeleteFileSearchStoreConfig_to_mldev(
|
|
87
|
+
getv(from_object, ['config']), to_object
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return to_object
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _GetFileSearchStoreParameters_to_mldev(
|
|
94
|
+
from_object: Union[dict[str, Any], object],
|
|
95
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
96
|
+
) -> dict[str, Any]:
|
|
97
|
+
to_object: dict[str, Any] = {}
|
|
98
|
+
if getv(from_object, ['name']) is not None:
|
|
99
|
+
setv(to_object, ['_url', 'name'], getv(from_object, ['name']))
|
|
100
|
+
|
|
101
|
+
return to_object
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _ImportFileConfig_to_mldev(
|
|
105
|
+
from_object: Union[dict[str, Any], object],
|
|
106
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
107
|
+
) -> dict[str, Any]:
|
|
108
|
+
to_object: dict[str, Any] = {}
|
|
109
|
+
|
|
110
|
+
if getv(from_object, ['custom_metadata']) is not None:
|
|
111
|
+
setv(
|
|
112
|
+
parent_object,
|
|
113
|
+
['customMetadata'],
|
|
114
|
+
[item for item in getv(from_object, ['custom_metadata'])],
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
if getv(from_object, ['chunking_config']) is not None:
|
|
118
|
+
setv(
|
|
119
|
+
parent_object,
|
|
120
|
+
['chunkingConfig'],
|
|
121
|
+
getv(from_object, ['chunking_config']),
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return to_object
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _ImportFileOperation_from_mldev(
|
|
128
|
+
from_object: Union[dict[str, Any], object],
|
|
129
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
130
|
+
) -> dict[str, Any]:
|
|
131
|
+
to_object: dict[str, Any] = {}
|
|
132
|
+
if getv(from_object, ['name']) is not None:
|
|
133
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
|
134
|
+
|
|
135
|
+
if getv(from_object, ['metadata']) is not None:
|
|
136
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
|
137
|
+
|
|
138
|
+
if getv(from_object, ['done']) is not None:
|
|
139
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
|
140
|
+
|
|
141
|
+
if getv(from_object, ['error']) is not None:
|
|
142
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
|
143
|
+
|
|
144
|
+
if getv(from_object, ['response']) is not None:
|
|
145
|
+
setv(
|
|
146
|
+
to_object,
|
|
147
|
+
['response'],
|
|
148
|
+
_ImportFileResponse_from_mldev(
|
|
149
|
+
getv(from_object, ['response']), to_object
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
return to_object
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _ImportFileParameters_to_mldev(
|
|
157
|
+
from_object: Union[dict[str, Any], object],
|
|
158
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
159
|
+
) -> dict[str, Any]:
|
|
160
|
+
to_object: dict[str, Any] = {}
|
|
161
|
+
if getv(from_object, ['file_search_store_name']) is not None:
|
|
162
|
+
setv(
|
|
163
|
+
to_object,
|
|
164
|
+
['_url', 'file_search_store_name'],
|
|
165
|
+
getv(from_object, ['file_search_store_name']),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
if getv(from_object, ['file_name']) is not None:
|
|
169
|
+
setv(to_object, ['fileName'], getv(from_object, ['file_name']))
|
|
170
|
+
|
|
171
|
+
if getv(from_object, ['config']) is not None:
|
|
172
|
+
_ImportFileConfig_to_mldev(getv(from_object, ['config']), to_object)
|
|
173
|
+
|
|
174
|
+
return to_object
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _ImportFileResponse_from_mldev(
|
|
178
|
+
from_object: Union[dict[str, Any], object],
|
|
179
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
180
|
+
) -> dict[str, Any]:
|
|
181
|
+
to_object: dict[str, Any] = {}
|
|
182
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
183
|
+
setv(
|
|
184
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
if getv(from_object, ['parent']) is not None:
|
|
188
|
+
setv(to_object, ['parent'], getv(from_object, ['parent']))
|
|
189
|
+
|
|
190
|
+
if getv(from_object, ['documentName']) is not None:
|
|
191
|
+
setv(to_object, ['document_name'], getv(from_object, ['documentName']))
|
|
192
|
+
|
|
193
|
+
return to_object
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _ListFileSearchStoresConfig_to_mldev(
|
|
197
|
+
from_object: Union[dict[str, Any], object],
|
|
198
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
199
|
+
) -> dict[str, Any]:
|
|
200
|
+
to_object: dict[str, Any] = {}
|
|
201
|
+
|
|
202
|
+
if getv(from_object, ['page_size']) is not None:
|
|
203
|
+
setv(
|
|
204
|
+
parent_object, ['_query', 'pageSize'], getv(from_object, ['page_size'])
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
if getv(from_object, ['page_token']) is not None:
|
|
208
|
+
setv(
|
|
209
|
+
parent_object,
|
|
210
|
+
['_query', 'pageToken'],
|
|
211
|
+
getv(from_object, ['page_token']),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
return to_object
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _ListFileSearchStoresParameters_to_mldev(
|
|
218
|
+
from_object: Union[dict[str, Any], object],
|
|
219
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
220
|
+
) -> dict[str, Any]:
|
|
221
|
+
to_object: dict[str, Any] = {}
|
|
222
|
+
if getv(from_object, ['config']) is not None:
|
|
223
|
+
_ListFileSearchStoresConfig_to_mldev(
|
|
224
|
+
getv(from_object, ['config']), to_object
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
return to_object
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _ListFileSearchStoresResponse_from_mldev(
|
|
231
|
+
from_object: Union[dict[str, Any], object],
|
|
232
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
233
|
+
) -> dict[str, Any]:
|
|
234
|
+
to_object: dict[str, Any] = {}
|
|
235
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
236
|
+
setv(
|
|
237
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
if getv(from_object, ['nextPageToken']) is not None:
|
|
241
|
+
setv(to_object, ['next_page_token'], getv(from_object, ['nextPageToken']))
|
|
242
|
+
|
|
243
|
+
if getv(from_object, ['fileSearchStores']) is not None:
|
|
244
|
+
setv(
|
|
245
|
+
to_object,
|
|
246
|
+
['file_search_stores'],
|
|
247
|
+
[item for item in getv(from_object, ['fileSearchStores'])],
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
return to_object
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _UploadToFileSearchStoreConfig_to_mldev(
|
|
254
|
+
from_object: Union[dict[str, Any], object],
|
|
255
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
256
|
+
) -> dict[str, Any]:
|
|
257
|
+
to_object: dict[str, Any] = {}
|
|
258
|
+
|
|
259
|
+
if getv(from_object, ['mime_type']) is not None:
|
|
260
|
+
setv(parent_object, ['mimeType'], getv(from_object, ['mime_type']))
|
|
261
|
+
|
|
262
|
+
if getv(from_object, ['display_name']) is not None:
|
|
263
|
+
setv(parent_object, ['displayName'], getv(from_object, ['display_name']))
|
|
264
|
+
|
|
265
|
+
if getv(from_object, ['custom_metadata']) is not None:
|
|
266
|
+
setv(
|
|
267
|
+
parent_object,
|
|
268
|
+
['customMetadata'],
|
|
269
|
+
[item for item in getv(from_object, ['custom_metadata'])],
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
if getv(from_object, ['chunking_config']) is not None:
|
|
273
|
+
setv(
|
|
274
|
+
parent_object,
|
|
275
|
+
['chunkingConfig'],
|
|
276
|
+
getv(from_object, ['chunking_config']),
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
return to_object
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _UploadToFileSearchStoreParameters_to_mldev(
|
|
283
|
+
from_object: Union[dict[str, Any], object],
|
|
284
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
285
|
+
) -> dict[str, Any]:
|
|
286
|
+
to_object: dict[str, Any] = {}
|
|
287
|
+
if getv(from_object, ['file_search_store_name']) is not None:
|
|
288
|
+
setv(
|
|
289
|
+
to_object,
|
|
290
|
+
['_url', 'file_search_store_name'],
|
|
291
|
+
getv(from_object, ['file_search_store_name']),
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
if getv(from_object, ['config']) is not None:
|
|
295
|
+
_UploadToFileSearchStoreConfig_to_mldev(
|
|
296
|
+
getv(from_object, ['config']), to_object
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
return to_object
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _UploadToFileSearchStoreResumableResponse_from_mldev(
|
|
303
|
+
from_object: Union[dict[str, Any], object],
|
|
304
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
305
|
+
) -> dict[str, Any]:
|
|
306
|
+
to_object: dict[str, Any] = {}
|
|
307
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
308
|
+
setv(
|
|
309
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
return to_object
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class FileSearchStores(_api_module.BaseModule):
|
|
316
|
+
|
|
317
|
+
@cached_property
|
|
318
|
+
def documents(self) -> Documents:
|
|
319
|
+
return Documents(self._api_client)
|
|
320
|
+
|
|
321
|
+
def create(
|
|
322
|
+
self, *, config: Optional[types.CreateFileSearchStoreConfigOrDict] = None
|
|
323
|
+
) -> types.FileSearchStore:
|
|
324
|
+
"""Creates a File Search Store.
|
|
325
|
+
|
|
326
|
+
Args:
|
|
327
|
+
config (CreateFileSearchStoreConfig | None): Optional parameters for the
|
|
328
|
+
request.
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
FileSearchStore
|
|
332
|
+
"""
|
|
333
|
+
|
|
334
|
+
parameter_model = types._CreateFileSearchStoreParameters(
|
|
335
|
+
config=config,
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
request_url_dict: Optional[dict[str, str]]
|
|
339
|
+
if self._api_client.vertexai:
|
|
340
|
+
raise ValueError(
|
|
341
|
+
'This method is only supported in the Gemini Developer client.'
|
|
342
|
+
)
|
|
343
|
+
else:
|
|
344
|
+
request_dict = _CreateFileSearchStoreParameters_to_mldev(parameter_model)
|
|
345
|
+
request_url_dict = request_dict.get('_url')
|
|
346
|
+
if request_url_dict:
|
|
347
|
+
path = 'fileSearchStores'.format_map(request_url_dict)
|
|
348
|
+
else:
|
|
349
|
+
path = 'fileSearchStores'
|
|
350
|
+
|
|
351
|
+
query_params = request_dict.get('_query')
|
|
352
|
+
if query_params:
|
|
353
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
354
|
+
# TODO: remove the hack that pops config.
|
|
355
|
+
request_dict.pop('config', None)
|
|
356
|
+
|
|
357
|
+
http_options: Optional[types.HttpOptions] = None
|
|
358
|
+
if (
|
|
359
|
+
parameter_model.config is not None
|
|
360
|
+
and parameter_model.config.http_options is not None
|
|
361
|
+
):
|
|
362
|
+
http_options = parameter_model.config.http_options
|
|
363
|
+
|
|
364
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
365
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
366
|
+
|
|
367
|
+
response = self._api_client.request(
|
|
368
|
+
'post', path, request_dict, http_options
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
372
|
+
|
|
373
|
+
return_value = types.FileSearchStore._from_response(
|
|
374
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
self._api_client._verify_response(return_value)
|
|
378
|
+
return return_value
|
|
379
|
+
|
|
380
|
+
def get(
|
|
381
|
+
self,
|
|
382
|
+
*,
|
|
383
|
+
name: str,
|
|
384
|
+
config: Optional[types.GetFileSearchStoreConfigOrDict] = None,
|
|
385
|
+
) -> types.FileSearchStore:
|
|
386
|
+
"""Gets metadata about a FileSearchStore.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
name (str): The resource name of the FileSearchStore. Example:
|
|
390
|
+
`FileSearchStores/my-file-search-store-123`
|
|
391
|
+
config (GetFileSearchStoreConfig | None): Optional parameters for the
|
|
392
|
+
request.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
A FileSearchStore object containing the metadata.
|
|
396
|
+
"""
|
|
397
|
+
|
|
398
|
+
parameter_model = types._GetFileSearchStoreParameters(
|
|
399
|
+
name=name,
|
|
400
|
+
config=config,
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
request_url_dict: Optional[dict[str, str]]
|
|
404
|
+
if self._api_client.vertexai:
|
|
405
|
+
raise ValueError(
|
|
406
|
+
'This method is only supported in the Gemini Developer client.'
|
|
407
|
+
)
|
|
408
|
+
else:
|
|
409
|
+
request_dict = _GetFileSearchStoreParameters_to_mldev(parameter_model)
|
|
410
|
+
request_url_dict = request_dict.get('_url')
|
|
411
|
+
if request_url_dict:
|
|
412
|
+
path = '{name}'.format_map(request_url_dict)
|
|
413
|
+
else:
|
|
414
|
+
path = '{name}'
|
|
415
|
+
|
|
416
|
+
query_params = request_dict.get('_query')
|
|
417
|
+
if query_params:
|
|
418
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
419
|
+
# TODO: remove the hack that pops config.
|
|
420
|
+
request_dict.pop('config', None)
|
|
421
|
+
|
|
422
|
+
http_options: Optional[types.HttpOptions] = None
|
|
423
|
+
if (
|
|
424
|
+
parameter_model.config is not None
|
|
425
|
+
and parameter_model.config.http_options is not None
|
|
426
|
+
):
|
|
427
|
+
http_options = parameter_model.config.http_options
|
|
428
|
+
|
|
429
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
430
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
431
|
+
|
|
432
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
|
433
|
+
|
|
434
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
435
|
+
|
|
436
|
+
return_value = types.FileSearchStore._from_response(
|
|
437
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
self._api_client._verify_response(return_value)
|
|
441
|
+
return return_value
|
|
442
|
+
|
|
443
|
+
def delete(
|
|
444
|
+
self,
|
|
445
|
+
*,
|
|
446
|
+
name: str,
|
|
447
|
+
config: Optional[types.DeleteFileSearchStoreConfigOrDict] = None,
|
|
448
|
+
) -> None:
|
|
449
|
+
"""Deletes a FileSearchStore.
|
|
450
|
+
|
|
451
|
+
Args:
|
|
452
|
+
name (str): The resource name of the FileSearchStore. Example:
|
|
453
|
+
`FileSearchStores/my-file-search-store-123`
|
|
454
|
+
config (DeleteFileSearchStoreConfig | None): Optional parameters for the
|
|
455
|
+
request.
|
|
456
|
+
|
|
457
|
+
Returns:
|
|
458
|
+
None
|
|
459
|
+
"""
|
|
460
|
+
|
|
461
|
+
parameter_model = types._DeleteFileSearchStoreParameters(
|
|
462
|
+
name=name,
|
|
463
|
+
config=config,
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
request_url_dict: Optional[dict[str, str]]
|
|
467
|
+
if self._api_client.vertexai:
|
|
468
|
+
raise ValueError(
|
|
469
|
+
'This method is only supported in the Gemini Developer client.'
|
|
470
|
+
)
|
|
471
|
+
else:
|
|
472
|
+
request_dict = _DeleteFileSearchStoreParameters_to_mldev(parameter_model)
|
|
473
|
+
request_url_dict = request_dict.get('_url')
|
|
474
|
+
if request_url_dict:
|
|
475
|
+
path = '{name}'.format_map(request_url_dict)
|
|
476
|
+
else:
|
|
477
|
+
path = '{name}'
|
|
478
|
+
|
|
479
|
+
query_params = request_dict.get('_query')
|
|
480
|
+
if query_params:
|
|
481
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
482
|
+
# TODO: remove the hack that pops config.
|
|
483
|
+
request_dict.pop('config', None)
|
|
484
|
+
|
|
485
|
+
http_options: Optional[types.HttpOptions] = None
|
|
486
|
+
if (
|
|
487
|
+
parameter_model.config is not None
|
|
488
|
+
and parameter_model.config.http_options is not None
|
|
489
|
+
):
|
|
490
|
+
http_options = parameter_model.config.http_options
|
|
491
|
+
|
|
492
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
493
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
494
|
+
|
|
495
|
+
response = self._api_client.request(
|
|
496
|
+
'delete', path, request_dict, http_options
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
def _list(
|
|
500
|
+
self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
|
|
501
|
+
) -> types.ListFileSearchStoresResponse:
|
|
502
|
+
"""Lists all FileSearchStore owned by the user.
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
config (ListFileSearchStoresConfig | None): Optional parameters for the
|
|
506
|
+
request, such as page_size.
|
|
507
|
+
|
|
508
|
+
Returns:
|
|
509
|
+
ListFileSearchStoresResponse: A paginated list of FileSearchStore.
|
|
510
|
+
"""
|
|
511
|
+
|
|
512
|
+
parameter_model = types._ListFileSearchStoresParameters(
|
|
513
|
+
config=config,
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
request_url_dict: Optional[dict[str, str]]
|
|
517
|
+
if self._api_client.vertexai:
|
|
518
|
+
raise ValueError(
|
|
519
|
+
'This method is only supported in the Gemini Developer client.'
|
|
520
|
+
)
|
|
521
|
+
else:
|
|
522
|
+
request_dict = _ListFileSearchStoresParameters_to_mldev(parameter_model)
|
|
523
|
+
request_url_dict = request_dict.get('_url')
|
|
524
|
+
if request_url_dict:
|
|
525
|
+
path = 'fileSearchStores'.format_map(request_url_dict)
|
|
526
|
+
else:
|
|
527
|
+
path = 'fileSearchStores'
|
|
528
|
+
|
|
529
|
+
query_params = request_dict.get('_query')
|
|
530
|
+
if query_params:
|
|
531
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
532
|
+
# TODO: remove the hack that pops config.
|
|
533
|
+
request_dict.pop('config', None)
|
|
534
|
+
|
|
535
|
+
http_options: Optional[types.HttpOptions] = None
|
|
536
|
+
if (
|
|
537
|
+
parameter_model.config is not None
|
|
538
|
+
and parameter_model.config.http_options is not None
|
|
539
|
+
):
|
|
540
|
+
http_options = parameter_model.config.http_options
|
|
541
|
+
|
|
542
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
543
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
544
|
+
|
|
545
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
|
546
|
+
|
|
547
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
548
|
+
|
|
549
|
+
if not self._api_client.vertexai:
|
|
550
|
+
response_dict = _ListFileSearchStoresResponse_from_mldev(response_dict)
|
|
551
|
+
|
|
552
|
+
return_value = types.ListFileSearchStoresResponse._from_response(
|
|
553
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
self._api_client._verify_response(return_value)
|
|
557
|
+
return return_value
|
|
558
|
+
|
|
559
|
+
def _upload_to_file_search_store(
|
|
560
|
+
self,
|
|
561
|
+
*,
|
|
562
|
+
file_search_store_name: str,
|
|
563
|
+
config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
|
|
564
|
+
) -> types.UploadToFileSearchStoreResumableResponse:
|
|
565
|
+
parameter_model = types._UploadToFileSearchStoreParameters(
|
|
566
|
+
file_search_store_name=file_search_store_name,
|
|
567
|
+
config=config,
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
request_url_dict: Optional[dict[str, str]]
|
|
571
|
+
if self._api_client.vertexai:
|
|
572
|
+
raise ValueError(
|
|
573
|
+
'This method is only supported in the Gemini Developer client.'
|
|
574
|
+
)
|
|
575
|
+
else:
|
|
576
|
+
request_dict = _UploadToFileSearchStoreParameters_to_mldev(
|
|
577
|
+
parameter_model
|
|
578
|
+
)
|
|
579
|
+
request_url_dict = request_dict.get('_url')
|
|
580
|
+
if request_url_dict:
|
|
581
|
+
path = (
|
|
582
|
+
'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
|
|
583
|
+
.format_map(request_url_dict)
|
|
584
|
+
)
|
|
585
|
+
else:
|
|
586
|
+
path = 'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
|
|
587
|
+
|
|
588
|
+
query_params = request_dict.get('_query')
|
|
589
|
+
if query_params:
|
|
590
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
591
|
+
# TODO: remove the hack that pops config.
|
|
592
|
+
request_dict.pop('config', None)
|
|
593
|
+
|
|
594
|
+
http_options: Optional[types.HttpOptions] = None
|
|
595
|
+
if (
|
|
596
|
+
parameter_model.config is not None
|
|
597
|
+
and parameter_model.config.http_options is not None
|
|
598
|
+
):
|
|
599
|
+
http_options = parameter_model.config.http_options
|
|
600
|
+
|
|
601
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
602
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
603
|
+
|
|
604
|
+
response = self._api_client.request(
|
|
605
|
+
'post', path, request_dict, http_options
|
|
606
|
+
)
|
|
607
|
+
|
|
608
|
+
if config is not None and getattr(
|
|
609
|
+
config, 'should_return_http_response', None
|
|
610
|
+
):
|
|
611
|
+
return_value = types.UploadToFileSearchStoreResumableResponse(
|
|
612
|
+
sdk_http_response=response
|
|
613
|
+
)
|
|
614
|
+
self._api_client._verify_response(return_value)
|
|
615
|
+
return return_value
|
|
616
|
+
|
|
617
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
618
|
+
|
|
619
|
+
if not self._api_client.vertexai:
|
|
620
|
+
response_dict = _UploadToFileSearchStoreResumableResponse_from_mldev(
|
|
621
|
+
response_dict
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
return_value = (
|
|
625
|
+
types.UploadToFileSearchStoreResumableResponse._from_response(
|
|
626
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
627
|
+
)
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
self._api_client._verify_response(return_value)
|
|
631
|
+
return return_value
|
|
632
|
+
|
|
633
|
+
def import_file(
|
|
634
|
+
self,
|
|
635
|
+
*,
|
|
636
|
+
file_search_store_name: str,
|
|
637
|
+
file_name: str,
|
|
638
|
+
config: Optional[types.ImportFileConfigOrDict] = None,
|
|
639
|
+
) -> types.ImportFileOperation:
|
|
640
|
+
"""Imports a File from File Service to a FileSearchStore.
|
|
641
|
+
|
|
642
|
+
This is a long-running operation, see aip.dev/151
|
|
643
|
+
|
|
644
|
+
Args:
|
|
645
|
+
file_search_store_name (str): The resource name of the FileSearchStore.
|
|
646
|
+
Example: `fileSearchStores/my-file-search-store-123`
|
|
647
|
+
file_name (str): The resource name of the File to import. Example:
|
|
648
|
+
`files/abc-123`
|
|
649
|
+
config (ImportFileConfig | None): Optional parameters for the request.
|
|
650
|
+
|
|
651
|
+
Returns:
|
|
652
|
+
ImportFileOperation.
|
|
653
|
+
"""
|
|
654
|
+
|
|
655
|
+
parameter_model = types._ImportFileParameters(
|
|
656
|
+
file_search_store_name=file_search_store_name,
|
|
657
|
+
file_name=file_name,
|
|
658
|
+
config=config,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
request_url_dict: Optional[dict[str, str]]
|
|
662
|
+
if self._api_client.vertexai:
|
|
663
|
+
raise ValueError(
|
|
664
|
+
'This method is only supported in the Gemini Developer client.'
|
|
665
|
+
)
|
|
666
|
+
else:
|
|
667
|
+
request_dict = _ImportFileParameters_to_mldev(parameter_model)
|
|
668
|
+
request_url_dict = request_dict.get('_url')
|
|
669
|
+
if request_url_dict:
|
|
670
|
+
path = '{file_search_store_name}:importFile'.format_map(
|
|
671
|
+
request_url_dict
|
|
672
|
+
)
|
|
673
|
+
else:
|
|
674
|
+
path = '{file_search_store_name}:importFile'
|
|
675
|
+
|
|
676
|
+
query_params = request_dict.get('_query')
|
|
677
|
+
if query_params:
|
|
678
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
679
|
+
# TODO: remove the hack that pops config.
|
|
680
|
+
request_dict.pop('config', None)
|
|
681
|
+
|
|
682
|
+
http_options: Optional[types.HttpOptions] = None
|
|
683
|
+
if (
|
|
684
|
+
parameter_model.config is not None
|
|
685
|
+
and parameter_model.config.http_options is not None
|
|
686
|
+
):
|
|
687
|
+
http_options = parameter_model.config.http_options
|
|
688
|
+
|
|
689
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
690
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
691
|
+
|
|
692
|
+
response = self._api_client.request(
|
|
693
|
+
'post', path, request_dict, http_options
|
|
694
|
+
)
|
|
695
|
+
|
|
696
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
697
|
+
|
|
698
|
+
if not self._api_client.vertexai:
|
|
699
|
+
response_dict = _ImportFileOperation_from_mldev(response_dict)
|
|
700
|
+
|
|
701
|
+
return_value = types.ImportFileOperation._from_response(
|
|
702
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
703
|
+
)
|
|
704
|
+
|
|
705
|
+
self._api_client._verify_response(return_value)
|
|
706
|
+
return return_value
|
|
707
|
+
|
|
708
|
+
def upload_to_file_search_store(
|
|
709
|
+
self,
|
|
710
|
+
*,
|
|
711
|
+
file_search_store_name: str,
|
|
712
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
|
713
|
+
config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
|
|
714
|
+
) -> types.UploadToFileSearchStoreOperation:
|
|
715
|
+
"""Calls the API to upload a file to the given file search store.
|
|
716
|
+
|
|
717
|
+
Args:
|
|
718
|
+
file_search_store_name: The resource name of the FileSearchStore. Example:
|
|
719
|
+
`fileSearchStores/file-search-store-123`
|
|
720
|
+
file: A path to the file or an `IOBase` object to be uploaded. If it's an
|
|
721
|
+
IOBase object, it must be opened in blocking (the default) mode and
|
|
722
|
+
binary mode. In other words, do not use non-blocking mode or text mode.
|
|
723
|
+
The given stream must be seekable, that is, it must be able to call
|
|
724
|
+
`seek()` on 'path'.
|
|
725
|
+
config: Optional parameters to set `diplay_name`, `mime_type`, and others.
|
|
726
|
+
"""
|
|
727
|
+
if self._api_client.vertexai:
|
|
728
|
+
raise ValueError(
|
|
729
|
+
'This method is only supported in the Gemini Developer client.'
|
|
730
|
+
)
|
|
731
|
+
if config is None:
|
|
732
|
+
user_config_dict: dict[str, Any] = {}
|
|
733
|
+
elif isinstance(config, dict):
|
|
734
|
+
user_config_dict = dict(config)
|
|
735
|
+
else:
|
|
736
|
+
user_config_dict = config.model_dump(exclude_unset=True)
|
|
737
|
+
|
|
738
|
+
http_options, size_bytes, _ = _extra_utils.prepare_resumable_upload(
|
|
739
|
+
file,
|
|
740
|
+
user_http_options=user_config_dict.get('http_options'),
|
|
741
|
+
user_mime_type=user_config_dict.get('mime_type'),
|
|
742
|
+
)
|
|
743
|
+
final_config_dict = {
|
|
744
|
+
**user_config_dict,
|
|
745
|
+
'http_options': http_options,
|
|
746
|
+
'should_return_http_response': True,
|
|
747
|
+
}
|
|
748
|
+
response = self._upload_to_file_search_store(
|
|
749
|
+
file_search_store_name=file_search_store_name,
|
|
750
|
+
config=types.UploadToFileSearchStoreConfig(**final_config_dict),
|
|
751
|
+
)
|
|
752
|
+
if (
|
|
753
|
+
response.sdk_http_response is None
|
|
754
|
+
or response.sdk_http_response.headers is None
|
|
755
|
+
or (
|
|
756
|
+
'x-goog-upload-url' not in response.sdk_http_response.headers
|
|
757
|
+
and 'X-Goog-Upload-URL' not in response.sdk_http_response.headers
|
|
758
|
+
)
|
|
759
|
+
):
|
|
760
|
+
raise KeyError(
|
|
761
|
+
'Failed to upload file to file search store. Upload URL did not'
|
|
762
|
+
' returned from the upload request.'
|
|
763
|
+
)
|
|
764
|
+
elif 'x-goog-upload-url' in response.sdk_http_response.headers:
|
|
765
|
+
upload_url = response.sdk_http_response.headers['x-goog-upload-url']
|
|
766
|
+
else:
|
|
767
|
+
upload_url = response.sdk_http_response.headers['X-Goog-Upload-URL']
|
|
768
|
+
if isinstance(file, io.IOBase):
|
|
769
|
+
upload_response = self._api_client.upload_file(
|
|
770
|
+
file, upload_url, size_bytes, http_options=http_options
|
|
771
|
+
)
|
|
772
|
+
else:
|
|
773
|
+
fs_path = os.fspath(file)
|
|
774
|
+
upload_response = self._api_client.upload_file(
|
|
775
|
+
fs_path, upload_url, size_bytes, http_options=http_options
|
|
776
|
+
)
|
|
777
|
+
response_dict = _UploadToFileSearchStoreOperation_from_mldev(
|
|
778
|
+
upload_response.json
|
|
779
|
+
)
|
|
780
|
+
return types.UploadToFileSearchStoreOperation._from_response(
|
|
781
|
+
response=response_dict, kwargs={}
|
|
782
|
+
)
|
|
783
|
+
|
|
784
|
+
def list(
|
|
785
|
+
self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
|
|
786
|
+
) -> Pager[types.FileSearchStore]:
|
|
787
|
+
"""Lists FileSearchStores.
|
|
788
|
+
|
|
789
|
+
Args:
|
|
790
|
+
config (ListFileSearchStoresConfig): Optional configuration for the list
|
|
791
|
+
request.
|
|
792
|
+
|
|
793
|
+
Returns:
|
|
794
|
+
A Pager object that contains one page of file search stores. When
|
|
795
|
+
iterating over
|
|
796
|
+
the pager, it automatically fetches the next page if there are more.
|
|
797
|
+
|
|
798
|
+
Usage:
|
|
799
|
+
|
|
800
|
+
.. code-block:: python
|
|
801
|
+
for file_search_store in client.file_search_stores.list():
|
|
802
|
+
print(f"file search store: {file_search_store.name} -
|
|
803
|
+
{file_search_store.display_name}")
|
|
804
|
+
"""
|
|
805
|
+
return Pager(
|
|
806
|
+
'file_search_stores',
|
|
807
|
+
self._list,
|
|
808
|
+
self._list(config=config),
|
|
809
|
+
config,
|
|
810
|
+
)
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
class AsyncFileSearchStores(_api_module.BaseModule):
|
|
814
|
+
|
|
815
|
+
@cached_property
|
|
816
|
+
def documents(self) -> AsyncDocuments:
|
|
817
|
+
return AsyncDocuments(self._api_client)
|
|
818
|
+
|
|
819
|
+
async def create(
|
|
820
|
+
self, *, config: Optional[types.CreateFileSearchStoreConfigOrDict] = None
|
|
821
|
+
) -> types.FileSearchStore:
|
|
822
|
+
"""Creates a File Search Store.
|
|
823
|
+
|
|
824
|
+
Args:
|
|
825
|
+
config (CreateFileSearchStoreConfig | None): Optional parameters for the
|
|
826
|
+
request.
|
|
827
|
+
|
|
828
|
+
Returns:
|
|
829
|
+
FileSearchStore
|
|
830
|
+
"""
|
|
831
|
+
|
|
832
|
+
parameter_model = types._CreateFileSearchStoreParameters(
|
|
833
|
+
config=config,
|
|
834
|
+
)
|
|
835
|
+
|
|
836
|
+
request_url_dict: Optional[dict[str, str]]
|
|
837
|
+
if self._api_client.vertexai:
|
|
838
|
+
raise ValueError(
|
|
839
|
+
'This method is only supported in the Gemini Developer client.'
|
|
840
|
+
)
|
|
841
|
+
else:
|
|
842
|
+
request_dict = _CreateFileSearchStoreParameters_to_mldev(parameter_model)
|
|
843
|
+
request_url_dict = request_dict.get('_url')
|
|
844
|
+
if request_url_dict:
|
|
845
|
+
path = 'fileSearchStores'.format_map(request_url_dict)
|
|
846
|
+
else:
|
|
847
|
+
path = 'fileSearchStores'
|
|
848
|
+
|
|
849
|
+
query_params = request_dict.get('_query')
|
|
850
|
+
if query_params:
|
|
851
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
852
|
+
# TODO: remove the hack that pops config.
|
|
853
|
+
request_dict.pop('config', None)
|
|
854
|
+
|
|
855
|
+
http_options: Optional[types.HttpOptions] = None
|
|
856
|
+
if (
|
|
857
|
+
parameter_model.config is not None
|
|
858
|
+
and parameter_model.config.http_options is not None
|
|
859
|
+
):
|
|
860
|
+
http_options = parameter_model.config.http_options
|
|
861
|
+
|
|
862
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
863
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
864
|
+
|
|
865
|
+
response = await self._api_client.async_request(
|
|
866
|
+
'post', path, request_dict, http_options
|
|
867
|
+
)
|
|
868
|
+
|
|
869
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
870
|
+
|
|
871
|
+
return_value = types.FileSearchStore._from_response(
|
|
872
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
873
|
+
)
|
|
874
|
+
|
|
875
|
+
self._api_client._verify_response(return_value)
|
|
876
|
+
return return_value
|
|
877
|
+
|
|
878
|
+
async def get(
|
|
879
|
+
self,
|
|
880
|
+
*,
|
|
881
|
+
name: str,
|
|
882
|
+
config: Optional[types.GetFileSearchStoreConfigOrDict] = None,
|
|
883
|
+
) -> types.FileSearchStore:
|
|
884
|
+
"""Gets metadata about a FileSearchStore.
|
|
885
|
+
|
|
886
|
+
Args:
|
|
887
|
+
name (str): The resource name of the FileSearchStore. Example:
|
|
888
|
+
`FileSearchStores/my-file-search-store-123`
|
|
889
|
+
config (GetFileSearchStoreConfig | None): Optional parameters for the
|
|
890
|
+
request.
|
|
891
|
+
|
|
892
|
+
Returns:
|
|
893
|
+
A FileSearchStore object containing the metadata.
|
|
894
|
+
"""
|
|
895
|
+
|
|
896
|
+
parameter_model = types._GetFileSearchStoreParameters(
|
|
897
|
+
name=name,
|
|
898
|
+
config=config,
|
|
899
|
+
)
|
|
900
|
+
|
|
901
|
+
request_url_dict: Optional[dict[str, str]]
|
|
902
|
+
if self._api_client.vertexai:
|
|
903
|
+
raise ValueError(
|
|
904
|
+
'This method is only supported in the Gemini Developer client.'
|
|
905
|
+
)
|
|
906
|
+
else:
|
|
907
|
+
request_dict = _GetFileSearchStoreParameters_to_mldev(parameter_model)
|
|
908
|
+
request_url_dict = request_dict.get('_url')
|
|
909
|
+
if request_url_dict:
|
|
910
|
+
path = '{name}'.format_map(request_url_dict)
|
|
911
|
+
else:
|
|
912
|
+
path = '{name}'
|
|
913
|
+
|
|
914
|
+
query_params = request_dict.get('_query')
|
|
915
|
+
if query_params:
|
|
916
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
917
|
+
# TODO: remove the hack that pops config.
|
|
918
|
+
request_dict.pop('config', None)
|
|
919
|
+
|
|
920
|
+
http_options: Optional[types.HttpOptions] = None
|
|
921
|
+
if (
|
|
922
|
+
parameter_model.config is not None
|
|
923
|
+
and parameter_model.config.http_options is not None
|
|
924
|
+
):
|
|
925
|
+
http_options = parameter_model.config.http_options
|
|
926
|
+
|
|
927
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
928
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
929
|
+
|
|
930
|
+
response = await self._api_client.async_request(
|
|
931
|
+
'get', path, request_dict, http_options
|
|
932
|
+
)
|
|
933
|
+
|
|
934
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
935
|
+
|
|
936
|
+
return_value = types.FileSearchStore._from_response(
|
|
937
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
938
|
+
)
|
|
939
|
+
|
|
940
|
+
self._api_client._verify_response(return_value)
|
|
941
|
+
return return_value
|
|
942
|
+
|
|
943
|
+
async def delete(
|
|
944
|
+
self,
|
|
945
|
+
*,
|
|
946
|
+
name: str,
|
|
947
|
+
config: Optional[types.DeleteFileSearchStoreConfigOrDict] = None,
|
|
948
|
+
) -> None:
|
|
949
|
+
"""Deletes a FileSearchStore.
|
|
950
|
+
|
|
951
|
+
Args:
|
|
952
|
+
name (str): The resource name of the FileSearchStore. Example:
|
|
953
|
+
`FileSearchStores/my-file-search-store-123`
|
|
954
|
+
config (DeleteFileSearchStoreConfig | None): Optional parameters for the
|
|
955
|
+
request.
|
|
956
|
+
|
|
957
|
+
Returns:
|
|
958
|
+
None
|
|
959
|
+
"""
|
|
960
|
+
|
|
961
|
+
parameter_model = types._DeleteFileSearchStoreParameters(
|
|
962
|
+
name=name,
|
|
963
|
+
config=config,
|
|
964
|
+
)
|
|
965
|
+
|
|
966
|
+
request_url_dict: Optional[dict[str, str]]
|
|
967
|
+
if self._api_client.vertexai:
|
|
968
|
+
raise ValueError(
|
|
969
|
+
'This method is only supported in the Gemini Developer client.'
|
|
970
|
+
)
|
|
971
|
+
else:
|
|
972
|
+
request_dict = _DeleteFileSearchStoreParameters_to_mldev(parameter_model)
|
|
973
|
+
request_url_dict = request_dict.get('_url')
|
|
974
|
+
if request_url_dict:
|
|
975
|
+
path = '{name}'.format_map(request_url_dict)
|
|
976
|
+
else:
|
|
977
|
+
path = '{name}'
|
|
978
|
+
|
|
979
|
+
query_params = request_dict.get('_query')
|
|
980
|
+
if query_params:
|
|
981
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
982
|
+
# TODO: remove the hack that pops config.
|
|
983
|
+
request_dict.pop('config', None)
|
|
984
|
+
|
|
985
|
+
http_options: Optional[types.HttpOptions] = None
|
|
986
|
+
if (
|
|
987
|
+
parameter_model.config is not None
|
|
988
|
+
and parameter_model.config.http_options is not None
|
|
989
|
+
):
|
|
990
|
+
http_options = parameter_model.config.http_options
|
|
991
|
+
|
|
992
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
993
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
994
|
+
|
|
995
|
+
response = await self._api_client.async_request(
|
|
996
|
+
'delete', path, request_dict, http_options
|
|
997
|
+
)
|
|
998
|
+
|
|
999
|
+
async def _list(
|
|
1000
|
+
self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
|
|
1001
|
+
) -> types.ListFileSearchStoresResponse:
|
|
1002
|
+
"""Lists all FileSearchStore owned by the user.
|
|
1003
|
+
|
|
1004
|
+
Args:
|
|
1005
|
+
config (ListFileSearchStoresConfig | None): Optional parameters for the
|
|
1006
|
+
request, such as page_size.
|
|
1007
|
+
|
|
1008
|
+
Returns:
|
|
1009
|
+
ListFileSearchStoresResponse: A paginated list of FileSearchStore.
|
|
1010
|
+
"""
|
|
1011
|
+
|
|
1012
|
+
parameter_model = types._ListFileSearchStoresParameters(
|
|
1013
|
+
config=config,
|
|
1014
|
+
)
|
|
1015
|
+
|
|
1016
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1017
|
+
if self._api_client.vertexai:
|
|
1018
|
+
raise ValueError(
|
|
1019
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1020
|
+
)
|
|
1021
|
+
else:
|
|
1022
|
+
request_dict = _ListFileSearchStoresParameters_to_mldev(parameter_model)
|
|
1023
|
+
request_url_dict = request_dict.get('_url')
|
|
1024
|
+
if request_url_dict:
|
|
1025
|
+
path = 'fileSearchStores'.format_map(request_url_dict)
|
|
1026
|
+
else:
|
|
1027
|
+
path = 'fileSearchStores'
|
|
1028
|
+
|
|
1029
|
+
query_params = request_dict.get('_query')
|
|
1030
|
+
if query_params:
|
|
1031
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
1032
|
+
# TODO: remove the hack that pops config.
|
|
1033
|
+
request_dict.pop('config', None)
|
|
1034
|
+
|
|
1035
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1036
|
+
if (
|
|
1037
|
+
parameter_model.config is not None
|
|
1038
|
+
and parameter_model.config.http_options is not None
|
|
1039
|
+
):
|
|
1040
|
+
http_options = parameter_model.config.http_options
|
|
1041
|
+
|
|
1042
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1043
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1044
|
+
|
|
1045
|
+
response = await self._api_client.async_request(
|
|
1046
|
+
'get', path, request_dict, http_options
|
|
1047
|
+
)
|
|
1048
|
+
|
|
1049
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1050
|
+
|
|
1051
|
+
if not self._api_client.vertexai:
|
|
1052
|
+
response_dict = _ListFileSearchStoresResponse_from_mldev(response_dict)
|
|
1053
|
+
|
|
1054
|
+
return_value = types.ListFileSearchStoresResponse._from_response(
|
|
1055
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1056
|
+
)
|
|
1057
|
+
|
|
1058
|
+
self._api_client._verify_response(return_value)
|
|
1059
|
+
return return_value
|
|
1060
|
+
|
|
1061
|
+
async def _upload_to_file_search_store(
|
|
1062
|
+
self,
|
|
1063
|
+
*,
|
|
1064
|
+
file_search_store_name: str,
|
|
1065
|
+
config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
|
|
1066
|
+
) -> types.UploadToFileSearchStoreResumableResponse:
|
|
1067
|
+
parameter_model = types._UploadToFileSearchStoreParameters(
|
|
1068
|
+
file_search_store_name=file_search_store_name,
|
|
1069
|
+
config=config,
|
|
1070
|
+
)
|
|
1071
|
+
|
|
1072
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1073
|
+
if self._api_client.vertexai:
|
|
1074
|
+
raise ValueError(
|
|
1075
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1076
|
+
)
|
|
1077
|
+
else:
|
|
1078
|
+
request_dict = _UploadToFileSearchStoreParameters_to_mldev(
|
|
1079
|
+
parameter_model
|
|
1080
|
+
)
|
|
1081
|
+
request_url_dict = request_dict.get('_url')
|
|
1082
|
+
if request_url_dict:
|
|
1083
|
+
path = (
|
|
1084
|
+
'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
|
|
1085
|
+
.format_map(request_url_dict)
|
|
1086
|
+
)
|
|
1087
|
+
else:
|
|
1088
|
+
path = 'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
|
|
1089
|
+
|
|
1090
|
+
query_params = request_dict.get('_query')
|
|
1091
|
+
if query_params:
|
|
1092
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
1093
|
+
# TODO: remove the hack that pops config.
|
|
1094
|
+
request_dict.pop('config', None)
|
|
1095
|
+
|
|
1096
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1097
|
+
if (
|
|
1098
|
+
parameter_model.config is not None
|
|
1099
|
+
and parameter_model.config.http_options is not None
|
|
1100
|
+
):
|
|
1101
|
+
http_options = parameter_model.config.http_options
|
|
1102
|
+
|
|
1103
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1104
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1105
|
+
|
|
1106
|
+
response = await self._api_client.async_request(
|
|
1107
|
+
'post', path, request_dict, http_options
|
|
1108
|
+
)
|
|
1109
|
+
|
|
1110
|
+
if config is not None and getattr(
|
|
1111
|
+
config, 'should_return_http_response', None
|
|
1112
|
+
):
|
|
1113
|
+
return_value = types.UploadToFileSearchStoreResumableResponse(
|
|
1114
|
+
sdk_http_response=response
|
|
1115
|
+
)
|
|
1116
|
+
self._api_client._verify_response(return_value)
|
|
1117
|
+
return return_value
|
|
1118
|
+
|
|
1119
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1120
|
+
|
|
1121
|
+
if not self._api_client.vertexai:
|
|
1122
|
+
response_dict = _UploadToFileSearchStoreResumableResponse_from_mldev(
|
|
1123
|
+
response_dict
|
|
1124
|
+
)
|
|
1125
|
+
|
|
1126
|
+
return_value = (
|
|
1127
|
+
types.UploadToFileSearchStoreResumableResponse._from_response(
|
|
1128
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1129
|
+
)
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1132
|
+
self._api_client._verify_response(return_value)
|
|
1133
|
+
return return_value
|
|
1134
|
+
|
|
1135
|
+
async def import_file(
|
|
1136
|
+
self,
|
|
1137
|
+
*,
|
|
1138
|
+
file_search_store_name: str,
|
|
1139
|
+
file_name: str,
|
|
1140
|
+
config: Optional[types.ImportFileConfigOrDict] = None,
|
|
1141
|
+
) -> types.ImportFileOperation:
|
|
1142
|
+
"""Imports a File from File Service to a FileSearchStore.
|
|
1143
|
+
|
|
1144
|
+
This is a long-running operation, see aip.dev/151
|
|
1145
|
+
|
|
1146
|
+
Args:
|
|
1147
|
+
file_search_store_name (str): The resource name of the FileSearchStore.
|
|
1148
|
+
Example: `fileSearchStores/my-file-search-store-123`
|
|
1149
|
+
file_name (str): The resource name of the File to import. Example:
|
|
1150
|
+
`files/abc-123`
|
|
1151
|
+
config (ImportFileConfig | None): Optional parameters for the request.
|
|
1152
|
+
|
|
1153
|
+
Returns:
|
|
1154
|
+
ImportFileOperation.
|
|
1155
|
+
"""
|
|
1156
|
+
|
|
1157
|
+
parameter_model = types._ImportFileParameters(
|
|
1158
|
+
file_search_store_name=file_search_store_name,
|
|
1159
|
+
file_name=file_name,
|
|
1160
|
+
config=config,
|
|
1161
|
+
)
|
|
1162
|
+
|
|
1163
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1164
|
+
if self._api_client.vertexai:
|
|
1165
|
+
raise ValueError(
|
|
1166
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1167
|
+
)
|
|
1168
|
+
else:
|
|
1169
|
+
request_dict = _ImportFileParameters_to_mldev(parameter_model)
|
|
1170
|
+
request_url_dict = request_dict.get('_url')
|
|
1171
|
+
if request_url_dict:
|
|
1172
|
+
path = '{file_search_store_name}:importFile'.format_map(
|
|
1173
|
+
request_url_dict
|
|
1174
|
+
)
|
|
1175
|
+
else:
|
|
1176
|
+
path = '{file_search_store_name}:importFile'
|
|
1177
|
+
|
|
1178
|
+
query_params = request_dict.get('_query')
|
|
1179
|
+
if query_params:
|
|
1180
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
1181
|
+
# TODO: remove the hack that pops config.
|
|
1182
|
+
request_dict.pop('config', None)
|
|
1183
|
+
|
|
1184
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1185
|
+
if (
|
|
1186
|
+
parameter_model.config is not None
|
|
1187
|
+
and parameter_model.config.http_options is not None
|
|
1188
|
+
):
|
|
1189
|
+
http_options = parameter_model.config.http_options
|
|
1190
|
+
|
|
1191
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1192
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1193
|
+
|
|
1194
|
+
response = await self._api_client.async_request(
|
|
1195
|
+
'post', path, request_dict, http_options
|
|
1196
|
+
)
|
|
1197
|
+
|
|
1198
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1199
|
+
|
|
1200
|
+
if not self._api_client.vertexai:
|
|
1201
|
+
response_dict = _ImportFileOperation_from_mldev(response_dict)
|
|
1202
|
+
|
|
1203
|
+
return_value = types.ImportFileOperation._from_response(
|
|
1204
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
|
1205
|
+
)
|
|
1206
|
+
|
|
1207
|
+
self._api_client._verify_response(return_value)
|
|
1208
|
+
return return_value
|
|
1209
|
+
|
|
1210
|
+
async def upload_to_file_search_store(
|
|
1211
|
+
self,
|
|
1212
|
+
*,
|
|
1213
|
+
file_search_store_name: str,
|
|
1214
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
|
1215
|
+
config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
|
|
1216
|
+
) -> types.UploadToFileSearchStoreOperation:
|
|
1217
|
+
"""Calls the API to upload a file to the given file search store.
|
|
1218
|
+
|
|
1219
|
+
Args:
|
|
1220
|
+
file_search_store_name: The resource name of the FileSearchStore. Example:
|
|
1221
|
+
`fileSearchStores/file-search-store-123`
|
|
1222
|
+
file: A path to the file or an `IOBase` object to be uploaded. If it's an
|
|
1223
|
+
IOBase object, it must be opened in blocking (the default) mode and
|
|
1224
|
+
binary mode. In other words, do not use non-blocking mode or text mode.
|
|
1225
|
+
The given stream must be seekable, that is, it must be able to call
|
|
1226
|
+
`seek()` on 'path'.
|
|
1227
|
+
config: Optional parameters to set `diplay_name`, `mime_type` and others.
|
|
1228
|
+
"""
|
|
1229
|
+
if self._api_client.vertexai:
|
|
1230
|
+
raise ValueError(
|
|
1231
|
+
'This method is only supported in the Gemini Developer client.'
|
|
1232
|
+
)
|
|
1233
|
+
if config is None:
|
|
1234
|
+
user_config_dict: dict[str, Any] = {}
|
|
1235
|
+
elif isinstance(config, dict):
|
|
1236
|
+
user_config_dict = dict(config)
|
|
1237
|
+
else:
|
|
1238
|
+
user_config_dict = config.model_dump(exclude_unset=True)
|
|
1239
|
+
|
|
1240
|
+
http_options, size_bytes, _ = _extra_utils.prepare_resumable_upload(
|
|
1241
|
+
file,
|
|
1242
|
+
user_http_options=user_config_dict.get('http_options'),
|
|
1243
|
+
user_mime_type=user_config_dict.get('mime_type'),
|
|
1244
|
+
)
|
|
1245
|
+
final_config_dict = {
|
|
1246
|
+
**user_config_dict,
|
|
1247
|
+
'http_options': http_options,
|
|
1248
|
+
'should_return_http_response': True,
|
|
1249
|
+
}
|
|
1250
|
+
response = await self._upload_to_file_search_store(
|
|
1251
|
+
file_search_store_name=file_search_store_name,
|
|
1252
|
+
config=types.UploadToFileSearchStoreConfig(**final_config_dict),
|
|
1253
|
+
)
|
|
1254
|
+
if (
|
|
1255
|
+
response.sdk_http_response is None
|
|
1256
|
+
or response.sdk_http_response.headers is None
|
|
1257
|
+
or (
|
|
1258
|
+
'x-goog-upload-url' not in response.sdk_http_response.headers
|
|
1259
|
+
and 'X-Goog-Upload-URL' not in response.sdk_http_response.headers
|
|
1260
|
+
)
|
|
1261
|
+
):
|
|
1262
|
+
raise KeyError(
|
|
1263
|
+
'Failed to upload file to file search store. Upload URL did not'
|
|
1264
|
+
' returned from the upload request.'
|
|
1265
|
+
)
|
|
1266
|
+
elif 'x-goog-upload-url' in response.sdk_http_response.headers:
|
|
1267
|
+
upload_url = response.sdk_http_response.headers['x-goog-upload-url']
|
|
1268
|
+
else:
|
|
1269
|
+
upload_url = response.sdk_http_response.headers['X-Goog-Upload-URL']
|
|
1270
|
+
if isinstance(file, io.IOBase):
|
|
1271
|
+
upload_response = await self._api_client.async_upload_file(
|
|
1272
|
+
file, upload_url, size_bytes, http_options=http_options
|
|
1273
|
+
)
|
|
1274
|
+
else:
|
|
1275
|
+
fs_path = os.fspath(file)
|
|
1276
|
+
upload_response = await self._api_client.async_upload_file(
|
|
1277
|
+
fs_path, upload_url, size_bytes, http_options=http_options
|
|
1278
|
+
)
|
|
1279
|
+
response_dict = _UploadToFileSearchStoreOperation_from_mldev(
|
|
1280
|
+
upload_response.json
|
|
1281
|
+
)
|
|
1282
|
+
return types.UploadToFileSearchStoreOperation._from_response(
|
|
1283
|
+
response=response_dict, kwargs={}
|
|
1284
|
+
)
|
|
1285
|
+
|
|
1286
|
+
async def list(
|
|
1287
|
+
self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
|
|
1288
|
+
) -> AsyncPager[types.FileSearchStore]:
|
|
1289
|
+
"""Lists FileSearchStores asynchronously.
|
|
1290
|
+
|
|
1291
|
+
Args:
|
|
1292
|
+
config (ListFileSearchStoresConfig): Optional configuration for the list
|
|
1293
|
+
request.
|
|
1294
|
+
|
|
1295
|
+
Returns:
|
|
1296
|
+
A Pager object that contains one page of FileSearchStores. When iterating
|
|
1297
|
+
over
|
|
1298
|
+
the pager, it automatically fetches the next page if there are more.
|
|
1299
|
+
|
|
1300
|
+
Usage:
|
|
1301
|
+
|
|
1302
|
+
.. code-block:: python
|
|
1303
|
+
async for file_search_store in await client.file_search_stores.list():
|
|
1304
|
+
print(f"file search store: {file_search_store.name} -
|
|
1305
|
+
{file_search_store.display_name}")
|
|
1306
|
+
"""
|
|
1307
|
+
return AsyncPager(
|
|
1308
|
+
'file_search_stores',
|
|
1309
|
+
self._list,
|
|
1310
|
+
await self._list(config=config),
|
|
1311
|
+
config,
|
|
1312
|
+
)
|