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.
Files changed (42) hide show
  1. google/genai/__init__.py +4 -2
  2. google/genai/_adapters.py +55 -0
  3. google/genai/_api_client.py +1301 -299
  4. google/genai/_api_module.py +1 -1
  5. google/genai/_automatic_function_calling_util.py +54 -33
  6. google/genai/_base_transformers.py +26 -0
  7. google/genai/_base_url.py +50 -0
  8. google/genai/_common.py +560 -59
  9. google/genai/_extra_utils.py +371 -38
  10. google/genai/_live_converters.py +1467 -0
  11. google/genai/_local_tokenizer_loader.py +214 -0
  12. google/genai/_mcp_utils.py +117 -0
  13. google/genai/_operations_converters.py +394 -0
  14. google/genai/_replay_api_client.py +204 -92
  15. google/genai/_test_api_client.py +1 -1
  16. google/genai/_tokens_converters.py +520 -0
  17. google/genai/_transformers.py +633 -233
  18. google/genai/batches.py +1733 -538
  19. google/genai/caches.py +678 -1012
  20. google/genai/chats.py +48 -38
  21. google/genai/client.py +142 -15
  22. google/genai/documents.py +532 -0
  23. google/genai/errors.py +141 -35
  24. google/genai/file_search_stores.py +1296 -0
  25. google/genai/files.py +312 -744
  26. google/genai/live.py +617 -367
  27. google/genai/live_music.py +197 -0
  28. google/genai/local_tokenizer.py +395 -0
  29. google/genai/models.py +3598 -3116
  30. google/genai/operations.py +201 -362
  31. google/genai/pagers.py +23 -7
  32. google/genai/py.typed +1 -0
  33. google/genai/tokens.py +362 -0
  34. google/genai/tunings.py +1274 -496
  35. google/genai/types.py +14535 -5454
  36. google/genai/version.py +2 -2
  37. {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/METADATA +736 -234
  38. google_genai-1.53.0.dist-info/RECORD +41 -0
  39. {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/WHEEL +1 -1
  40. google_genai-1.7.0.dist-info/RECORD +0 -27
  41. {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info/licenses}/LICENSE +0 -0
  42. {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1296 @@
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
+ parameter_model = types._ListFileSearchStoresParameters(
503
+ config=config,
504
+ )
505
+
506
+ request_url_dict: Optional[dict[str, str]]
507
+ if self._api_client.vertexai:
508
+ raise ValueError(
509
+ 'This method is only supported in the Gemini Developer client.'
510
+ )
511
+ else:
512
+ request_dict = _ListFileSearchStoresParameters_to_mldev(parameter_model)
513
+ request_url_dict = request_dict.get('_url')
514
+ if request_url_dict:
515
+ path = 'fileSearchStores'.format_map(request_url_dict)
516
+ else:
517
+ path = 'fileSearchStores'
518
+
519
+ query_params = request_dict.get('_query')
520
+ if query_params:
521
+ path = f'{path}?{urlencode(query_params)}'
522
+ # TODO: remove the hack that pops config.
523
+ request_dict.pop('config', None)
524
+
525
+ http_options: Optional[types.HttpOptions] = None
526
+ if (
527
+ parameter_model.config is not None
528
+ and parameter_model.config.http_options is not None
529
+ ):
530
+ http_options = parameter_model.config.http_options
531
+
532
+ request_dict = _common.convert_to_dict(request_dict)
533
+ request_dict = _common.encode_unserializable_types(request_dict)
534
+
535
+ response = self._api_client.request('get', path, request_dict, http_options)
536
+
537
+ response_dict = {} if not response.body else json.loads(response.body)
538
+
539
+ if not self._api_client.vertexai:
540
+ response_dict = _ListFileSearchStoresResponse_from_mldev(response_dict)
541
+
542
+ return_value = types.ListFileSearchStoresResponse._from_response(
543
+ response=response_dict, kwargs=parameter_model.model_dump()
544
+ )
545
+
546
+ self._api_client._verify_response(return_value)
547
+ return return_value
548
+
549
+ def _upload_to_file_search_store(
550
+ self,
551
+ *,
552
+ file_search_store_name: str,
553
+ config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
554
+ ) -> types.UploadToFileSearchStoreResumableResponse:
555
+ parameter_model = types._UploadToFileSearchStoreParameters(
556
+ file_search_store_name=file_search_store_name,
557
+ config=config,
558
+ )
559
+
560
+ request_url_dict: Optional[dict[str, str]]
561
+ if self._api_client.vertexai:
562
+ raise ValueError(
563
+ 'This method is only supported in the Gemini Developer client.'
564
+ )
565
+ else:
566
+ request_dict = _UploadToFileSearchStoreParameters_to_mldev(
567
+ parameter_model
568
+ )
569
+ request_url_dict = request_dict.get('_url')
570
+ if request_url_dict:
571
+ path = (
572
+ 'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
573
+ .format_map(request_url_dict)
574
+ )
575
+ else:
576
+ path = 'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
577
+
578
+ query_params = request_dict.get('_query')
579
+ if query_params:
580
+ path = f'{path}?{urlencode(query_params)}'
581
+ # TODO: remove the hack that pops config.
582
+ request_dict.pop('config', None)
583
+
584
+ http_options: Optional[types.HttpOptions] = None
585
+ if (
586
+ parameter_model.config is not None
587
+ and parameter_model.config.http_options is not None
588
+ ):
589
+ http_options = parameter_model.config.http_options
590
+
591
+ request_dict = _common.convert_to_dict(request_dict)
592
+ request_dict = _common.encode_unserializable_types(request_dict)
593
+
594
+ response = self._api_client.request(
595
+ 'post', path, request_dict, http_options
596
+ )
597
+
598
+ if config is not None and getattr(
599
+ config, 'should_return_http_response', None
600
+ ):
601
+ return_value = types.UploadToFileSearchStoreResumableResponse(
602
+ sdk_http_response=response
603
+ )
604
+ self._api_client._verify_response(return_value)
605
+ return return_value
606
+
607
+ response_dict = {} if not response.body else json.loads(response.body)
608
+
609
+ if not self._api_client.vertexai:
610
+ response_dict = _UploadToFileSearchStoreResumableResponse_from_mldev(
611
+ response_dict
612
+ )
613
+
614
+ return_value = (
615
+ types.UploadToFileSearchStoreResumableResponse._from_response(
616
+ response=response_dict, kwargs=parameter_model.model_dump()
617
+ )
618
+ )
619
+
620
+ self._api_client._verify_response(return_value)
621
+ return return_value
622
+
623
+ def import_file(
624
+ self,
625
+ *,
626
+ file_search_store_name: str,
627
+ file_name: str,
628
+ config: Optional[types.ImportFileConfigOrDict] = None,
629
+ ) -> types.ImportFileOperation:
630
+ """Imports a File from File Service to a FileSearchStore.
631
+
632
+ This is a long-running operation, see aip.dev/151
633
+
634
+ Args:
635
+ file_search_store_name (str): The resource name of the FileSearchStore.
636
+ Example: `fileSearchStores/my-file-search-store-123`
637
+ file_name (str): The resource name of the File to import. Example:
638
+ `files/abc-123`
639
+ config (ImportFileConfig | None): Optional parameters for the request.
640
+
641
+ Returns:
642
+ ImportFileOperation.
643
+ """
644
+
645
+ parameter_model = types._ImportFileParameters(
646
+ file_search_store_name=file_search_store_name,
647
+ file_name=file_name,
648
+ config=config,
649
+ )
650
+
651
+ request_url_dict: Optional[dict[str, str]]
652
+ if self._api_client.vertexai:
653
+ raise ValueError(
654
+ 'This method is only supported in the Gemini Developer client.'
655
+ )
656
+ else:
657
+ request_dict = _ImportFileParameters_to_mldev(parameter_model)
658
+ request_url_dict = request_dict.get('_url')
659
+ if request_url_dict:
660
+ path = '{file_search_store_name}:importFile'.format_map(
661
+ request_url_dict
662
+ )
663
+ else:
664
+ path = '{file_search_store_name}:importFile'
665
+
666
+ query_params = request_dict.get('_query')
667
+ if query_params:
668
+ path = f'{path}?{urlencode(query_params)}'
669
+ # TODO: remove the hack that pops config.
670
+ request_dict.pop('config', None)
671
+
672
+ http_options: Optional[types.HttpOptions] = None
673
+ if (
674
+ parameter_model.config is not None
675
+ and parameter_model.config.http_options is not None
676
+ ):
677
+ http_options = parameter_model.config.http_options
678
+
679
+ request_dict = _common.convert_to_dict(request_dict)
680
+ request_dict = _common.encode_unserializable_types(request_dict)
681
+
682
+ response = self._api_client.request(
683
+ 'post', path, request_dict, http_options
684
+ )
685
+
686
+ response_dict = {} if not response.body else json.loads(response.body)
687
+
688
+ if not self._api_client.vertexai:
689
+ response_dict = _ImportFileOperation_from_mldev(response_dict)
690
+
691
+ return_value = types.ImportFileOperation._from_response(
692
+ response=response_dict, kwargs=parameter_model.model_dump()
693
+ )
694
+
695
+ self._api_client._verify_response(return_value)
696
+ return return_value
697
+
698
+ def list(
699
+ self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
700
+ ) -> Pager[types.FileSearchStore]:
701
+ """Lists FileSearchStores.
702
+
703
+ Args:
704
+ config (ListFileSearchStoresConfig): Optional configuration for the list
705
+ request.
706
+
707
+ Returns:
708
+ A Pager object that contains one page of file search stores. When
709
+ iterating over
710
+ the pager, it automatically fetches the next page if there are more.
711
+
712
+ Usage:
713
+
714
+ .. code-block:: python
715
+ for file_search_store in client.file_search_stores.list():
716
+ print(f"file search store: {file_search_store.name} -
717
+ {file_search_store.display_name}")
718
+ """
719
+
720
+ list_request = self._list
721
+ return Pager(
722
+ 'file_search_stores',
723
+ list_request,
724
+ self._list(config=config),
725
+ config,
726
+ )
727
+
728
+ def upload_to_file_search_store(
729
+ self,
730
+ *,
731
+ file_search_store_name: str,
732
+ file: Union[str, os.PathLike[str], io.IOBase],
733
+ config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
734
+ ) -> types.UploadToFileSearchStoreOperation:
735
+ """Calls the API to upload a file to the given file search store.
736
+
737
+ Args:
738
+ file_search_store_name: The resource name of the FileSearchStore. Example:
739
+ `fileSearchStores/file-search-store-123`
740
+ file: A path to the file or an `IOBase` object to be uploaded. If it's an
741
+ IOBase object, it must be opened in blocking (the default) mode and
742
+ binary mode. In other words, do not use non-blocking mode or text mode.
743
+ The given stream must be seekable, that is, it must be able to call
744
+ `seek()` on 'path'.
745
+ config: Optional parameters to set `diplay_name`, `mime_type`, and others.
746
+ """
747
+ if self._api_client.vertexai:
748
+ raise ValueError(
749
+ 'This method is only supported in the Gemini Developer client.'
750
+ )
751
+ if config is None:
752
+ user_config_dict: dict[str, Any] = {}
753
+ elif isinstance(config, dict):
754
+ user_config_dict = dict(config)
755
+ else:
756
+ user_config_dict = config.model_dump(exclude_unset=True)
757
+
758
+ http_options, size_bytes, _ = _extra_utils.prepare_resumable_upload(
759
+ file,
760
+ user_http_options=user_config_dict.get('http_options'),
761
+ user_mime_type=user_config_dict.get('mime_type'),
762
+ )
763
+ final_config_dict = {
764
+ **user_config_dict,
765
+ 'http_options': http_options,
766
+ 'should_return_http_response': True,
767
+ }
768
+ response = self._upload_to_file_search_store(
769
+ file_search_store_name=file_search_store_name,
770
+ config=types.UploadToFileSearchStoreConfig(**final_config_dict),
771
+ )
772
+ if (
773
+ response.sdk_http_response is None
774
+ or response.sdk_http_response.headers is None
775
+ or (
776
+ 'x-goog-upload-url' not in response.sdk_http_response.headers
777
+ and 'X-Goog-Upload-URL' not in response.sdk_http_response.headers
778
+ )
779
+ ):
780
+ raise KeyError(
781
+ 'Failed to upload file to file search store. Upload URL did not'
782
+ ' returned from the upload request.'
783
+ )
784
+ elif 'x-goog-upload-url' in response.sdk_http_response.headers:
785
+ upload_url = response.sdk_http_response.headers['x-goog-upload-url']
786
+ else:
787
+ upload_url = response.sdk_http_response.headers['X-Goog-Upload-URL']
788
+ if isinstance(file, io.IOBase):
789
+ upload_response = self._api_client.upload_file(
790
+ file, upload_url, size_bytes, http_options=http_options
791
+ )
792
+ else:
793
+ fs_path = os.fspath(file)
794
+ upload_response = self._api_client.upload_file(
795
+ fs_path, upload_url, size_bytes, http_options=http_options
796
+ )
797
+ response_dict = _UploadToFileSearchStoreOperation_from_mldev(
798
+ upload_response.json
799
+ )
800
+ return types.UploadToFileSearchStoreOperation._from_response(
801
+ response=response_dict, kwargs={}
802
+ )
803
+
804
+
805
+ class AsyncFileSearchStores(_api_module.BaseModule):
806
+
807
+ @cached_property
808
+ def documents(self) -> AsyncDocuments:
809
+ return AsyncDocuments(self._api_client)
810
+
811
+ async def create(
812
+ self, *, config: Optional[types.CreateFileSearchStoreConfigOrDict] = None
813
+ ) -> types.FileSearchStore:
814
+ """Creates a File Search Store.
815
+
816
+ Args:
817
+ config (CreateFileSearchStoreConfig | None): Optional parameters for the
818
+ request.
819
+
820
+ Returns:
821
+ FileSearchStore
822
+ """
823
+
824
+ parameter_model = types._CreateFileSearchStoreParameters(
825
+ config=config,
826
+ )
827
+
828
+ request_url_dict: Optional[dict[str, str]]
829
+ if self._api_client.vertexai:
830
+ raise ValueError(
831
+ 'This method is only supported in the Gemini Developer client.'
832
+ )
833
+ else:
834
+ request_dict = _CreateFileSearchStoreParameters_to_mldev(parameter_model)
835
+ request_url_dict = request_dict.get('_url')
836
+ if request_url_dict:
837
+ path = 'fileSearchStores'.format_map(request_url_dict)
838
+ else:
839
+ path = 'fileSearchStores'
840
+
841
+ query_params = request_dict.get('_query')
842
+ if query_params:
843
+ path = f'{path}?{urlencode(query_params)}'
844
+ # TODO: remove the hack that pops config.
845
+ request_dict.pop('config', None)
846
+
847
+ http_options: Optional[types.HttpOptions] = None
848
+ if (
849
+ parameter_model.config is not None
850
+ and parameter_model.config.http_options is not None
851
+ ):
852
+ http_options = parameter_model.config.http_options
853
+
854
+ request_dict = _common.convert_to_dict(request_dict)
855
+ request_dict = _common.encode_unserializable_types(request_dict)
856
+
857
+ response = await self._api_client.async_request(
858
+ 'post', path, request_dict, http_options
859
+ )
860
+
861
+ response_dict = {} if not response.body else json.loads(response.body)
862
+
863
+ return_value = types.FileSearchStore._from_response(
864
+ response=response_dict, kwargs=parameter_model.model_dump()
865
+ )
866
+
867
+ self._api_client._verify_response(return_value)
868
+ return return_value
869
+
870
+ async def get(
871
+ self,
872
+ *,
873
+ name: str,
874
+ config: Optional[types.GetFileSearchStoreConfigOrDict] = None,
875
+ ) -> types.FileSearchStore:
876
+ """Gets metadata about a FileSearchStore.
877
+
878
+ Args:
879
+ name (str): The resource name of the FileSearchStore. Example:
880
+ `FileSearchStores/my-file-search-store-123`
881
+ config (GetFileSearchStoreConfig | None): Optional parameters for the
882
+ request.
883
+
884
+ Returns:
885
+ A FileSearchStore object containing the metadata.
886
+ """
887
+
888
+ parameter_model = types._GetFileSearchStoreParameters(
889
+ name=name,
890
+ config=config,
891
+ )
892
+
893
+ request_url_dict: Optional[dict[str, str]]
894
+ if self._api_client.vertexai:
895
+ raise ValueError(
896
+ 'This method is only supported in the Gemini Developer client.'
897
+ )
898
+ else:
899
+ request_dict = _GetFileSearchStoreParameters_to_mldev(parameter_model)
900
+ request_url_dict = request_dict.get('_url')
901
+ if request_url_dict:
902
+ path = '{name}'.format_map(request_url_dict)
903
+ else:
904
+ path = '{name}'
905
+
906
+ query_params = request_dict.get('_query')
907
+ if query_params:
908
+ path = f'{path}?{urlencode(query_params)}'
909
+ # TODO: remove the hack that pops config.
910
+ request_dict.pop('config', None)
911
+
912
+ http_options: Optional[types.HttpOptions] = None
913
+ if (
914
+ parameter_model.config is not None
915
+ and parameter_model.config.http_options is not None
916
+ ):
917
+ http_options = parameter_model.config.http_options
918
+
919
+ request_dict = _common.convert_to_dict(request_dict)
920
+ request_dict = _common.encode_unserializable_types(request_dict)
921
+
922
+ response = await self._api_client.async_request(
923
+ 'get', path, request_dict, http_options
924
+ )
925
+
926
+ response_dict = {} if not response.body else json.loads(response.body)
927
+
928
+ return_value = types.FileSearchStore._from_response(
929
+ response=response_dict, kwargs=parameter_model.model_dump()
930
+ )
931
+
932
+ self._api_client._verify_response(return_value)
933
+ return return_value
934
+
935
+ async def delete(
936
+ self,
937
+ *,
938
+ name: str,
939
+ config: Optional[types.DeleteFileSearchStoreConfigOrDict] = None,
940
+ ) -> None:
941
+ """Deletes a FileSearchStore.
942
+
943
+ Args:
944
+ name (str): The resource name of the FileSearchStore. Example:
945
+ `FileSearchStores/my-file-search-store-123`
946
+ config (DeleteFileSearchStoreConfig | None): Optional parameters for the
947
+ request.
948
+
949
+ Returns:
950
+ None
951
+ """
952
+
953
+ parameter_model = types._DeleteFileSearchStoreParameters(
954
+ name=name,
955
+ config=config,
956
+ )
957
+
958
+ request_url_dict: Optional[dict[str, str]]
959
+ if self._api_client.vertexai:
960
+ raise ValueError(
961
+ 'This method is only supported in the Gemini Developer client.'
962
+ )
963
+ else:
964
+ request_dict = _DeleteFileSearchStoreParameters_to_mldev(parameter_model)
965
+ request_url_dict = request_dict.get('_url')
966
+ if request_url_dict:
967
+ path = '{name}'.format_map(request_url_dict)
968
+ else:
969
+ path = '{name}'
970
+
971
+ query_params = request_dict.get('_query')
972
+ if query_params:
973
+ path = f'{path}?{urlencode(query_params)}'
974
+ # TODO: remove the hack that pops config.
975
+ request_dict.pop('config', None)
976
+
977
+ http_options: Optional[types.HttpOptions] = None
978
+ if (
979
+ parameter_model.config is not None
980
+ and parameter_model.config.http_options is not None
981
+ ):
982
+ http_options = parameter_model.config.http_options
983
+
984
+ request_dict = _common.convert_to_dict(request_dict)
985
+ request_dict = _common.encode_unserializable_types(request_dict)
986
+
987
+ response = await self._api_client.async_request(
988
+ 'delete', path, request_dict, http_options
989
+ )
990
+
991
+ async def _list(
992
+ self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
993
+ ) -> types.ListFileSearchStoresResponse:
994
+ parameter_model = types._ListFileSearchStoresParameters(
995
+ config=config,
996
+ )
997
+
998
+ request_url_dict: Optional[dict[str, str]]
999
+ if self._api_client.vertexai:
1000
+ raise ValueError(
1001
+ 'This method is only supported in the Gemini Developer client.'
1002
+ )
1003
+ else:
1004
+ request_dict = _ListFileSearchStoresParameters_to_mldev(parameter_model)
1005
+ request_url_dict = request_dict.get('_url')
1006
+ if request_url_dict:
1007
+ path = 'fileSearchStores'.format_map(request_url_dict)
1008
+ else:
1009
+ path = 'fileSearchStores'
1010
+
1011
+ query_params = request_dict.get('_query')
1012
+ if query_params:
1013
+ path = f'{path}?{urlencode(query_params)}'
1014
+ # TODO: remove the hack that pops config.
1015
+ request_dict.pop('config', None)
1016
+
1017
+ http_options: Optional[types.HttpOptions] = None
1018
+ if (
1019
+ parameter_model.config is not None
1020
+ and parameter_model.config.http_options is not None
1021
+ ):
1022
+ http_options = parameter_model.config.http_options
1023
+
1024
+ request_dict = _common.convert_to_dict(request_dict)
1025
+ request_dict = _common.encode_unserializable_types(request_dict)
1026
+
1027
+ response = await self._api_client.async_request(
1028
+ 'get', path, request_dict, http_options
1029
+ )
1030
+
1031
+ response_dict = {} if not response.body else json.loads(response.body)
1032
+
1033
+ if not self._api_client.vertexai:
1034
+ response_dict = _ListFileSearchStoresResponse_from_mldev(response_dict)
1035
+
1036
+ return_value = types.ListFileSearchStoresResponse._from_response(
1037
+ response=response_dict, kwargs=parameter_model.model_dump()
1038
+ )
1039
+
1040
+ self._api_client._verify_response(return_value)
1041
+ return return_value
1042
+
1043
+ async def _upload_to_file_search_store(
1044
+ self,
1045
+ *,
1046
+ file_search_store_name: str,
1047
+ config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
1048
+ ) -> types.UploadToFileSearchStoreResumableResponse:
1049
+ parameter_model = types._UploadToFileSearchStoreParameters(
1050
+ file_search_store_name=file_search_store_name,
1051
+ config=config,
1052
+ )
1053
+
1054
+ request_url_dict: Optional[dict[str, str]]
1055
+ if self._api_client.vertexai:
1056
+ raise ValueError(
1057
+ 'This method is only supported in the Gemini Developer client.'
1058
+ )
1059
+ else:
1060
+ request_dict = _UploadToFileSearchStoreParameters_to_mldev(
1061
+ parameter_model
1062
+ )
1063
+ request_url_dict = request_dict.get('_url')
1064
+ if request_url_dict:
1065
+ path = (
1066
+ 'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
1067
+ .format_map(request_url_dict)
1068
+ )
1069
+ else:
1070
+ path = 'upload/v1beta/{file_search_store_name}:uploadToFileSearchStore'
1071
+
1072
+ query_params = request_dict.get('_query')
1073
+ if query_params:
1074
+ path = f'{path}?{urlencode(query_params)}'
1075
+ # TODO: remove the hack that pops config.
1076
+ request_dict.pop('config', None)
1077
+
1078
+ http_options: Optional[types.HttpOptions] = None
1079
+ if (
1080
+ parameter_model.config is not None
1081
+ and parameter_model.config.http_options is not None
1082
+ ):
1083
+ http_options = parameter_model.config.http_options
1084
+
1085
+ request_dict = _common.convert_to_dict(request_dict)
1086
+ request_dict = _common.encode_unserializable_types(request_dict)
1087
+
1088
+ response = await self._api_client.async_request(
1089
+ 'post', path, request_dict, http_options
1090
+ )
1091
+
1092
+ if config is not None and getattr(
1093
+ config, 'should_return_http_response', None
1094
+ ):
1095
+ return_value = types.UploadToFileSearchStoreResumableResponse(
1096
+ sdk_http_response=response
1097
+ )
1098
+ self._api_client._verify_response(return_value)
1099
+ return return_value
1100
+
1101
+ response_dict = {} if not response.body else json.loads(response.body)
1102
+
1103
+ if not self._api_client.vertexai:
1104
+ response_dict = _UploadToFileSearchStoreResumableResponse_from_mldev(
1105
+ response_dict
1106
+ )
1107
+
1108
+ return_value = (
1109
+ types.UploadToFileSearchStoreResumableResponse._from_response(
1110
+ response=response_dict, kwargs=parameter_model.model_dump()
1111
+ )
1112
+ )
1113
+
1114
+ self._api_client._verify_response(return_value)
1115
+ return return_value
1116
+
1117
+ async def import_file(
1118
+ self,
1119
+ *,
1120
+ file_search_store_name: str,
1121
+ file_name: str,
1122
+ config: Optional[types.ImportFileConfigOrDict] = None,
1123
+ ) -> types.ImportFileOperation:
1124
+ """Imports a File from File Service to a FileSearchStore.
1125
+
1126
+ This is a long-running operation, see aip.dev/151
1127
+
1128
+ Args:
1129
+ file_search_store_name (str): The resource name of the FileSearchStore.
1130
+ Example: `fileSearchStores/my-file-search-store-123`
1131
+ file_name (str): The resource name of the File to import. Example:
1132
+ `files/abc-123`
1133
+ config (ImportFileConfig | None): Optional parameters for the request.
1134
+
1135
+ Returns:
1136
+ ImportFileOperation.
1137
+ """
1138
+
1139
+ parameter_model = types._ImportFileParameters(
1140
+ file_search_store_name=file_search_store_name,
1141
+ file_name=file_name,
1142
+ config=config,
1143
+ )
1144
+
1145
+ request_url_dict: Optional[dict[str, str]]
1146
+ if self._api_client.vertexai:
1147
+ raise ValueError(
1148
+ 'This method is only supported in the Gemini Developer client.'
1149
+ )
1150
+ else:
1151
+ request_dict = _ImportFileParameters_to_mldev(parameter_model)
1152
+ request_url_dict = request_dict.get('_url')
1153
+ if request_url_dict:
1154
+ path = '{file_search_store_name}:importFile'.format_map(
1155
+ request_url_dict
1156
+ )
1157
+ else:
1158
+ path = '{file_search_store_name}:importFile'
1159
+
1160
+ query_params = request_dict.get('_query')
1161
+ if query_params:
1162
+ path = f'{path}?{urlencode(query_params)}'
1163
+ # TODO: remove the hack that pops config.
1164
+ request_dict.pop('config', None)
1165
+
1166
+ http_options: Optional[types.HttpOptions] = None
1167
+ if (
1168
+ parameter_model.config is not None
1169
+ and parameter_model.config.http_options is not None
1170
+ ):
1171
+ http_options = parameter_model.config.http_options
1172
+
1173
+ request_dict = _common.convert_to_dict(request_dict)
1174
+ request_dict = _common.encode_unserializable_types(request_dict)
1175
+
1176
+ response = await self._api_client.async_request(
1177
+ 'post', path, request_dict, http_options
1178
+ )
1179
+
1180
+ response_dict = {} if not response.body else json.loads(response.body)
1181
+
1182
+ if not self._api_client.vertexai:
1183
+ response_dict = _ImportFileOperation_from_mldev(response_dict)
1184
+
1185
+ return_value = types.ImportFileOperation._from_response(
1186
+ response=response_dict, kwargs=parameter_model.model_dump()
1187
+ )
1188
+
1189
+ self._api_client._verify_response(return_value)
1190
+ return return_value
1191
+
1192
+ async def list(
1193
+ self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
1194
+ ) -> AsyncPager[types.FileSearchStore]:
1195
+ """Lists FileSearchStores asynchronously.
1196
+
1197
+ Args:
1198
+ config (ListFileSearchStoresConfig): Optional parameters for the request,
1199
+ such as page_size.
1200
+
1201
+ Returns:
1202
+ A Pager object that contains one page of FileSearchStores. When iterating
1203
+ over
1204
+ the pager, it automatically fetches the next page if there are more.
1205
+
1206
+ Usage:
1207
+
1208
+ .. code-block:: python
1209
+ async for file_search_store in await client.aio.file_search_stores.list():
1210
+ print(f"file search store: {file_search_store.name} -
1211
+ {file_search_store.display_name}")
1212
+ """
1213
+
1214
+ list_request = self._list
1215
+ return AsyncPager(
1216
+ 'file_search_stores',
1217
+ list_request,
1218
+ await self._list(config=config),
1219
+ config,
1220
+ )
1221
+
1222
+ async def upload_to_file_search_store(
1223
+ self,
1224
+ *,
1225
+ file_search_store_name: str,
1226
+ file: Union[str, os.PathLike[str], io.IOBase],
1227
+ config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
1228
+ ) -> types.UploadToFileSearchStoreOperation:
1229
+ """Calls the API to upload a file to the given file search store.
1230
+
1231
+ Args:
1232
+ file_search_store_name: The resource name of the FileSearchStore. Example:
1233
+ `fileSearchStores/file-search-store-123`
1234
+ file: A path to the file or an `IOBase` object to be uploaded. If it's an
1235
+ IOBase object, it must be opened in blocking (the default) mode and
1236
+ binary mode. In other words, do not use non-blocking mode or text mode.
1237
+ The given stream must be seekable, that is, it must be able to call
1238
+ `seek()` on 'path'.
1239
+ config: Optional parameters to set `diplay_name`, `mime_type` and others.
1240
+ """
1241
+ if self._api_client.vertexai:
1242
+ raise ValueError(
1243
+ 'This method is only supported in the Gemini Developer client.'
1244
+ )
1245
+ if config is None:
1246
+ user_config_dict: dict[str, Any] = {}
1247
+ elif isinstance(config, dict):
1248
+ user_config_dict = dict(config)
1249
+ else:
1250
+ user_config_dict = config.model_dump(exclude_unset=True)
1251
+
1252
+ http_options, size_bytes, _ = _extra_utils.prepare_resumable_upload(
1253
+ file,
1254
+ user_http_options=user_config_dict.get('http_options'),
1255
+ user_mime_type=user_config_dict.get('mime_type'),
1256
+ )
1257
+ final_config_dict = {
1258
+ **user_config_dict,
1259
+ 'http_options': http_options,
1260
+ 'should_return_http_response': True,
1261
+ }
1262
+ response = await self._upload_to_file_search_store(
1263
+ file_search_store_name=file_search_store_name,
1264
+ config=types.UploadToFileSearchStoreConfig(**final_config_dict),
1265
+ )
1266
+ if (
1267
+ response.sdk_http_response is None
1268
+ or response.sdk_http_response.headers is None
1269
+ or (
1270
+ 'x-goog-upload-url' not in response.sdk_http_response.headers
1271
+ and 'X-Goog-Upload-URL' not in response.sdk_http_response.headers
1272
+ )
1273
+ ):
1274
+ raise KeyError(
1275
+ 'Failed to upload file to file search store. Upload URL did not'
1276
+ ' returned from the upload request.'
1277
+ )
1278
+ elif 'x-goog-upload-url' in response.sdk_http_response.headers:
1279
+ upload_url = response.sdk_http_response.headers['x-goog-upload-url']
1280
+ else:
1281
+ upload_url = response.sdk_http_response.headers['X-Goog-Upload-URL']
1282
+ if isinstance(file, io.IOBase):
1283
+ upload_response = await self._api_client.async_upload_file(
1284
+ file, upload_url, size_bytes, http_options=http_options
1285
+ )
1286
+ else:
1287
+ fs_path = os.fspath(file)
1288
+ upload_response = await self._api_client.async_upload_file(
1289
+ fs_path, upload_url, size_bytes, http_options=http_options
1290
+ )
1291
+ response_dict = _UploadToFileSearchStoreOperation_from_mldev(
1292
+ upload_response.json
1293
+ )
1294
+ return types.UploadToFileSearchStoreOperation._from_response(
1295
+ response=response_dict, kwargs={}
1296
+ )