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.
- google/genai/__init__.py +4 -2
- google/genai/_adapters.py +55 -0
- google/genai/_api_client.py +1301 -299
- google/genai/_api_module.py +1 -1
- google/genai/_automatic_function_calling_util.py +54 -33
- google/genai/_base_transformers.py +26 -0
- google/genai/_base_url.py +50 -0
- google/genai/_common.py +560 -59
- google/genai/_extra_utils.py +371 -38
- google/genai/_live_converters.py +1467 -0
- google/genai/_local_tokenizer_loader.py +214 -0
- google/genai/_mcp_utils.py +117 -0
- google/genai/_operations_converters.py +394 -0
- google/genai/_replay_api_client.py +204 -92
- google/genai/_test_api_client.py +1 -1
- google/genai/_tokens_converters.py +520 -0
- google/genai/_transformers.py +633 -233
- google/genai/batches.py +1733 -538
- google/genai/caches.py +678 -1012
- google/genai/chats.py +48 -38
- google/genai/client.py +142 -15
- google/genai/documents.py +532 -0
- google/genai/errors.py +141 -35
- google/genai/file_search_stores.py +1296 -0
- google/genai/files.py +312 -744
- google/genai/live.py +617 -367
- google/genai/live_music.py +197 -0
- google/genai/local_tokenizer.py +395 -0
- google/genai/models.py +3598 -3116
- google/genai/operations.py +201 -362
- google/genai/pagers.py +23 -7
- google/genai/py.typed +1 -0
- google/genai/tokens.py +362 -0
- google/genai/tunings.py +1274 -496
- google/genai/types.py +14535 -5454
- google/genai/version.py +2 -2
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/METADATA +736 -234
- google_genai-1.53.0.dist-info/RECORD +41 -0
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/WHEEL +1 -1
- google_genai-1.7.0.dist-info/RECORD +0 -27
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info/licenses}/LICENSE +0 -0
- {google_genai-1.7.0.dist-info → google_genai-1.53.0.dist-info}/top_level.txt +0 -0
google/genai/operations.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -15,81 +15,25 @@
|
|
|
15
15
|
|
|
16
16
|
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
17
17
|
|
|
18
|
+
import json
|
|
18
19
|
import logging
|
|
19
|
-
from typing import Any, Optional, Union
|
|
20
|
+
from typing import Any, Optional, TypeVar, Union
|
|
20
21
|
from urllib.parse import urlencode
|
|
22
|
+
|
|
21
23
|
from . import _api_module
|
|
22
24
|
from . import _common
|
|
23
|
-
from . import _transformers as t
|
|
24
25
|
from . import types
|
|
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
|
|
|
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
29
|
|
|
48
|
-
|
|
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
|
|
30
|
+
logger = logging.getLogger('google_genai.operations')
|
|
86
31
|
|
|
87
32
|
|
|
88
33
|
def _FetchPredictOperationParameters_to_vertex(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
) -> dict:
|
|
34
|
+
from_object: Union[dict[str, Any], object],
|
|
35
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
36
|
+
) -> dict[str, Any]:
|
|
93
37
|
to_object: dict[str, Any] = {}
|
|
94
38
|
if getv(from_object, ['operation_name']) is not None:
|
|
95
39
|
setv(to_object, ['operationName'], getv(from_object, ['operation_name']))
|
|
@@ -101,217 +45,47 @@ def _FetchPredictOperationParameters_to_vertex(
|
|
|
101
45
|
getv(from_object, ['resource_name']),
|
|
102
46
|
)
|
|
103
47
|
|
|
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, ['video', 'uri']) is not None:
|
|
117
|
-
setv(to_object, ['uri'], getv(from_object, ['video', 'uri']))
|
|
118
|
-
|
|
119
|
-
if getv(from_object, ['video', 'encodedVideo']) is not None:
|
|
120
|
-
setv(
|
|
121
|
-
to_object,
|
|
122
|
-
['video_bytes'],
|
|
123
|
-
t.t_bytes(api_client, getv(from_object, ['video', '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
48
|
return to_object
|
|
168
49
|
|
|
169
50
|
|
|
170
|
-
def
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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, ['generatedSamples']) 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, ['generatedSamples'])
|
|
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:
|
|
51
|
+
def _GetOperationParameters_to_mldev(
|
|
52
|
+
from_object: Union[dict[str, Any], object],
|
|
53
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
54
|
+
) -> dict[str, Any]:
|
|
224
55
|
to_object: dict[str, Any] = {}
|
|
225
|
-
if getv(from_object, ['
|
|
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:
|
|
56
|
+
if getv(from_object, ['operation_name']) is not None:
|
|
243
57
|
setv(
|
|
244
58
|
to_object,
|
|
245
|
-
['
|
|
246
|
-
getv(from_object, ['
|
|
59
|
+
['_url', 'operationName'],
|
|
60
|
+
getv(from_object, ['operation_name']),
|
|
247
61
|
)
|
|
248
62
|
|
|
249
63
|
return to_object
|
|
250
64
|
|
|
251
65
|
|
|
252
|
-
def
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
) -> dict:
|
|
66
|
+
def _GetOperationParameters_to_vertex(
|
|
67
|
+
from_object: Union[dict[str, Any], object],
|
|
68
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
69
|
+
) -> dict[str, Any]:
|
|
257
70
|
to_object: dict[str, Any] = {}
|
|
258
|
-
if getv(from_object, ['
|
|
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:
|
|
71
|
+
if getv(from_object, ['operation_name']) is not None:
|
|
274
72
|
setv(
|
|
275
73
|
to_object,
|
|
276
|
-
['
|
|
277
|
-
|
|
278
|
-
api_client,
|
|
279
|
-
getv(from_object, ['response', 'generateVideoResponse']),
|
|
280
|
-
to_object,
|
|
281
|
-
),
|
|
74
|
+
['_url', 'operationName'],
|
|
75
|
+
getv(from_object, ['operation_name']),
|
|
282
76
|
)
|
|
283
77
|
|
|
284
78
|
return to_object
|
|
285
79
|
|
|
286
80
|
|
|
287
|
-
def
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
) -> dict:
|
|
81
|
+
def _GetProjectOperationParameters_to_vertex(
|
|
82
|
+
from_object: Union[dict[str, Any], object],
|
|
83
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
84
|
+
) -> dict[str, Any]:
|
|
292
85
|
to_object: dict[str, Any] = {}
|
|
293
|
-
if getv(from_object, ['
|
|
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:
|
|
86
|
+
if getv(from_object, ['operation_id']) is not None:
|
|
309
87
|
setv(
|
|
310
|
-
to_object,
|
|
311
|
-
['result'],
|
|
312
|
-
_GenerateVideosResponse_from_vertex(
|
|
313
|
-
api_client, getv(from_object, ['response']), to_object
|
|
314
|
-
),
|
|
88
|
+
to_object, ['_url', 'operation_id'], getv(from_object, ['operation_id'])
|
|
315
89
|
)
|
|
316
90
|
|
|
317
91
|
return to_object
|
|
@@ -319,12 +93,12 @@ def _GenerateVideosOperation_from_vertex(
|
|
|
319
93
|
|
|
320
94
|
class Operations(_api_module.BaseModule):
|
|
321
95
|
|
|
322
|
-
def
|
|
96
|
+
def _get_videos_operation(
|
|
323
97
|
self,
|
|
324
98
|
*,
|
|
325
99
|
operation_name: str,
|
|
326
100
|
config: Optional[types.GetOperationConfigOrDict] = None,
|
|
327
|
-
) ->
|
|
101
|
+
) -> Any:
|
|
328
102
|
parameter_model = types._GetOperationParameters(
|
|
329
103
|
operation_name=operation_name,
|
|
330
104
|
config=config,
|
|
@@ -333,18 +107,14 @@ class Operations(_api_module.BaseModule):
|
|
|
333
107
|
request_url_dict: Optional[dict[str, str]]
|
|
334
108
|
|
|
335
109
|
if self._api_client.vertexai:
|
|
336
|
-
request_dict = _GetOperationParameters_to_vertex(
|
|
337
|
-
self._api_client, parameter_model
|
|
338
|
-
)
|
|
110
|
+
request_dict = _GetOperationParameters_to_vertex(parameter_model)
|
|
339
111
|
request_url_dict = request_dict.get('_url')
|
|
340
112
|
if request_url_dict:
|
|
341
113
|
path = '{operationName}'.format_map(request_url_dict)
|
|
342
114
|
else:
|
|
343
115
|
path = '{operationName}'
|
|
344
116
|
else:
|
|
345
|
-
request_dict = _GetOperationParameters_to_mldev(
|
|
346
|
-
self._api_client, parameter_model
|
|
347
|
-
)
|
|
117
|
+
request_dict = _GetOperationParameters_to_mldev(parameter_model)
|
|
348
118
|
request_url_dict = request_dict.get('_url')
|
|
349
119
|
if request_url_dict:
|
|
350
120
|
path = '{operationName}'.format_map(request_url_dict)
|
|
@@ -356,41 +126,29 @@ class Operations(_api_module.BaseModule):
|
|
|
356
126
|
# TODO: remove the hack that pops config.
|
|
357
127
|
request_dict.pop('config', None)
|
|
358
128
|
|
|
359
|
-
http_options: Optional[types.
|
|
360
|
-
if
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
129
|
+
http_options: Optional[types.HttpOptions] = None
|
|
130
|
+
if (
|
|
131
|
+
parameter_model.config is not None
|
|
132
|
+
and parameter_model.config.http_options is not None
|
|
133
|
+
):
|
|
134
|
+
http_options = parameter_model.config.http_options
|
|
364
135
|
|
|
365
136
|
request_dict = _common.convert_to_dict(request_dict)
|
|
366
137
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
367
138
|
|
|
368
|
-
|
|
369
|
-
'get', path, request_dict, http_options
|
|
370
|
-
)
|
|
139
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
|
371
140
|
|
|
372
|
-
if
|
|
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
|
-
)
|
|
141
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
380
142
|
|
|
381
|
-
|
|
382
|
-
response=response_dict, kwargs=parameter_model.model_dump()
|
|
383
|
-
)
|
|
384
|
-
self._api_client._verify_response(return_value)
|
|
385
|
-
return return_value
|
|
143
|
+
return response_dict
|
|
386
144
|
|
|
387
|
-
def
|
|
145
|
+
def _fetch_predict_videos_operation(
|
|
388
146
|
self,
|
|
389
147
|
*,
|
|
390
148
|
operation_name: str,
|
|
391
149
|
resource_name: str,
|
|
392
150
|
config: Optional[types.FetchPredictOperationConfigOrDict] = None,
|
|
393
|
-
) ->
|
|
151
|
+
) -> Any:
|
|
394
152
|
parameter_model = types._FetchPredictOperationParameters(
|
|
395
153
|
operation_name=operation_name,
|
|
396
154
|
resource_name=resource_name,
|
|
@@ -401,9 +159,7 @@ class Operations(_api_module.BaseModule):
|
|
|
401
159
|
if not self._api_client.vertexai:
|
|
402
160
|
raise ValueError('This method is only supported in the Vertex AI client.')
|
|
403
161
|
else:
|
|
404
|
-
request_dict = _FetchPredictOperationParameters_to_vertex(
|
|
405
|
-
self._api_client, parameter_model
|
|
406
|
-
)
|
|
162
|
+
request_dict = _FetchPredictOperationParameters_to_vertex(parameter_model)
|
|
407
163
|
request_url_dict = request_dict.get('_url')
|
|
408
164
|
if request_url_dict:
|
|
409
165
|
path = '{resourceName}:fetchPredictOperation'.format_map(
|
|
@@ -418,43 +174,81 @@ class Operations(_api_module.BaseModule):
|
|
|
418
174
|
# TODO: remove the hack that pops config.
|
|
419
175
|
request_dict.pop('config', None)
|
|
420
176
|
|
|
421
|
-
http_options: Optional[types.
|
|
422
|
-
if
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
177
|
+
http_options: Optional[types.HttpOptions] = None
|
|
178
|
+
if (
|
|
179
|
+
parameter_model.config is not None
|
|
180
|
+
and parameter_model.config.http_options is not None
|
|
181
|
+
):
|
|
182
|
+
http_options = parameter_model.config.http_options
|
|
426
183
|
|
|
427
184
|
request_dict = _common.convert_to_dict(request_dict)
|
|
428
185
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
429
186
|
|
|
430
|
-
|
|
187
|
+
response = self._api_client.request(
|
|
431
188
|
'post', path, request_dict, http_options
|
|
432
189
|
)
|
|
433
190
|
|
|
434
|
-
if
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
191
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
192
|
+
|
|
193
|
+
return response_dict
|
|
194
|
+
|
|
195
|
+
def _get(
|
|
196
|
+
self,
|
|
197
|
+
*,
|
|
198
|
+
operation_id: str,
|
|
199
|
+
config: Optional[types.GetOperationConfigOrDict] = None,
|
|
200
|
+
) -> types.ProjectOperation:
|
|
201
|
+
parameter_model = types._GetProjectOperationParameters(
|
|
202
|
+
operation_id=operation_id,
|
|
203
|
+
config=config,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
request_url_dict: Optional[dict[str, str]]
|
|
207
|
+
if not self._api_client.vertexai:
|
|
208
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
|
438
209
|
else:
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
210
|
+
request_dict = _GetProjectOperationParameters_to_vertex(parameter_model)
|
|
211
|
+
request_url_dict = request_dict.get('_url')
|
|
212
|
+
if request_url_dict:
|
|
213
|
+
path = 'operations/{operation_id}'.format_map(request_url_dict)
|
|
214
|
+
else:
|
|
215
|
+
path = 'operations/{operation_id}'
|
|
216
|
+
|
|
217
|
+
query_params = request_dict.get('_query')
|
|
218
|
+
if query_params:
|
|
219
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
220
|
+
# TODO: remove the hack that pops config.
|
|
221
|
+
request_dict.pop('config', None)
|
|
222
|
+
|
|
223
|
+
http_options: Optional[types.HttpOptions] = None
|
|
224
|
+
if (
|
|
225
|
+
parameter_model.config is not None
|
|
226
|
+
and parameter_model.config.http_options is not None
|
|
227
|
+
):
|
|
228
|
+
http_options = parameter_model.config.http_options
|
|
229
|
+
|
|
230
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
231
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
232
|
+
|
|
233
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
|
234
|
+
|
|
235
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
442
236
|
|
|
443
|
-
return_value = types.
|
|
237
|
+
return_value = types.ProjectOperation._from_response(
|
|
444
238
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
445
239
|
)
|
|
240
|
+
|
|
446
241
|
self._api_client._verify_response(return_value)
|
|
447
242
|
return return_value
|
|
448
243
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
)
|
|
244
|
+
T = TypeVar('T', bound=types.Operation)
|
|
245
|
+
|
|
452
246
|
def get(
|
|
453
247
|
self,
|
|
454
|
-
operation:
|
|
248
|
+
operation: T,
|
|
455
249
|
*,
|
|
456
250
|
config: Optional[types.GetOperationConfigOrDict] = None,
|
|
457
|
-
) ->
|
|
251
|
+
) -> T:
|
|
458
252
|
"""Gets the status of an operation."""
|
|
459
253
|
# Currently, only GenerateVideosOperation is supported.
|
|
460
254
|
# TODO(b/398040607): Support short form names
|
|
@@ -479,26 +273,39 @@ class Operations(_api_module.BaseModule):
|
|
|
479
273
|
fetch_operation_config = types.FetchPredictOperationConfig(
|
|
480
274
|
http_options=http_options
|
|
481
275
|
)
|
|
482
|
-
|
|
276
|
+
response_dict = self._fetch_predict_videos_operation(
|
|
483
277
|
operation_name=operation_name,
|
|
484
278
|
resource_name=resource_name,
|
|
485
279
|
config=fetch_operation_config,
|
|
486
280
|
)
|
|
281
|
+
|
|
282
|
+
response_operation = operation.from_api_response(
|
|
283
|
+
response_dict, is_vertex_ai=True
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
self._api_client._verify_response(response_operation) # type: ignore [arg-type]
|
|
287
|
+
return response_operation # type: ignore[no-any-return]
|
|
487
288
|
else:
|
|
488
|
-
|
|
289
|
+
response_dict = self._get_videos_operation(
|
|
489
290
|
operation_name=operation_name,
|
|
490
291
|
config=config,
|
|
491
292
|
)
|
|
293
|
+
response_operation = operation.from_api_response(
|
|
294
|
+
response_dict, is_vertex_ai=False
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
self._api_client._verify_response(response_operation) # type: ignore [arg-type]
|
|
298
|
+
return response_operation # type: ignore[no-any-return]
|
|
492
299
|
|
|
493
300
|
|
|
494
301
|
class AsyncOperations(_api_module.BaseModule):
|
|
495
302
|
|
|
496
|
-
async def
|
|
303
|
+
async def _get_videos_operation(
|
|
497
304
|
self,
|
|
498
305
|
*,
|
|
499
306
|
operation_name: str,
|
|
500
307
|
config: Optional[types.GetOperationConfigOrDict] = None,
|
|
501
|
-
) ->
|
|
308
|
+
) -> Any:
|
|
502
309
|
parameter_model = types._GetOperationParameters(
|
|
503
310
|
operation_name=operation_name,
|
|
504
311
|
config=config,
|
|
@@ -507,18 +314,14 @@ class AsyncOperations(_api_module.BaseModule):
|
|
|
507
314
|
request_url_dict: Optional[dict[str, str]]
|
|
508
315
|
|
|
509
316
|
if self._api_client.vertexai:
|
|
510
|
-
request_dict = _GetOperationParameters_to_vertex(
|
|
511
|
-
self._api_client, parameter_model
|
|
512
|
-
)
|
|
317
|
+
request_dict = _GetOperationParameters_to_vertex(parameter_model)
|
|
513
318
|
request_url_dict = request_dict.get('_url')
|
|
514
319
|
if request_url_dict:
|
|
515
320
|
path = '{operationName}'.format_map(request_url_dict)
|
|
516
321
|
else:
|
|
517
322
|
path = '{operationName}'
|
|
518
323
|
else:
|
|
519
|
-
request_dict = _GetOperationParameters_to_mldev(
|
|
520
|
-
self._api_client, parameter_model
|
|
521
|
-
)
|
|
324
|
+
request_dict = _GetOperationParameters_to_mldev(parameter_model)
|
|
522
325
|
request_url_dict = request_dict.get('_url')
|
|
523
326
|
if request_url_dict:
|
|
524
327
|
path = '{operationName}'.format_map(request_url_dict)
|
|
@@ -530,41 +333,31 @@ class AsyncOperations(_api_module.BaseModule):
|
|
|
530
333
|
# TODO: remove the hack that pops config.
|
|
531
334
|
request_dict.pop('config', None)
|
|
532
335
|
|
|
533
|
-
http_options: Optional[types.
|
|
534
|
-
if
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
336
|
+
http_options: Optional[types.HttpOptions] = None
|
|
337
|
+
if (
|
|
338
|
+
parameter_model.config is not None
|
|
339
|
+
and parameter_model.config.http_options is not None
|
|
340
|
+
):
|
|
341
|
+
http_options = parameter_model.config.http_options
|
|
538
342
|
|
|
539
343
|
request_dict = _common.convert_to_dict(request_dict)
|
|
540
344
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
541
345
|
|
|
542
|
-
|
|
346
|
+
response = await self._api_client.async_request(
|
|
543
347
|
'get', path, request_dict, http_options
|
|
544
348
|
)
|
|
545
349
|
|
|
546
|
-
if
|
|
547
|
-
response_dict = _GenerateVideosOperation_from_vertex(
|
|
548
|
-
self._api_client, response_dict
|
|
549
|
-
)
|
|
550
|
-
else:
|
|
551
|
-
response_dict = _GenerateVideosOperation_from_mldev(
|
|
552
|
-
self._api_client, response_dict
|
|
553
|
-
)
|
|
350
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
554
351
|
|
|
555
|
-
|
|
556
|
-
response=response_dict, kwargs=parameter_model.model_dump()
|
|
557
|
-
)
|
|
558
|
-
self._api_client._verify_response(return_value)
|
|
559
|
-
return return_value
|
|
352
|
+
return response_dict
|
|
560
353
|
|
|
561
|
-
async def
|
|
354
|
+
async def _fetch_predict_videos_operation(
|
|
562
355
|
self,
|
|
563
356
|
*,
|
|
564
357
|
operation_name: str,
|
|
565
358
|
resource_name: str,
|
|
566
359
|
config: Optional[types.FetchPredictOperationConfigOrDict] = None,
|
|
567
|
-
) ->
|
|
360
|
+
) -> Any:
|
|
568
361
|
parameter_model = types._FetchPredictOperationParameters(
|
|
569
362
|
operation_name=operation_name,
|
|
570
363
|
resource_name=resource_name,
|
|
@@ -575,9 +368,7 @@ class AsyncOperations(_api_module.BaseModule):
|
|
|
575
368
|
if not self._api_client.vertexai:
|
|
576
369
|
raise ValueError('This method is only supported in the Vertex AI client.')
|
|
577
370
|
else:
|
|
578
|
-
request_dict = _FetchPredictOperationParameters_to_vertex(
|
|
579
|
-
self._api_client, parameter_model
|
|
580
|
-
)
|
|
371
|
+
request_dict = _FetchPredictOperationParameters_to_vertex(parameter_model)
|
|
581
372
|
request_url_dict = request_dict.get('_url')
|
|
582
373
|
if request_url_dict:
|
|
583
374
|
path = '{resourceName}:fetchPredictOperation'.format_map(
|
|
@@ -592,43 +383,83 @@ class AsyncOperations(_api_module.BaseModule):
|
|
|
592
383
|
# TODO: remove the hack that pops config.
|
|
593
384
|
request_dict.pop('config', None)
|
|
594
385
|
|
|
595
|
-
http_options: Optional[types.
|
|
596
|
-
if
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
386
|
+
http_options: Optional[types.HttpOptions] = None
|
|
387
|
+
if (
|
|
388
|
+
parameter_model.config is not None
|
|
389
|
+
and parameter_model.config.http_options is not None
|
|
390
|
+
):
|
|
391
|
+
http_options = parameter_model.config.http_options
|
|
600
392
|
|
|
601
393
|
request_dict = _common.convert_to_dict(request_dict)
|
|
602
394
|
request_dict = _common.encode_unserializable_types(request_dict)
|
|
603
395
|
|
|
604
|
-
|
|
396
|
+
response = await self._api_client.async_request(
|
|
605
397
|
'post', path, request_dict, http_options
|
|
606
398
|
)
|
|
607
399
|
|
|
608
|
-
if
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
400
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
401
|
+
|
|
402
|
+
return response_dict
|
|
403
|
+
|
|
404
|
+
async def _get(
|
|
405
|
+
self,
|
|
406
|
+
*,
|
|
407
|
+
operation_id: str,
|
|
408
|
+
config: Optional[types.GetOperationConfigOrDict] = None,
|
|
409
|
+
) -> types.ProjectOperation:
|
|
410
|
+
parameter_model = types._GetProjectOperationParameters(
|
|
411
|
+
operation_id=operation_id,
|
|
412
|
+
config=config,
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
request_url_dict: Optional[dict[str, str]]
|
|
416
|
+
if not self._api_client.vertexai:
|
|
417
|
+
raise ValueError('This method is only supported in the Vertex AI client.')
|
|
612
418
|
else:
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
419
|
+
request_dict = _GetProjectOperationParameters_to_vertex(parameter_model)
|
|
420
|
+
request_url_dict = request_dict.get('_url')
|
|
421
|
+
if request_url_dict:
|
|
422
|
+
path = 'operations/{operation_id}'.format_map(request_url_dict)
|
|
423
|
+
else:
|
|
424
|
+
path = 'operations/{operation_id}'
|
|
425
|
+
|
|
426
|
+
query_params = request_dict.get('_query')
|
|
427
|
+
if query_params:
|
|
428
|
+
path = f'{path}?{urlencode(query_params)}'
|
|
429
|
+
# TODO: remove the hack that pops config.
|
|
430
|
+
request_dict.pop('config', None)
|
|
431
|
+
|
|
432
|
+
http_options: Optional[types.HttpOptions] = None
|
|
433
|
+
if (
|
|
434
|
+
parameter_model.config is not None
|
|
435
|
+
and parameter_model.config.http_options is not None
|
|
436
|
+
):
|
|
437
|
+
http_options = parameter_model.config.http_options
|
|
616
438
|
|
|
617
|
-
|
|
439
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
440
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
441
|
+
|
|
442
|
+
response = await self._api_client.async_request(
|
|
443
|
+
'get', path, request_dict, http_options
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
447
|
+
|
|
448
|
+
return_value = types.ProjectOperation._from_response(
|
|
618
449
|
response=response_dict, kwargs=parameter_model.model_dump()
|
|
619
450
|
)
|
|
451
|
+
|
|
620
452
|
self._api_client._verify_response(return_value)
|
|
621
453
|
return return_value
|
|
622
454
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
)
|
|
455
|
+
T = TypeVar('T', bound=types.Operation)
|
|
456
|
+
|
|
626
457
|
async def get(
|
|
627
458
|
self,
|
|
628
|
-
operation:
|
|
459
|
+
operation: T,
|
|
629
460
|
*,
|
|
630
461
|
config: Optional[types.GetOperationConfigOrDict] = None,
|
|
631
|
-
) ->
|
|
462
|
+
) -> T:
|
|
632
463
|
"""Gets the status of an operation."""
|
|
633
464
|
# Currently, only GenerateVideosOperation is supported.
|
|
634
465
|
operation_name = operation.name
|
|
@@ -651,13 +482,21 @@ class AsyncOperations(_api_module.BaseModule):
|
|
|
651
482
|
fetch_operation_config = types.FetchPredictOperationConfig(
|
|
652
483
|
http_options=http_options
|
|
653
484
|
)
|
|
654
|
-
|
|
485
|
+
response_dict = await self._fetch_predict_videos_operation(
|
|
655
486
|
operation_name=operation_name,
|
|
656
487
|
resource_name=resource_name,
|
|
657
488
|
config=fetch_operation_config,
|
|
658
489
|
)
|
|
490
|
+
response_operation = operation.from_api_response(
|
|
491
|
+
response_dict, is_vertex_ai=True
|
|
492
|
+
)
|
|
493
|
+
return response_operation # type: ignore[no-any-return]
|
|
659
494
|
else:
|
|
660
|
-
|
|
495
|
+
response_dict = await self._get_videos_operation(
|
|
661
496
|
operation_name=operation_name,
|
|
662
497
|
config=config,
|
|
663
498
|
)
|
|
499
|
+
response_operation = operation.from_api_response(
|
|
500
|
+
response_dict, is_vertex_ai=False
|
|
501
|
+
)
|
|
502
|
+
return response_operation # type: ignore[no-any-return]
|