google-genai 1.3.0__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/_api_client.py +143 -69
- google/genai/_api_module.py +1 -1
- google/genai/_automatic_function_calling_util.py +15 -15
- google/genai/_common.py +6 -3
- google/genai/_extra_utils.py +62 -46
- google/genai/_replay_api_client.py +73 -4
- google/genai/_test_api_client.py +8 -8
- google/genai/_transformers.py +194 -66
- google/genai/batches.py +180 -134
- google/genai/caches.py +316 -216
- google/genai/chats.py +179 -35
- google/genai/client.py +3 -3
- google/genai/errors.py +1 -2
- google/genai/files.py +175 -119
- google/genai/live.py +73 -64
- google/genai/models.py +898 -637
- google/genai/operations.py +96 -66
- google/genai/pagers.py +16 -7
- google/genai/tunings.py +172 -112
- google/genai/types.py +228 -178
- google/genai/version.py +1 -1
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/METADATA +8 -1
- google_genai-1.5.0.dist-info/RECORD +27 -0
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/WHEEL +1 -1
- google_genai-1.3.0.dist-info/RECORD +0 -27
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/LICENSE +0 -0
- {google_genai-1.3.0.dist-info → google_genai-1.5.0.dist-info}/top_level.txt +0 -0
google/genai/operations.py
CHANGED
@@ -16,13 +16,13 @@
|
|
16
16
|
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
17
17
|
|
18
18
|
import logging
|
19
|
-
from typing import Optional, Union
|
19
|
+
from typing import Any, Optional, Union
|
20
20
|
from urllib.parse import urlencode
|
21
21
|
from . import _api_module
|
22
22
|
from . import _common
|
23
23
|
from . import _transformers as t
|
24
24
|
from . import types
|
25
|
-
from ._api_client import
|
25
|
+
from ._api_client import BaseApiClient
|
26
26
|
from ._common import get_value_by_path as getv
|
27
27
|
from ._common import set_value_by_path as setv
|
28
28
|
|
@@ -30,11 +30,11 @@ logger = logging.getLogger('google_genai.operations')
|
|
30
30
|
|
31
31
|
|
32
32
|
def _GetOperationParameters_to_mldev(
|
33
|
-
api_client:
|
33
|
+
api_client: BaseApiClient,
|
34
34
|
from_object: Union[dict, object],
|
35
|
-
parent_object: dict = None,
|
35
|
+
parent_object: Optional[dict] = None,
|
36
36
|
) -> dict:
|
37
|
-
to_object = {}
|
37
|
+
to_object: dict[str, Any] = {}
|
38
38
|
if getv(from_object, ['operation_name']) is not None:
|
39
39
|
setv(
|
40
40
|
to_object,
|
@@ -49,11 +49,11 @@ def _GetOperationParameters_to_mldev(
|
|
49
49
|
|
50
50
|
|
51
51
|
def _GetOperationParameters_to_vertex(
|
52
|
-
api_client:
|
52
|
+
api_client: BaseApiClient,
|
53
53
|
from_object: Union[dict, object],
|
54
|
-
parent_object: dict = None,
|
54
|
+
parent_object: Optional[dict] = None,
|
55
55
|
) -> dict:
|
56
|
-
to_object = {}
|
56
|
+
to_object: dict[str, Any] = {}
|
57
57
|
if getv(from_object, ['operation_name']) is not None:
|
58
58
|
setv(
|
59
59
|
to_object,
|
@@ -68,11 +68,11 @@ def _GetOperationParameters_to_vertex(
|
|
68
68
|
|
69
69
|
|
70
70
|
def _FetchPredictOperationParameters_to_mldev(
|
71
|
-
api_client:
|
71
|
+
api_client: BaseApiClient,
|
72
72
|
from_object: Union[dict, object],
|
73
|
-
parent_object: dict = None,
|
73
|
+
parent_object: Optional[dict] = None,
|
74
74
|
) -> dict:
|
75
|
-
to_object = {}
|
75
|
+
to_object: dict[str, Any] = {}
|
76
76
|
if getv(from_object, ['operation_name']) is not None:
|
77
77
|
raise ValueError('operation_name parameter is not supported in Gemini API.')
|
78
78
|
|
@@ -86,11 +86,11 @@ def _FetchPredictOperationParameters_to_mldev(
|
|
86
86
|
|
87
87
|
|
88
88
|
def _FetchPredictOperationParameters_to_vertex(
|
89
|
-
api_client:
|
89
|
+
api_client: BaseApiClient,
|
90
90
|
from_object: Union[dict, object],
|
91
|
-
parent_object: dict = None,
|
91
|
+
parent_object: Optional[dict] = None,
|
92
92
|
) -> dict:
|
93
|
-
to_object = {}
|
93
|
+
to_object: dict[str, Any] = {}
|
94
94
|
if getv(from_object, ['operation_name']) is not None:
|
95
95
|
setv(to_object, ['operationName'], getv(from_object, ['operation_name']))
|
96
96
|
|
@@ -108,19 +108,19 @@ def _FetchPredictOperationParameters_to_vertex(
|
|
108
108
|
|
109
109
|
|
110
110
|
def _Video_from_mldev(
|
111
|
-
api_client:
|
111
|
+
api_client: BaseApiClient,
|
112
112
|
from_object: Union[dict, object],
|
113
|
-
parent_object: dict = None,
|
113
|
+
parent_object: Optional[dict] = None,
|
114
114
|
) -> dict:
|
115
|
-
to_object = {}
|
116
|
-
if getv(from_object, ['uri']) is not None:
|
117
|
-
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
115
|
+
to_object: dict[str, Any] = {}
|
116
|
+
if getv(from_object, ['video', 'uri']) is not None:
|
117
|
+
setv(to_object, ['uri'], getv(from_object, ['video', 'uri']))
|
118
118
|
|
119
|
-
if getv(from_object, ['encodedVideo']) is not None:
|
119
|
+
if getv(from_object, ['video', 'encodedVideo']) is not None:
|
120
120
|
setv(
|
121
121
|
to_object,
|
122
122
|
['video_bytes'],
|
123
|
-
t.t_bytes(api_client, getv(from_object, ['encodedVideo'])),
|
123
|
+
t.t_bytes(api_client, getv(from_object, ['video', 'encodedVideo'])),
|
124
124
|
)
|
125
125
|
|
126
126
|
if getv(from_object, ['encoding']) is not None:
|
@@ -130,11 +130,11 @@ def _Video_from_mldev(
|
|
130
130
|
|
131
131
|
|
132
132
|
def _Video_from_vertex(
|
133
|
-
api_client:
|
133
|
+
api_client: BaseApiClient,
|
134
134
|
from_object: Union[dict, object],
|
135
|
-
parent_object: dict = None,
|
135
|
+
parent_object: Optional[dict] = None,
|
136
136
|
) -> dict:
|
137
|
-
to_object = {}
|
137
|
+
to_object: dict[str, Any] = {}
|
138
138
|
if getv(from_object, ['gcsUri']) is not None:
|
139
139
|
setv(to_object, ['uri'], getv(from_object, ['gcsUri']))
|
140
140
|
|
@@ -152,11 +152,11 @@ def _Video_from_vertex(
|
|
152
152
|
|
153
153
|
|
154
154
|
def _GeneratedVideo_from_mldev(
|
155
|
-
api_client:
|
155
|
+
api_client: BaseApiClient,
|
156
156
|
from_object: Union[dict, object],
|
157
|
-
parent_object: dict = None,
|
157
|
+
parent_object: Optional[dict] = None,
|
158
158
|
) -> dict:
|
159
|
-
to_object = {}
|
159
|
+
to_object: dict[str, Any] = {}
|
160
160
|
if getv(from_object, ['_self']) is not None:
|
161
161
|
setv(
|
162
162
|
to_object,
|
@@ -168,11 +168,11 @@ def _GeneratedVideo_from_mldev(
|
|
168
168
|
|
169
169
|
|
170
170
|
def _GeneratedVideo_from_vertex(
|
171
|
-
api_client:
|
171
|
+
api_client: BaseApiClient,
|
172
172
|
from_object: Union[dict, object],
|
173
|
-
parent_object: dict = None,
|
173
|
+
parent_object: Optional[dict] = None,
|
174
174
|
) -> dict:
|
175
|
-
to_object = {}
|
175
|
+
to_object: dict[str, Any] = {}
|
176
176
|
if getv(from_object, ['_self']) is not None:
|
177
177
|
setv(
|
178
178
|
to_object,
|
@@ -184,18 +184,18 @@ def _GeneratedVideo_from_vertex(
|
|
184
184
|
|
185
185
|
|
186
186
|
def _GenerateVideosResponse_from_mldev(
|
187
|
-
api_client:
|
187
|
+
api_client: BaseApiClient,
|
188
188
|
from_object: Union[dict, object],
|
189
|
-
parent_object: dict = None,
|
189
|
+
parent_object: Optional[dict] = None,
|
190
190
|
) -> dict:
|
191
|
-
to_object = {}
|
192
|
-
if getv(from_object, ['
|
191
|
+
to_object: dict[str, Any] = {}
|
192
|
+
if getv(from_object, ['generatedSamples']) is not None:
|
193
193
|
setv(
|
194
194
|
to_object,
|
195
195
|
['generated_videos'],
|
196
196
|
[
|
197
197
|
_GeneratedVideo_from_mldev(api_client, item, to_object)
|
198
|
-
for item in getv(from_object, ['
|
198
|
+
for item in getv(from_object, ['generatedSamples'])
|
199
199
|
],
|
200
200
|
)
|
201
201
|
|
@@ -217,11 +217,11 @@ def _GenerateVideosResponse_from_mldev(
|
|
217
217
|
|
218
218
|
|
219
219
|
def _GenerateVideosResponse_from_vertex(
|
220
|
-
api_client:
|
220
|
+
api_client: BaseApiClient,
|
221
221
|
from_object: Union[dict, object],
|
222
|
-
parent_object: dict = None,
|
222
|
+
parent_object: Optional[dict] = None,
|
223
223
|
) -> dict:
|
224
|
-
to_object = {}
|
224
|
+
to_object: dict[str, Any] = {}
|
225
225
|
if getv(from_object, ['videos']) is not None:
|
226
226
|
setv(
|
227
227
|
to_object,
|
@@ -250,11 +250,11 @@ def _GenerateVideosResponse_from_vertex(
|
|
250
250
|
|
251
251
|
|
252
252
|
def _GenerateVideosOperation_from_mldev(
|
253
|
-
api_client:
|
253
|
+
api_client: BaseApiClient,
|
254
254
|
from_object: Union[dict, object],
|
255
|
-
parent_object: dict = None,
|
255
|
+
parent_object: Optional[dict] = None,
|
256
256
|
) -> dict:
|
257
|
-
to_object = {}
|
257
|
+
to_object: dict[str, Any] = {}
|
258
258
|
if getv(from_object, ['name']) is not None:
|
259
259
|
setv(to_object, ['name'], getv(from_object, ['name']))
|
260
260
|
|
@@ -285,11 +285,11 @@ def _GenerateVideosOperation_from_mldev(
|
|
285
285
|
|
286
286
|
|
287
287
|
def _GenerateVideosOperation_from_vertex(
|
288
|
-
api_client:
|
288
|
+
api_client: BaseApiClient,
|
289
289
|
from_object: Union[dict, object],
|
290
|
-
parent_object: dict = None,
|
290
|
+
parent_object: Optional[dict] = None,
|
291
291
|
) -> dict:
|
292
|
-
to_object = {}
|
292
|
+
to_object: dict[str, Any] = {}
|
293
293
|
if getv(from_object, ['name']) is not None:
|
294
294
|
setv(to_object, ['name'], getv(from_object, ['name']))
|
295
295
|
|
@@ -330,26 +330,36 @@ class Operations(_api_module.BaseModule):
|
|
330
330
|
config=config,
|
331
331
|
)
|
332
332
|
|
333
|
+
request_url_dict: Optional[dict[str, str]]
|
334
|
+
|
333
335
|
if self._api_client.vertexai:
|
334
336
|
request_dict = _GetOperationParameters_to_vertex(
|
335
337
|
self._api_client, parameter_model
|
336
338
|
)
|
337
|
-
|
339
|
+
request_url_dict = request_dict.get('_url')
|
340
|
+
if request_url_dict:
|
341
|
+
path = '{operationName}'.format_map(request_url_dict)
|
342
|
+
else:
|
343
|
+
path = '{operationName}'
|
338
344
|
else:
|
339
345
|
request_dict = _GetOperationParameters_to_mldev(
|
340
346
|
self._api_client, parameter_model
|
341
347
|
)
|
342
|
-
|
348
|
+
request_url_dict = request_dict.get('_url')
|
349
|
+
if request_url_dict:
|
350
|
+
path = '{operationName}'.format_map(request_url_dict)
|
351
|
+
else:
|
352
|
+
path = '{operationName}'
|
343
353
|
query_params = request_dict.get('_query')
|
344
354
|
if query_params:
|
345
355
|
path = f'{path}?{urlencode(query_params)}'
|
346
356
|
# TODO: remove the hack that pops config.
|
347
357
|
request_dict.pop('config', None)
|
348
358
|
|
349
|
-
http_options = None
|
359
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
350
360
|
if isinstance(config, dict):
|
351
361
|
http_options = config.get('http_options', None)
|
352
|
-
elif hasattr(config, 'http_options'):
|
362
|
+
elif hasattr(config, 'http_options') and config is not None:
|
353
363
|
http_options = config.http_options
|
354
364
|
|
355
365
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -369,7 +379,7 @@ class Operations(_api_module.BaseModule):
|
|
369
379
|
)
|
370
380
|
|
371
381
|
return_value = types.GenerateVideosOperation._from_response(
|
372
|
-
response=response_dict, kwargs=parameter_model
|
382
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
373
383
|
)
|
374
384
|
self._api_client._verify_response(return_value)
|
375
385
|
return return_value
|
@@ -387,15 +397,20 @@ class Operations(_api_module.BaseModule):
|
|
387
397
|
config=config,
|
388
398
|
)
|
389
399
|
|
400
|
+
request_url_dict: Optional[dict[str, str]]
|
390
401
|
if not self._api_client.vertexai:
|
391
402
|
raise ValueError('This method is only supported in the Vertex AI client.')
|
392
403
|
else:
|
393
404
|
request_dict = _FetchPredictOperationParameters_to_vertex(
|
394
405
|
self._api_client, parameter_model
|
395
406
|
)
|
396
|
-
|
397
|
-
|
398
|
-
|
407
|
+
request_url_dict = request_dict.get('_url')
|
408
|
+
if request_url_dict:
|
409
|
+
path = '{resourceName}:fetchPredictOperation'.format_map(
|
410
|
+
request_url_dict
|
411
|
+
)
|
412
|
+
else:
|
413
|
+
path = '{resourceName}:fetchPredictOperation'
|
399
414
|
|
400
415
|
query_params = request_dict.get('_query')
|
401
416
|
if query_params:
|
@@ -403,10 +418,10 @@ class Operations(_api_module.BaseModule):
|
|
403
418
|
# TODO: remove the hack that pops config.
|
404
419
|
request_dict.pop('config', None)
|
405
420
|
|
406
|
-
http_options = None
|
421
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
407
422
|
if isinstance(config, dict):
|
408
423
|
http_options = config.get('http_options', None)
|
409
|
-
elif hasattr(config, 'http_options'):
|
424
|
+
elif hasattr(config, 'http_options') and config is not None:
|
410
425
|
http_options = config.http_options
|
411
426
|
|
412
427
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -426,7 +441,7 @@ class Operations(_api_module.BaseModule):
|
|
426
441
|
)
|
427
442
|
|
428
443
|
return_value = types.GenerateVideosOperation._from_response(
|
429
|
-
response=response_dict, kwargs=parameter_model
|
444
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
430
445
|
)
|
431
446
|
self._api_client._verify_response(return_value)
|
432
447
|
return return_value
|
@@ -475,26 +490,36 @@ class AsyncOperations(_api_module.BaseModule):
|
|
475
490
|
config=config,
|
476
491
|
)
|
477
492
|
|
493
|
+
request_url_dict: Optional[dict[str, str]]
|
494
|
+
|
478
495
|
if self._api_client.vertexai:
|
479
496
|
request_dict = _GetOperationParameters_to_vertex(
|
480
497
|
self._api_client, parameter_model
|
481
498
|
)
|
482
|
-
|
499
|
+
request_url_dict = request_dict.get('_url')
|
500
|
+
if request_url_dict:
|
501
|
+
path = '{operationName}'.format_map(request_url_dict)
|
502
|
+
else:
|
503
|
+
path = '{operationName}'
|
483
504
|
else:
|
484
505
|
request_dict = _GetOperationParameters_to_mldev(
|
485
506
|
self._api_client, parameter_model
|
486
507
|
)
|
487
|
-
|
508
|
+
request_url_dict = request_dict.get('_url')
|
509
|
+
if request_url_dict:
|
510
|
+
path = '{operationName}'.format_map(request_url_dict)
|
511
|
+
else:
|
512
|
+
path = '{operationName}'
|
488
513
|
query_params = request_dict.get('_query')
|
489
514
|
if query_params:
|
490
515
|
path = f'{path}?{urlencode(query_params)}'
|
491
516
|
# TODO: remove the hack that pops config.
|
492
517
|
request_dict.pop('config', None)
|
493
518
|
|
494
|
-
http_options = None
|
519
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
495
520
|
if isinstance(config, dict):
|
496
521
|
http_options = config.get('http_options', None)
|
497
|
-
elif hasattr(config, 'http_options'):
|
522
|
+
elif hasattr(config, 'http_options') and config is not None:
|
498
523
|
http_options = config.http_options
|
499
524
|
|
500
525
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -514,7 +539,7 @@ class AsyncOperations(_api_module.BaseModule):
|
|
514
539
|
)
|
515
540
|
|
516
541
|
return_value = types.GenerateVideosOperation._from_response(
|
517
|
-
response=response_dict, kwargs=parameter_model
|
542
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
518
543
|
)
|
519
544
|
self._api_client._verify_response(return_value)
|
520
545
|
return return_value
|
@@ -532,15 +557,20 @@ class AsyncOperations(_api_module.BaseModule):
|
|
532
557
|
config=config,
|
533
558
|
)
|
534
559
|
|
560
|
+
request_url_dict: Optional[dict[str, str]]
|
535
561
|
if not self._api_client.vertexai:
|
536
562
|
raise ValueError('This method is only supported in the Vertex AI client.')
|
537
563
|
else:
|
538
564
|
request_dict = _FetchPredictOperationParameters_to_vertex(
|
539
565
|
self._api_client, parameter_model
|
540
566
|
)
|
541
|
-
|
542
|
-
|
543
|
-
|
567
|
+
request_url_dict = request_dict.get('_url')
|
568
|
+
if request_url_dict:
|
569
|
+
path = '{resourceName}:fetchPredictOperation'.format_map(
|
570
|
+
request_url_dict
|
571
|
+
)
|
572
|
+
else:
|
573
|
+
path = '{resourceName}:fetchPredictOperation'
|
544
574
|
|
545
575
|
query_params = request_dict.get('_query')
|
546
576
|
if query_params:
|
@@ -548,10 +578,10 @@ class AsyncOperations(_api_module.BaseModule):
|
|
548
578
|
# TODO: remove the hack that pops config.
|
549
579
|
request_dict.pop('config', None)
|
550
580
|
|
551
|
-
http_options = None
|
581
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
552
582
|
if isinstance(config, dict):
|
553
583
|
http_options = config.get('http_options', None)
|
554
|
-
elif hasattr(config, 'http_options'):
|
584
|
+
elif hasattr(config, 'http_options') and config is not None:
|
555
585
|
http_options = config.http_options
|
556
586
|
|
557
587
|
request_dict = _common.convert_to_dict(request_dict)
|
@@ -571,7 +601,7 @@ class AsyncOperations(_api_module.BaseModule):
|
|
571
601
|
)
|
572
602
|
|
573
603
|
return_value = types.GenerateVideosOperation._from_response(
|
574
|
-
response=response_dict, kwargs=parameter_model
|
604
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
575
605
|
)
|
576
606
|
self._api_client._verify_response(return_value)
|
577
607
|
return return_value
|
google/genai/pagers.py
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
# pylint: disable=protected-access
|
19
19
|
|
20
20
|
import copy
|
21
|
-
from typing import Any, AsyncIterator,
|
21
|
+
from typing import Any, AsyncIterator,Awaitable, Callable, Generic, Iterator, Literal, TypeVar
|
22
22
|
|
23
23
|
T = TypeVar('T')
|
24
24
|
|
@@ -30,10 +30,10 @@ PagedItem = Literal[
|
|
30
30
|
class _BasePager(Generic[T]):
|
31
31
|
"""Base pager class for iterating through paginated results."""
|
32
32
|
|
33
|
-
def
|
33
|
+
def _init_page(
|
34
34
|
self,
|
35
35
|
name: PagedItem,
|
36
|
-
request: Callable[
|
36
|
+
request: Callable[..., Any],
|
37
37
|
response: Any,
|
38
38
|
config: Any,
|
39
39
|
):
|
@@ -54,6 +54,15 @@ class _BasePager(Generic[T]):
|
|
54
54
|
|
55
55
|
self._page_size = request_config.get('page_size', len(self._page))
|
56
56
|
|
57
|
+
def __init__(
|
58
|
+
self,
|
59
|
+
name: PagedItem,
|
60
|
+
request: Callable[..., Any],
|
61
|
+
response: Any,
|
62
|
+
config: Any,
|
63
|
+
):
|
64
|
+
self._init_page(name, request, response, config)
|
65
|
+
|
57
66
|
@property
|
58
67
|
def page(self) -> list[T]:
|
59
68
|
"""Returns the current page, which is a list of items.
|
@@ -72,7 +81,7 @@ class _BasePager(Generic[T]):
|
|
72
81
|
return self._page
|
73
82
|
|
74
83
|
@property
|
75
|
-
def name(self) ->
|
84
|
+
def name(self) -> PagedItem:
|
76
85
|
"""Returns the type of paged item (for example, ``batch_jobs``).
|
77
86
|
|
78
87
|
Usage:
|
@@ -139,7 +148,7 @@ class _BasePager(Generic[T]):
|
|
139
148
|
Args:
|
140
149
|
response: The response object from the API request.
|
141
150
|
"""
|
142
|
-
self.
|
151
|
+
self._init_page(self.name, self._request, response, self.config)
|
143
152
|
|
144
153
|
|
145
154
|
class Pager(_BasePager[T]):
|
@@ -191,7 +200,7 @@ class AsyncPager(_BasePager[T]):
|
|
191
200
|
def __init__(
|
192
201
|
self,
|
193
202
|
name: PagedItem,
|
194
|
-
request: Callable[
|
203
|
+
request: Callable[..., Awaitable[Any]],
|
195
204
|
response: Any,
|
196
205
|
config: Any,
|
197
206
|
):
|
@@ -202,7 +211,7 @@ class AsyncPager(_BasePager[T]):
|
|
202
211
|
self._idx = 0
|
203
212
|
return self
|
204
213
|
|
205
|
-
async def __anext__(self) ->
|
214
|
+
async def __anext__(self) -> T:
|
206
215
|
"""Returns the next item asynchronously."""
|
207
216
|
if self._idx >= len(self):
|
208
217
|
try:
|