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,532 @@
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 partial
19
+ import json
20
+ import logging
21
+ from typing import Any, Optional, Union
22
+ from urllib.parse import urlencode
23
+
24
+ from . import _api_module
25
+ from . import _common
26
+ from . import types
27
+ from ._common import get_value_by_path as getv
28
+ from ._common import set_value_by_path as setv
29
+ from .pagers import AsyncPager, Pager
30
+
31
+
32
+ logger = logging.getLogger('google_genai.documents')
33
+
34
+
35
+ def _DeleteDocumentConfig_to_mldev(
36
+ from_object: Union[dict[str, Any], object],
37
+ parent_object: Optional[dict[str, Any]] = None,
38
+ ) -> dict[str, Any]:
39
+ to_object: dict[str, Any] = {}
40
+
41
+ if getv(from_object, ['force']) is not None:
42
+ setv(parent_object, ['_query', 'force'], getv(from_object, ['force']))
43
+
44
+ return to_object
45
+
46
+
47
+ def _DeleteDocumentParameters_to_mldev(
48
+ from_object: Union[dict[str, Any], object],
49
+ parent_object: Optional[dict[str, Any]] = None,
50
+ ) -> dict[str, Any]:
51
+ to_object: dict[str, Any] = {}
52
+ if getv(from_object, ['name']) is not None:
53
+ setv(to_object, ['_url', 'name'], getv(from_object, ['name']))
54
+
55
+ if getv(from_object, ['config']) is not None:
56
+ _DeleteDocumentConfig_to_mldev(getv(from_object, ['config']), to_object)
57
+
58
+ return to_object
59
+
60
+
61
+ def _GetDocumentParameters_to_mldev(
62
+ from_object: Union[dict[str, Any], object],
63
+ parent_object: Optional[dict[str, Any]] = None,
64
+ ) -> dict[str, Any]:
65
+ to_object: dict[str, Any] = {}
66
+ if getv(from_object, ['name']) is not None:
67
+ setv(to_object, ['_url', 'name'], getv(from_object, ['name']))
68
+
69
+ return to_object
70
+
71
+
72
+ def _ListDocumentsConfig_to_mldev(
73
+ from_object: Union[dict[str, Any], object],
74
+ parent_object: Optional[dict[str, Any]] = None,
75
+ ) -> dict[str, Any]:
76
+ to_object: dict[str, Any] = {}
77
+
78
+ if getv(from_object, ['page_size']) is not None:
79
+ setv(
80
+ parent_object, ['_query', 'pageSize'], getv(from_object, ['page_size'])
81
+ )
82
+
83
+ if getv(from_object, ['page_token']) is not None:
84
+ setv(
85
+ parent_object,
86
+ ['_query', 'pageToken'],
87
+ getv(from_object, ['page_token']),
88
+ )
89
+
90
+ return to_object
91
+
92
+
93
+ def _ListDocumentsParameters_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, ['parent']) is not None:
99
+ setv(to_object, ['_url', 'parent'], getv(from_object, ['parent']))
100
+
101
+ if getv(from_object, ['config']) is not None:
102
+ _ListDocumentsConfig_to_mldev(getv(from_object, ['config']), to_object)
103
+
104
+ return to_object
105
+
106
+
107
+ def _ListDocumentsResponse_from_mldev(
108
+ from_object: Union[dict[str, Any], object],
109
+ parent_object: Optional[dict[str, Any]] = None,
110
+ ) -> dict[str, Any]:
111
+ to_object: dict[str, Any] = {}
112
+ if getv(from_object, ['sdkHttpResponse']) is not None:
113
+ setv(
114
+ to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
115
+ )
116
+
117
+ if getv(from_object, ['nextPageToken']) is not None:
118
+ setv(to_object, ['next_page_token'], getv(from_object, ['nextPageToken']))
119
+
120
+ if getv(from_object, ['documents']) is not None:
121
+ setv(
122
+ to_object,
123
+ ['documents'],
124
+ [item for item in getv(from_object, ['documents'])],
125
+ )
126
+
127
+ return to_object
128
+
129
+
130
+ class Documents(_api_module.BaseModule):
131
+
132
+ def get(
133
+ self, *, name: str, config: Optional[types.GetDocumentConfigOrDict] = None
134
+ ) -> types.Document:
135
+ """Gets metadata about a Document.
136
+
137
+ Args:
138
+ name (str): The resource name of the Document.
139
+ Example: ragStores/rag-store-foo/documents/documents-bar
140
+ config (GetDocumentConfig | None): Optional parameters for the request.
141
+
142
+ Returns:
143
+ The Document.
144
+ """
145
+
146
+ parameter_model = types._GetDocumentParameters(
147
+ name=name,
148
+ config=config,
149
+ )
150
+
151
+ request_url_dict: Optional[dict[str, str]]
152
+ if self._api_client.vertexai:
153
+ raise ValueError(
154
+ 'This method is only supported in the Gemini Developer client.'
155
+ )
156
+ else:
157
+ request_dict = _GetDocumentParameters_to_mldev(parameter_model)
158
+ request_url_dict = request_dict.get('_url')
159
+ if request_url_dict:
160
+ path = '{name}'.format_map(request_url_dict)
161
+ else:
162
+ path = '{name}'
163
+
164
+ query_params = request_dict.get('_query')
165
+ if query_params:
166
+ path = f'{path}?{urlencode(query_params)}'
167
+ # TODO: remove the hack that pops config.
168
+ request_dict.pop('config', None)
169
+
170
+ http_options: Optional[types.HttpOptions] = None
171
+ if (
172
+ parameter_model.config is not None
173
+ and parameter_model.config.http_options is not None
174
+ ):
175
+ http_options = parameter_model.config.http_options
176
+
177
+ request_dict = _common.convert_to_dict(request_dict)
178
+ request_dict = _common.encode_unserializable_types(request_dict)
179
+
180
+ response = self._api_client.request('get', path, request_dict, http_options)
181
+
182
+ response_dict = {} if not response.body else json.loads(response.body)
183
+
184
+ return_value = types.Document._from_response(
185
+ response=response_dict, kwargs=parameter_model.model_dump()
186
+ )
187
+
188
+ self._api_client._verify_response(return_value)
189
+ return return_value
190
+
191
+ def delete(
192
+ self,
193
+ *,
194
+ name: str,
195
+ config: Optional[types.DeleteDocumentConfigOrDict] = None,
196
+ ) -> None:
197
+ """Deletes a Document.
198
+
199
+ Args:
200
+ name (str): The resource name of the Document.
201
+ Example: ragStores/rag-store-foo/documents/documents-bar
202
+ config (DeleteDocumentConfig | None): Optional parameters for the request.
203
+
204
+ Returns:
205
+ None
206
+ """
207
+
208
+ parameter_model = types._DeleteDocumentParameters(
209
+ name=name,
210
+ config=config,
211
+ )
212
+
213
+ request_url_dict: Optional[dict[str, str]]
214
+ if self._api_client.vertexai:
215
+ raise ValueError(
216
+ 'This method is only supported in the Gemini Developer client.'
217
+ )
218
+ else:
219
+ request_dict = _DeleteDocumentParameters_to_mldev(parameter_model)
220
+ request_url_dict = request_dict.get('_url')
221
+ if request_url_dict:
222
+ path = '{name}'.format_map(request_url_dict)
223
+ else:
224
+ path = '{name}'
225
+
226
+ query_params = request_dict.get('_query')
227
+ if query_params:
228
+ path = f'{path}?{urlencode(query_params)}'
229
+ # TODO: remove the hack that pops config.
230
+ request_dict.pop('config', None)
231
+
232
+ http_options: Optional[types.HttpOptions] = None
233
+ if (
234
+ parameter_model.config is not None
235
+ and parameter_model.config.http_options is not None
236
+ ):
237
+ http_options = parameter_model.config.http_options
238
+
239
+ request_dict = _common.convert_to_dict(request_dict)
240
+ request_dict = _common.encode_unserializable_types(request_dict)
241
+
242
+ response = self._api_client.request(
243
+ 'delete', path, request_dict, http_options
244
+ )
245
+
246
+ def _list(
247
+ self,
248
+ *,
249
+ parent: str,
250
+ config: Optional[types.ListDocumentsConfigOrDict] = None,
251
+ ) -> types.ListDocumentsResponse:
252
+ parameter_model = types._ListDocumentsParameters(
253
+ parent=parent,
254
+ config=config,
255
+ )
256
+
257
+ request_url_dict: Optional[dict[str, str]]
258
+ if self._api_client.vertexai:
259
+ raise ValueError(
260
+ 'This method is only supported in the Gemini Developer client.'
261
+ )
262
+ else:
263
+ request_dict = _ListDocumentsParameters_to_mldev(parameter_model)
264
+ request_url_dict = request_dict.get('_url')
265
+ if request_url_dict:
266
+ path = '{parent}/documents'.format_map(request_url_dict)
267
+ else:
268
+ path = '{parent}/documents'
269
+
270
+ query_params = request_dict.get('_query')
271
+ if query_params:
272
+ path = f'{path}?{urlencode(query_params)}'
273
+ # TODO: remove the hack that pops config.
274
+ request_dict.pop('config', None)
275
+
276
+ http_options: Optional[types.HttpOptions] = None
277
+ if (
278
+ parameter_model.config is not None
279
+ and parameter_model.config.http_options is not None
280
+ ):
281
+ http_options = parameter_model.config.http_options
282
+
283
+ request_dict = _common.convert_to_dict(request_dict)
284
+ request_dict = _common.encode_unserializable_types(request_dict)
285
+
286
+ response = self._api_client.request('get', path, request_dict, http_options)
287
+
288
+ response_dict = {} if not response.body else json.loads(response.body)
289
+
290
+ if not self._api_client.vertexai:
291
+ response_dict = _ListDocumentsResponse_from_mldev(response_dict)
292
+
293
+ return_value = types.ListDocumentsResponse._from_response(
294
+ response=response_dict, kwargs=parameter_model.model_dump()
295
+ )
296
+
297
+ self._api_client._verify_response(return_value)
298
+ return return_value
299
+
300
+ def list(
301
+ self,
302
+ *,
303
+ parent: str,
304
+ config: Optional[types.ListDocumentsConfigOrDict] = None,
305
+ ) -> Pager[types.Document]:
306
+ """Lists documents.
307
+
308
+ Args:
309
+ parent (str): The name of the RagStore containing the Documents.
310
+ config (ListDocumentsConfig): Optional configuration for the list request.
311
+
312
+ Returns:
313
+ A Pager object that contains one page of documents. When iterating over
314
+ the pager, it automatically fetches the next page if there are more.
315
+ Usage:
316
+ .. code-block:: python
317
+ for document in client.documents.list(parent='rag_store_name'):
318
+ print(f"document: {document.name} - {document.display_name}")
319
+ """
320
+
321
+ list_request = partial(self._list, parent=parent)
322
+ return Pager(
323
+ 'documents',
324
+ list_request,
325
+ self._list(parent=parent, config=config),
326
+ config,
327
+ )
328
+
329
+
330
+ class AsyncDocuments(_api_module.BaseModule):
331
+
332
+ async def get(
333
+ self, *, name: str, config: Optional[types.GetDocumentConfigOrDict] = None
334
+ ) -> types.Document:
335
+ """Gets metadata about a Document.
336
+
337
+ Args:
338
+ name (str): The resource name of the Document.
339
+ Example: ragStores/rag-store-foo/documents/documents-bar
340
+ config (GetDocumentConfig | None): Optional parameters for the request.
341
+
342
+ Returns:
343
+ The Document.
344
+ """
345
+
346
+ parameter_model = types._GetDocumentParameters(
347
+ name=name,
348
+ config=config,
349
+ )
350
+
351
+ request_url_dict: Optional[dict[str, str]]
352
+ if self._api_client.vertexai:
353
+ raise ValueError(
354
+ 'This method is only supported in the Gemini Developer client.'
355
+ )
356
+ else:
357
+ request_dict = _GetDocumentParameters_to_mldev(parameter_model)
358
+ request_url_dict = request_dict.get('_url')
359
+ if request_url_dict:
360
+ path = '{name}'.format_map(request_url_dict)
361
+ else:
362
+ path = '{name}'
363
+
364
+ query_params = request_dict.get('_query')
365
+ if query_params:
366
+ path = f'{path}?{urlencode(query_params)}'
367
+ # TODO: remove the hack that pops config.
368
+ request_dict.pop('config', None)
369
+
370
+ http_options: Optional[types.HttpOptions] = None
371
+ if (
372
+ parameter_model.config is not None
373
+ and parameter_model.config.http_options is not None
374
+ ):
375
+ http_options = parameter_model.config.http_options
376
+
377
+ request_dict = _common.convert_to_dict(request_dict)
378
+ request_dict = _common.encode_unserializable_types(request_dict)
379
+
380
+ response = await self._api_client.async_request(
381
+ 'get', path, request_dict, http_options
382
+ )
383
+
384
+ response_dict = {} if not response.body else json.loads(response.body)
385
+
386
+ return_value = types.Document._from_response(
387
+ response=response_dict, kwargs=parameter_model.model_dump()
388
+ )
389
+
390
+ self._api_client._verify_response(return_value)
391
+ return return_value
392
+
393
+ async def delete(
394
+ self,
395
+ *,
396
+ name: str,
397
+ config: Optional[types.DeleteDocumentConfigOrDict] = None,
398
+ ) -> None:
399
+ """Deletes a Document.
400
+
401
+ Args:
402
+ name (str): The resource name of the Document.
403
+ Example: ragStores/rag-store-foo/documents/documents-bar
404
+ config (DeleteDocumentConfig | None): Optional parameters for the request.
405
+
406
+ Returns:
407
+ None
408
+ """
409
+
410
+ parameter_model = types._DeleteDocumentParameters(
411
+ name=name,
412
+ config=config,
413
+ )
414
+
415
+ request_url_dict: Optional[dict[str, str]]
416
+ if self._api_client.vertexai:
417
+ raise ValueError(
418
+ 'This method is only supported in the Gemini Developer client.'
419
+ )
420
+ else:
421
+ request_dict = _DeleteDocumentParameters_to_mldev(parameter_model)
422
+ request_url_dict = request_dict.get('_url')
423
+ if request_url_dict:
424
+ path = '{name}'.format_map(request_url_dict)
425
+ else:
426
+ path = '{name}'
427
+
428
+ query_params = request_dict.get('_query')
429
+ if query_params:
430
+ path = f'{path}?{urlencode(query_params)}'
431
+ # TODO: remove the hack that pops config.
432
+ request_dict.pop('config', None)
433
+
434
+ http_options: Optional[types.HttpOptions] = None
435
+ if (
436
+ parameter_model.config is not None
437
+ and parameter_model.config.http_options is not None
438
+ ):
439
+ http_options = parameter_model.config.http_options
440
+
441
+ request_dict = _common.convert_to_dict(request_dict)
442
+ request_dict = _common.encode_unserializable_types(request_dict)
443
+
444
+ response = await self._api_client.async_request(
445
+ 'delete', path, request_dict, http_options
446
+ )
447
+
448
+ async def _list(
449
+ self,
450
+ *,
451
+ parent: str,
452
+ config: Optional[types.ListDocumentsConfigOrDict] = None,
453
+ ) -> types.ListDocumentsResponse:
454
+ parameter_model = types._ListDocumentsParameters(
455
+ parent=parent,
456
+ config=config,
457
+ )
458
+
459
+ request_url_dict: Optional[dict[str, str]]
460
+ if self._api_client.vertexai:
461
+ raise ValueError(
462
+ 'This method is only supported in the Gemini Developer client.'
463
+ )
464
+ else:
465
+ request_dict = _ListDocumentsParameters_to_mldev(parameter_model)
466
+ request_url_dict = request_dict.get('_url')
467
+ if request_url_dict:
468
+ path = '{parent}/documents'.format_map(request_url_dict)
469
+ else:
470
+ path = '{parent}/documents'
471
+
472
+ query_params = request_dict.get('_query')
473
+ if query_params:
474
+ path = f'{path}?{urlencode(query_params)}'
475
+ # TODO: remove the hack that pops config.
476
+ request_dict.pop('config', None)
477
+
478
+ http_options: Optional[types.HttpOptions] = None
479
+ if (
480
+ parameter_model.config is not None
481
+ and parameter_model.config.http_options is not None
482
+ ):
483
+ http_options = parameter_model.config.http_options
484
+
485
+ request_dict = _common.convert_to_dict(request_dict)
486
+ request_dict = _common.encode_unserializable_types(request_dict)
487
+
488
+ response = await self._api_client.async_request(
489
+ 'get', path, request_dict, http_options
490
+ )
491
+
492
+ response_dict = {} if not response.body else json.loads(response.body)
493
+
494
+ if not self._api_client.vertexai:
495
+ response_dict = _ListDocumentsResponse_from_mldev(response_dict)
496
+
497
+ return_value = types.ListDocumentsResponse._from_response(
498
+ response=response_dict, kwargs=parameter_model.model_dump()
499
+ )
500
+
501
+ self._api_client._verify_response(return_value)
502
+ return return_value
503
+
504
+ async def list(
505
+ self,
506
+ *,
507
+ parent: str,
508
+ config: Optional[types.ListDocumentsConfigOrDict] = None,
509
+ ) -> AsyncPager[types.Document]:
510
+ """Lists documents asynchronously.
511
+
512
+ Args:
513
+ parent (str): The name of the RagStore containing the Documents.
514
+ config (ListDocumentsConfig): Optional configuration for the list request.
515
+
516
+ Returns:
517
+ A Pager object that contains one page of documents. When iterating over
518
+ the pager, it automatically fetches the next page if there are more.
519
+ Usage:
520
+ .. code-block:: python
521
+ async for document in await
522
+ client.aio.documents.list(parent='rag_store_name'):
523
+ print(f"document: {document.name} - {document.display_name}")
524
+ """
525
+
526
+ list_request = partial(self._list, parent=parent)
527
+ return AsyncPager(
528
+ 'documents',
529
+ list_request,
530
+ await self._list(parent=parent, config=config),
531
+ config,
532
+ )