google-genai 1.2.0__py3-none-any.whl → 1.4.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 +160 -59
- google/genai/_api_module.py +6 -1
- google/genai/_automatic_function_calling_util.py +12 -12
- google/genai/_common.py +14 -2
- google/genai/_extra_utils.py +14 -8
- google/genai/_replay_api_client.py +35 -3
- google/genai/_test_api_client.py +8 -8
- google/genai/_transformers.py +169 -48
- google/genai/batches.py +176 -127
- google/genai/caches.py +315 -214
- google/genai/chats.py +179 -35
- google/genai/client.py +16 -6
- google/genai/errors.py +19 -5
- google/genai/files.py +161 -115
- google/genai/live.py +137 -105
- google/genai/models.py +1553 -734
- google/genai/operations.py +635 -0
- google/genai/pagers.py +5 -5
- google/genai/tunings.py +166 -103
- google/genai/types.py +590 -142
- google/genai/version.py +1 -1
- {google_genai-1.2.0.dist-info → google_genai-1.4.0.dist-info}/METADATA +94 -12
- google_genai-1.4.0.dist-info/RECORD +27 -0
- {google_genai-1.2.0.dist-info → google_genai-1.4.0.dist-info}/WHEEL +1 -1
- google/genai/_operations.py +0 -365
- google_genai-1.2.0.dist-info/RECORD +0 -27
- {google_genai-1.2.0.dist-info → google_genai-1.4.0.dist-info}/LICENSE +0 -0
- {google_genai-1.2.0.dist-info → google_genai-1.4.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,635 @@
|
|
1
|
+
# Copyright 2024 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
|
+
import logging
|
19
|
+
from typing import Any, Optional, Union
|
20
|
+
from urllib.parse import urlencode
|
21
|
+
from . import _api_module
|
22
|
+
from . import _common
|
23
|
+
from . import _transformers as t
|
24
|
+
from . import types
|
25
|
+
from ._api_client import BaseApiClient
|
26
|
+
from ._common import get_value_by_path as getv
|
27
|
+
from ._common import set_value_by_path as setv
|
28
|
+
|
29
|
+
logger = logging.getLogger('google_genai.operations')
|
30
|
+
|
31
|
+
|
32
|
+
def _GetOperationParameters_to_mldev(
|
33
|
+
api_client: BaseApiClient,
|
34
|
+
from_object: Union[dict, object],
|
35
|
+
parent_object: Optional[dict] = None,
|
36
|
+
) -> dict:
|
37
|
+
to_object: dict[str, Any] = {}
|
38
|
+
if getv(from_object, ['operation_name']) is not None:
|
39
|
+
setv(
|
40
|
+
to_object,
|
41
|
+
['_url', 'operationName'],
|
42
|
+
getv(from_object, ['operation_name']),
|
43
|
+
)
|
44
|
+
|
45
|
+
if getv(from_object, ['config']) is not None:
|
46
|
+
setv(to_object, ['config'], getv(from_object, ['config']))
|
47
|
+
|
48
|
+
return to_object
|
49
|
+
|
50
|
+
|
51
|
+
def _GetOperationParameters_to_vertex(
|
52
|
+
api_client: BaseApiClient,
|
53
|
+
from_object: Union[dict, object],
|
54
|
+
parent_object: Optional[dict] = None,
|
55
|
+
) -> dict:
|
56
|
+
to_object: dict[str, Any] = {}
|
57
|
+
if getv(from_object, ['operation_name']) is not None:
|
58
|
+
setv(
|
59
|
+
to_object,
|
60
|
+
['_url', 'operationName'],
|
61
|
+
getv(from_object, ['operation_name']),
|
62
|
+
)
|
63
|
+
|
64
|
+
if getv(from_object, ['config']) is not None:
|
65
|
+
setv(to_object, ['config'], getv(from_object, ['config']))
|
66
|
+
|
67
|
+
return to_object
|
68
|
+
|
69
|
+
|
70
|
+
def _FetchPredictOperationParameters_to_mldev(
|
71
|
+
api_client: BaseApiClient,
|
72
|
+
from_object: Union[dict, object],
|
73
|
+
parent_object: Optional[dict] = None,
|
74
|
+
) -> dict:
|
75
|
+
to_object: dict[str, Any] = {}
|
76
|
+
if getv(from_object, ['operation_name']) is not None:
|
77
|
+
raise ValueError('operation_name parameter is not supported in Gemini API.')
|
78
|
+
|
79
|
+
if getv(from_object, ['resource_name']) is not None:
|
80
|
+
raise ValueError('resource_name parameter is not supported in Gemini API.')
|
81
|
+
|
82
|
+
if getv(from_object, ['config']) is not None:
|
83
|
+
raise ValueError('config parameter is not supported in Gemini API.')
|
84
|
+
|
85
|
+
return to_object
|
86
|
+
|
87
|
+
|
88
|
+
def _FetchPredictOperationParameters_to_vertex(
|
89
|
+
api_client: BaseApiClient,
|
90
|
+
from_object: Union[dict, object],
|
91
|
+
parent_object: Optional[dict] = None,
|
92
|
+
) -> dict:
|
93
|
+
to_object: dict[str, Any] = {}
|
94
|
+
if getv(from_object, ['operation_name']) is not None:
|
95
|
+
setv(to_object, ['operationName'], getv(from_object, ['operation_name']))
|
96
|
+
|
97
|
+
if getv(from_object, ['resource_name']) is not None:
|
98
|
+
setv(
|
99
|
+
to_object,
|
100
|
+
['_url', 'resourceName'],
|
101
|
+
getv(from_object, ['resource_name']),
|
102
|
+
)
|
103
|
+
|
104
|
+
if getv(from_object, ['config']) is not None:
|
105
|
+
setv(to_object, ['config'], getv(from_object, ['config']))
|
106
|
+
|
107
|
+
return to_object
|
108
|
+
|
109
|
+
|
110
|
+
def _Video_from_mldev(
|
111
|
+
api_client: BaseApiClient,
|
112
|
+
from_object: Union[dict, object],
|
113
|
+
parent_object: Optional[dict] = None,
|
114
|
+
) -> dict:
|
115
|
+
to_object: dict[str, Any] = {}
|
116
|
+
if getv(from_object, ['uri']) is not None:
|
117
|
+
setv(to_object, ['uri'], getv(from_object, ['uri']))
|
118
|
+
|
119
|
+
if getv(from_object, ['encodedVideo']) is not None:
|
120
|
+
setv(
|
121
|
+
to_object,
|
122
|
+
['video_bytes'],
|
123
|
+
t.t_bytes(api_client, getv(from_object, ['encodedVideo'])),
|
124
|
+
)
|
125
|
+
|
126
|
+
if getv(from_object, ['encoding']) is not None:
|
127
|
+
setv(to_object, ['mime_type'], getv(from_object, ['encoding']))
|
128
|
+
|
129
|
+
return to_object
|
130
|
+
|
131
|
+
|
132
|
+
def _Video_from_vertex(
|
133
|
+
api_client: BaseApiClient,
|
134
|
+
from_object: Union[dict, object],
|
135
|
+
parent_object: Optional[dict] = None,
|
136
|
+
) -> dict:
|
137
|
+
to_object: dict[str, Any] = {}
|
138
|
+
if getv(from_object, ['gcsUri']) is not None:
|
139
|
+
setv(to_object, ['uri'], getv(from_object, ['gcsUri']))
|
140
|
+
|
141
|
+
if getv(from_object, ['bytesBase64Encoded']) is not None:
|
142
|
+
setv(
|
143
|
+
to_object,
|
144
|
+
['video_bytes'],
|
145
|
+
t.t_bytes(api_client, getv(from_object, ['bytesBase64Encoded'])),
|
146
|
+
)
|
147
|
+
|
148
|
+
if getv(from_object, ['mimeType']) is not None:
|
149
|
+
setv(to_object, ['mime_type'], getv(from_object, ['mimeType']))
|
150
|
+
|
151
|
+
return to_object
|
152
|
+
|
153
|
+
|
154
|
+
def _GeneratedVideo_from_mldev(
|
155
|
+
api_client: BaseApiClient,
|
156
|
+
from_object: Union[dict, object],
|
157
|
+
parent_object: Optional[dict] = None,
|
158
|
+
) -> dict:
|
159
|
+
to_object: dict[str, Any] = {}
|
160
|
+
if getv(from_object, ['_self']) is not None:
|
161
|
+
setv(
|
162
|
+
to_object,
|
163
|
+
['video'],
|
164
|
+
_Video_from_mldev(api_client, getv(from_object, ['_self']), to_object),
|
165
|
+
)
|
166
|
+
|
167
|
+
return to_object
|
168
|
+
|
169
|
+
|
170
|
+
def _GeneratedVideo_from_vertex(
|
171
|
+
api_client: BaseApiClient,
|
172
|
+
from_object: Union[dict, object],
|
173
|
+
parent_object: Optional[dict] = None,
|
174
|
+
) -> dict:
|
175
|
+
to_object: dict[str, Any] = {}
|
176
|
+
if getv(from_object, ['_self']) is not None:
|
177
|
+
setv(
|
178
|
+
to_object,
|
179
|
+
['video'],
|
180
|
+
_Video_from_vertex(api_client, getv(from_object, ['_self']), to_object),
|
181
|
+
)
|
182
|
+
|
183
|
+
return to_object
|
184
|
+
|
185
|
+
|
186
|
+
def _GenerateVideosResponse_from_mldev(
|
187
|
+
api_client: BaseApiClient,
|
188
|
+
from_object: Union[dict, object],
|
189
|
+
parent_object: Optional[dict] = None,
|
190
|
+
) -> dict:
|
191
|
+
to_object: dict[str, Any] = {}
|
192
|
+
if getv(from_object, ['videos']) is not None:
|
193
|
+
setv(
|
194
|
+
to_object,
|
195
|
+
['generated_videos'],
|
196
|
+
[
|
197
|
+
_GeneratedVideo_from_mldev(api_client, item, to_object)
|
198
|
+
for item in getv(from_object, ['videos'])
|
199
|
+
],
|
200
|
+
)
|
201
|
+
|
202
|
+
if getv(from_object, ['raiMediaFilteredCount']) is not None:
|
203
|
+
setv(
|
204
|
+
to_object,
|
205
|
+
['rai_media_filtered_count'],
|
206
|
+
getv(from_object, ['raiMediaFilteredCount']),
|
207
|
+
)
|
208
|
+
|
209
|
+
if getv(from_object, ['raiMediaFilteredReasons']) is not None:
|
210
|
+
setv(
|
211
|
+
to_object,
|
212
|
+
['rai_media_filtered_reasons'],
|
213
|
+
getv(from_object, ['raiMediaFilteredReasons']),
|
214
|
+
)
|
215
|
+
|
216
|
+
return to_object
|
217
|
+
|
218
|
+
|
219
|
+
def _GenerateVideosResponse_from_vertex(
|
220
|
+
api_client: BaseApiClient,
|
221
|
+
from_object: Union[dict, object],
|
222
|
+
parent_object: Optional[dict] = None,
|
223
|
+
) -> dict:
|
224
|
+
to_object: dict[str, Any] = {}
|
225
|
+
if getv(from_object, ['videos']) is not None:
|
226
|
+
setv(
|
227
|
+
to_object,
|
228
|
+
['generated_videos'],
|
229
|
+
[
|
230
|
+
_GeneratedVideo_from_vertex(api_client, item, to_object)
|
231
|
+
for item in getv(from_object, ['videos'])
|
232
|
+
],
|
233
|
+
)
|
234
|
+
|
235
|
+
if getv(from_object, ['raiMediaFilteredCount']) is not None:
|
236
|
+
setv(
|
237
|
+
to_object,
|
238
|
+
['rai_media_filtered_count'],
|
239
|
+
getv(from_object, ['raiMediaFilteredCount']),
|
240
|
+
)
|
241
|
+
|
242
|
+
if getv(from_object, ['raiMediaFilteredReasons']) is not None:
|
243
|
+
setv(
|
244
|
+
to_object,
|
245
|
+
['rai_media_filtered_reasons'],
|
246
|
+
getv(from_object, ['raiMediaFilteredReasons']),
|
247
|
+
)
|
248
|
+
|
249
|
+
return to_object
|
250
|
+
|
251
|
+
|
252
|
+
def _GenerateVideosOperation_from_mldev(
|
253
|
+
api_client: BaseApiClient,
|
254
|
+
from_object: Union[dict, object],
|
255
|
+
parent_object: Optional[dict] = None,
|
256
|
+
) -> dict:
|
257
|
+
to_object: dict[str, Any] = {}
|
258
|
+
if getv(from_object, ['name']) is not None:
|
259
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
260
|
+
|
261
|
+
if getv(from_object, ['metadata']) is not None:
|
262
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
263
|
+
|
264
|
+
if getv(from_object, ['done']) is not None:
|
265
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
266
|
+
|
267
|
+
if getv(from_object, ['error']) is not None:
|
268
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
269
|
+
|
270
|
+
if getv(from_object, ['response']) is not None:
|
271
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
272
|
+
|
273
|
+
if getv(from_object, ['response', 'generateVideoResponse']) is not None:
|
274
|
+
setv(
|
275
|
+
to_object,
|
276
|
+
['result'],
|
277
|
+
_GenerateVideosResponse_from_mldev(
|
278
|
+
api_client,
|
279
|
+
getv(from_object, ['response', 'generateVideoResponse']),
|
280
|
+
to_object,
|
281
|
+
),
|
282
|
+
)
|
283
|
+
|
284
|
+
return to_object
|
285
|
+
|
286
|
+
|
287
|
+
def _GenerateVideosOperation_from_vertex(
|
288
|
+
api_client: BaseApiClient,
|
289
|
+
from_object: Union[dict, object],
|
290
|
+
parent_object: Optional[dict] = None,
|
291
|
+
) -> dict:
|
292
|
+
to_object: dict[str, Any] = {}
|
293
|
+
if getv(from_object, ['name']) is not None:
|
294
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
295
|
+
|
296
|
+
if getv(from_object, ['metadata']) is not None:
|
297
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
298
|
+
|
299
|
+
if getv(from_object, ['done']) is not None:
|
300
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
301
|
+
|
302
|
+
if getv(from_object, ['error']) is not None:
|
303
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
304
|
+
|
305
|
+
if getv(from_object, ['response']) is not None:
|
306
|
+
setv(to_object, ['response'], getv(from_object, ['response']))
|
307
|
+
|
308
|
+
if getv(from_object, ['response']) is not None:
|
309
|
+
setv(
|
310
|
+
to_object,
|
311
|
+
['result'],
|
312
|
+
_GenerateVideosResponse_from_vertex(
|
313
|
+
api_client, getv(from_object, ['response']), to_object
|
314
|
+
),
|
315
|
+
)
|
316
|
+
|
317
|
+
return to_object
|
318
|
+
|
319
|
+
|
320
|
+
class Operations(_api_module.BaseModule):
|
321
|
+
|
322
|
+
def _get_operation(
|
323
|
+
self,
|
324
|
+
*,
|
325
|
+
operation_name: str,
|
326
|
+
config: Optional[types.GetOperationConfigOrDict] = None,
|
327
|
+
) -> types.GenerateVideosOperation:
|
328
|
+
parameter_model = types._GetOperationParameters(
|
329
|
+
operation_name=operation_name,
|
330
|
+
config=config,
|
331
|
+
)
|
332
|
+
|
333
|
+
request_url_dict: Optional[dict[str, str]]
|
334
|
+
|
335
|
+
if self._api_client.vertexai:
|
336
|
+
request_dict = _GetOperationParameters_to_vertex(
|
337
|
+
self._api_client, parameter_model
|
338
|
+
)
|
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}'
|
344
|
+
else:
|
345
|
+
request_dict = _GetOperationParameters_to_mldev(
|
346
|
+
self._api_client, parameter_model
|
347
|
+
)
|
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}'
|
353
|
+
query_params = request_dict.get('_query')
|
354
|
+
if query_params:
|
355
|
+
path = f'{path}?{urlencode(query_params)}'
|
356
|
+
# TODO: remove the hack that pops config.
|
357
|
+
request_dict.pop('config', None)
|
358
|
+
|
359
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
360
|
+
if isinstance(config, dict):
|
361
|
+
http_options = config.get('http_options', None)
|
362
|
+
elif hasattr(config, 'http_options'):
|
363
|
+
http_options = config.http_options
|
364
|
+
|
365
|
+
request_dict = _common.convert_to_dict(request_dict)
|
366
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
367
|
+
|
368
|
+
response_dict = self._api_client.request(
|
369
|
+
'get', path, request_dict, http_options
|
370
|
+
)
|
371
|
+
|
372
|
+
if self._api_client.vertexai:
|
373
|
+
response_dict = _GenerateVideosOperation_from_vertex(
|
374
|
+
self._api_client, response_dict
|
375
|
+
)
|
376
|
+
else:
|
377
|
+
response_dict = _GenerateVideosOperation_from_mldev(
|
378
|
+
self._api_client, response_dict
|
379
|
+
)
|
380
|
+
|
381
|
+
return_value = types.GenerateVideosOperation._from_response(
|
382
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
383
|
+
)
|
384
|
+
self._api_client._verify_response(return_value)
|
385
|
+
return return_value
|
386
|
+
|
387
|
+
def _fetch_predict_operation(
|
388
|
+
self,
|
389
|
+
*,
|
390
|
+
operation_name: str,
|
391
|
+
resource_name: str,
|
392
|
+
config: Optional[types.FetchPredictOperationConfigOrDict] = None,
|
393
|
+
) -> types.GenerateVideosOperation:
|
394
|
+
parameter_model = types._FetchPredictOperationParameters(
|
395
|
+
operation_name=operation_name,
|
396
|
+
resource_name=resource_name,
|
397
|
+
config=config,
|
398
|
+
)
|
399
|
+
|
400
|
+
request_url_dict: Optional[dict[str, str]]
|
401
|
+
if not self._api_client.vertexai:
|
402
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
403
|
+
else:
|
404
|
+
request_dict = _FetchPredictOperationParameters_to_vertex(
|
405
|
+
self._api_client, parameter_model
|
406
|
+
)
|
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'
|
414
|
+
|
415
|
+
query_params = request_dict.get('_query')
|
416
|
+
if query_params:
|
417
|
+
path = f'{path}?{urlencode(query_params)}'
|
418
|
+
# TODO: remove the hack that pops config.
|
419
|
+
request_dict.pop('config', None)
|
420
|
+
|
421
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
422
|
+
if isinstance(config, dict):
|
423
|
+
http_options = config.get('http_options', None)
|
424
|
+
elif hasattr(config, 'http_options'):
|
425
|
+
http_options = config.http_options
|
426
|
+
|
427
|
+
request_dict = _common.convert_to_dict(request_dict)
|
428
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
429
|
+
|
430
|
+
response_dict = self._api_client.request(
|
431
|
+
'post', path, request_dict, http_options
|
432
|
+
)
|
433
|
+
|
434
|
+
if self._api_client.vertexai:
|
435
|
+
response_dict = _GenerateVideosOperation_from_vertex(
|
436
|
+
self._api_client, response_dict
|
437
|
+
)
|
438
|
+
else:
|
439
|
+
response_dict = _GenerateVideosOperation_from_mldev(
|
440
|
+
self._api_client, response_dict
|
441
|
+
)
|
442
|
+
|
443
|
+
return_value = types.GenerateVideosOperation._from_response(
|
444
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
445
|
+
)
|
446
|
+
self._api_client._verify_response(return_value)
|
447
|
+
return return_value
|
448
|
+
|
449
|
+
@_common.experimental_warning(
|
450
|
+
'This method is experimental and may change in future versions.'
|
451
|
+
)
|
452
|
+
def get(
|
453
|
+
self,
|
454
|
+
operation: types.GenerateVideosOperation,
|
455
|
+
*,
|
456
|
+
config: Optional[types.GetOperationConfigOrDict] = None,
|
457
|
+
) -> types.GenerateVideosOperation:
|
458
|
+
"""Gets the status of an operation."""
|
459
|
+
# Currently, only GenerateVideosOperation is supported.
|
460
|
+
# TODO(b/398040607): Support short form names
|
461
|
+
operation_name = operation.name
|
462
|
+
if not operation_name:
|
463
|
+
raise ValueError('Operation name is empty.')
|
464
|
+
|
465
|
+
# TODO(b/398233524): Cast operation types
|
466
|
+
if self._api_client.vertexai:
|
467
|
+
resource_name = operation_name.rpartition('/operations/')[0]
|
468
|
+
return self._fetch_predict_operation(
|
469
|
+
operation_name=operation_name,
|
470
|
+
resource_name=resource_name,
|
471
|
+
config=config,
|
472
|
+
)
|
473
|
+
else:
|
474
|
+
return self._get_operation(
|
475
|
+
operation_name=operation_name,
|
476
|
+
config=config,
|
477
|
+
)
|
478
|
+
|
479
|
+
|
480
|
+
class AsyncOperations(_api_module.BaseModule):
|
481
|
+
|
482
|
+
async def _get_operation(
|
483
|
+
self,
|
484
|
+
*,
|
485
|
+
operation_name: str,
|
486
|
+
config: Optional[types.GetOperationConfigOrDict] = None,
|
487
|
+
) -> types.GenerateVideosOperation:
|
488
|
+
parameter_model = types._GetOperationParameters(
|
489
|
+
operation_name=operation_name,
|
490
|
+
config=config,
|
491
|
+
)
|
492
|
+
|
493
|
+
request_url_dict: Optional[dict[str, str]]
|
494
|
+
|
495
|
+
if self._api_client.vertexai:
|
496
|
+
request_dict = _GetOperationParameters_to_vertex(
|
497
|
+
self._api_client, parameter_model
|
498
|
+
)
|
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}'
|
504
|
+
else:
|
505
|
+
request_dict = _GetOperationParameters_to_mldev(
|
506
|
+
self._api_client, parameter_model
|
507
|
+
)
|
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}'
|
513
|
+
query_params = request_dict.get('_query')
|
514
|
+
if query_params:
|
515
|
+
path = f'{path}?{urlencode(query_params)}'
|
516
|
+
# TODO: remove the hack that pops config.
|
517
|
+
request_dict.pop('config', None)
|
518
|
+
|
519
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
520
|
+
if isinstance(config, dict):
|
521
|
+
http_options = config.get('http_options', None)
|
522
|
+
elif hasattr(config, 'http_options'):
|
523
|
+
http_options = config.http_options
|
524
|
+
|
525
|
+
request_dict = _common.convert_to_dict(request_dict)
|
526
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
527
|
+
|
528
|
+
response_dict = await self._api_client.async_request(
|
529
|
+
'get', path, request_dict, http_options
|
530
|
+
)
|
531
|
+
|
532
|
+
if self._api_client.vertexai:
|
533
|
+
response_dict = _GenerateVideosOperation_from_vertex(
|
534
|
+
self._api_client, response_dict
|
535
|
+
)
|
536
|
+
else:
|
537
|
+
response_dict = _GenerateVideosOperation_from_mldev(
|
538
|
+
self._api_client, response_dict
|
539
|
+
)
|
540
|
+
|
541
|
+
return_value = types.GenerateVideosOperation._from_response(
|
542
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
543
|
+
)
|
544
|
+
self._api_client._verify_response(return_value)
|
545
|
+
return return_value
|
546
|
+
|
547
|
+
async def _fetch_predict_operation(
|
548
|
+
self,
|
549
|
+
*,
|
550
|
+
operation_name: str,
|
551
|
+
resource_name: str,
|
552
|
+
config: Optional[types.FetchPredictOperationConfigOrDict] = None,
|
553
|
+
) -> types.GenerateVideosOperation:
|
554
|
+
parameter_model = types._FetchPredictOperationParameters(
|
555
|
+
operation_name=operation_name,
|
556
|
+
resource_name=resource_name,
|
557
|
+
config=config,
|
558
|
+
)
|
559
|
+
|
560
|
+
request_url_dict: Optional[dict[str, str]]
|
561
|
+
if not self._api_client.vertexai:
|
562
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
563
|
+
else:
|
564
|
+
request_dict = _FetchPredictOperationParameters_to_vertex(
|
565
|
+
self._api_client, parameter_model
|
566
|
+
)
|
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'
|
574
|
+
|
575
|
+
query_params = request_dict.get('_query')
|
576
|
+
if query_params:
|
577
|
+
path = f'{path}?{urlencode(query_params)}'
|
578
|
+
# TODO: remove the hack that pops config.
|
579
|
+
request_dict.pop('config', None)
|
580
|
+
|
581
|
+
http_options: Optional[types.HttpOptionsOrDict] = None
|
582
|
+
if isinstance(config, dict):
|
583
|
+
http_options = config.get('http_options', None)
|
584
|
+
elif hasattr(config, 'http_options'):
|
585
|
+
http_options = config.http_options
|
586
|
+
|
587
|
+
request_dict = _common.convert_to_dict(request_dict)
|
588
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
589
|
+
|
590
|
+
response_dict = await self._api_client.async_request(
|
591
|
+
'post', path, request_dict, http_options
|
592
|
+
)
|
593
|
+
|
594
|
+
if self._api_client.vertexai:
|
595
|
+
response_dict = _GenerateVideosOperation_from_vertex(
|
596
|
+
self._api_client, response_dict
|
597
|
+
)
|
598
|
+
else:
|
599
|
+
response_dict = _GenerateVideosOperation_from_mldev(
|
600
|
+
self._api_client, response_dict
|
601
|
+
)
|
602
|
+
|
603
|
+
return_value = types.GenerateVideosOperation._from_response(
|
604
|
+
response=response_dict, kwargs=parameter_model.model_dump()
|
605
|
+
)
|
606
|
+
self._api_client._verify_response(return_value)
|
607
|
+
return return_value
|
608
|
+
|
609
|
+
@_common.experimental_warning(
|
610
|
+
'This method is experimental and may change in future versions.'
|
611
|
+
)
|
612
|
+
async def get(
|
613
|
+
self,
|
614
|
+
operation: types.GenerateVideosOperation,
|
615
|
+
*,
|
616
|
+
config: Optional[types.GetOperationConfigOrDict] = None,
|
617
|
+
) -> types.GenerateVideosOperation:
|
618
|
+
"""Gets the status of an operation."""
|
619
|
+
# Currently, only GenerateVideosOperation is supported.
|
620
|
+
operation_name = operation.name
|
621
|
+
if not operation_name:
|
622
|
+
raise ValueError('Operation name is empty.')
|
623
|
+
|
624
|
+
if self._api_client.vertexai:
|
625
|
+
resource_name = operation_name.rpartition('/operations/')[0]
|
626
|
+
return await self._fetch_predict_operation(
|
627
|
+
operation_name=operation_name,
|
628
|
+
resource_name=resource_name,
|
629
|
+
config=config,
|
630
|
+
)
|
631
|
+
else:
|
632
|
+
return await self._get_operation(
|
633
|
+
operation_name=operation_name,
|
634
|
+
config=config,
|
635
|
+
)
|
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,
|
21
|
+
from typing import Any, Awaitable, Callable, Generic, Iterator, Literal, TypeVar
|
22
22
|
|
23
23
|
T = TypeVar('T')
|
24
24
|
|
@@ -33,7 +33,7 @@ class _BasePager(Generic[T]):
|
|
33
33
|
def __init__(
|
34
34
|
self,
|
35
35
|
name: PagedItem,
|
36
|
-
request: Callable[
|
36
|
+
request: Callable[..., Any],
|
37
37
|
response: Any,
|
38
38
|
config: Any,
|
39
39
|
):
|
@@ -191,18 +191,18 @@ class AsyncPager(_BasePager[T]):
|
|
191
191
|
def __init__(
|
192
192
|
self,
|
193
193
|
name: PagedItem,
|
194
|
-
request: Callable[
|
194
|
+
request: Callable[..., Awaitable[Any]],
|
195
195
|
response: Any,
|
196
196
|
config: Any,
|
197
197
|
):
|
198
198
|
super().__init__(name, request, response, config)
|
199
199
|
|
200
|
-
def __aiter__(self) ->
|
200
|
+
def __aiter__(self) -> T:
|
201
201
|
"""Returns an async iterator over the items."""
|
202
202
|
self._idx = 0
|
203
203
|
return self
|
204
204
|
|
205
|
-
async def __anext__(self) ->
|
205
|
+
async def __anext__(self) -> T:
|
206
206
|
"""Returns the next item asynchronously."""
|
207
207
|
if self._idx >= len(self):
|
208
208
|
try:
|