google-genai 1.33.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.
@@ -30,6 +30,24 @@ from ._common import set_value_by_path as setv
30
30
  logger = logging.getLogger('google_genai.operations')
31
31
 
32
32
 
33
+ def _FetchPredictOperationParameters_to_vertex(
34
+ from_object: Union[dict[str, Any], object],
35
+ parent_object: Optional[dict[str, Any]] = None,
36
+ ) -> dict[str, Any]:
37
+ to_object: dict[str, Any] = {}
38
+ if getv(from_object, ['operation_name']) is not None:
39
+ setv(to_object, ['operationName'], getv(from_object, ['operation_name']))
40
+
41
+ if getv(from_object, ['resource_name']) is not None:
42
+ setv(
43
+ to_object,
44
+ ['_url', 'resourceName'],
45
+ getv(from_object, ['resource_name']),
46
+ )
47
+
48
+ return to_object
49
+
50
+
33
51
  def _GetOperationParameters_to_mldev(
34
52
  from_object: Union[dict[str, Any], object],
35
53
  parent_object: Optional[dict[str, Any]] = None,
@@ -42,9 +60,6 @@ def _GetOperationParameters_to_mldev(
42
60
  getv(from_object, ['operation_name']),
43
61
  )
44
62
 
45
- if getv(from_object, ['config']) is not None:
46
- setv(to_object, ['config'], getv(from_object, ['config']))
47
-
48
63
  return to_object
49
64
 
50
65
 
@@ -60,30 +75,19 @@ def _GetOperationParameters_to_vertex(
60
75
  getv(from_object, ['operation_name']),
61
76
  )
62
77
 
63
- if getv(from_object, ['config']) is not None:
64
- setv(to_object, ['config'], getv(from_object, ['config']))
65
-
66
78
  return to_object
67
79
 
68
80
 
69
- def _FetchPredictOperationParameters_to_vertex(
81
+ def _GetProjectOperationParameters_to_vertex(
70
82
  from_object: Union[dict[str, Any], object],
71
83
  parent_object: Optional[dict[str, Any]] = None,
72
84
  ) -> dict[str, Any]:
73
85
  to_object: dict[str, Any] = {}
74
- if getv(from_object, ['operation_name']) is not None:
75
- setv(to_object, ['operationName'], getv(from_object, ['operation_name']))
76
-
77
- if getv(from_object, ['resource_name']) is not None:
86
+ if getv(from_object, ['operation_id']) is not None:
78
87
  setv(
79
- to_object,
80
- ['_url', 'resourceName'],
81
- getv(from_object, ['resource_name']),
88
+ to_object, ['_url', 'operation_id'], getv(from_object, ['operation_id'])
82
89
  )
83
90
 
84
- if getv(from_object, ['config']) is not None:
85
- setv(to_object, ['config'], getv(from_object, ['config']))
86
-
87
91
  return to_object
88
92
 
89
93
 
@@ -134,7 +138,7 @@ class Operations(_api_module.BaseModule):
134
138
 
135
139
  response = self._api_client.request('get', path, request_dict, http_options)
136
140
 
137
- response_dict = '' if not response.body else json.loads(response.body)
141
+ response_dict = {} if not response.body else json.loads(response.body)
138
142
 
139
143
  return response_dict
140
144
 
@@ -184,10 +188,59 @@ class Operations(_api_module.BaseModule):
184
188
  'post', path, request_dict, http_options
185
189
  )
186
190
 
187
- response_dict = '' if not response.body else json.loads(response.body)
191
+ response_dict = {} if not response.body else json.loads(response.body)
188
192
 
189
193
  return response_dict
190
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.')
209
+ else:
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)
236
+
237
+ return_value = types.ProjectOperation._from_response(
238
+ response=response_dict, kwargs=parameter_model.model_dump()
239
+ )
240
+
241
+ self._api_client._verify_response(return_value)
242
+ return return_value
243
+
191
244
  T = TypeVar('T', bound=types.Operation)
192
245
 
193
246
  def get(
@@ -229,6 +282,8 @@ class Operations(_api_module.BaseModule):
229
282
  response_operation = operation.from_api_response(
230
283
  response_dict, is_vertex_ai=True
231
284
  )
285
+
286
+ self._api_client._verify_response(response_operation) # type: ignore [arg-type]
232
287
  return response_operation # type: ignore[no-any-return]
233
288
  else:
234
289
  response_dict = self._get_videos_operation(
@@ -238,6 +293,8 @@ class Operations(_api_module.BaseModule):
238
293
  response_operation = operation.from_api_response(
239
294
  response_dict, is_vertex_ai=False
240
295
  )
296
+
297
+ self._api_client._verify_response(response_operation) # type: ignore [arg-type]
241
298
  return response_operation # type: ignore[no-any-return]
242
299
 
243
300
 
@@ -290,7 +347,7 @@ class AsyncOperations(_api_module.BaseModule):
290
347
  'get', path, request_dict, http_options
291
348
  )
292
349
 
293
- response_dict = '' if not response.body else json.loads(response.body)
350
+ response_dict = {} if not response.body else json.loads(response.body)
294
351
 
295
352
  return response_dict
296
353
 
@@ -340,10 +397,61 @@ class AsyncOperations(_api_module.BaseModule):
340
397
  'post', path, request_dict, http_options
341
398
  )
342
399
 
343
- response_dict = '' if not response.body else json.loads(response.body)
400
+ response_dict = {} if not response.body else json.loads(response.body)
344
401
 
345
402
  return response_dict
346
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.')
418
+ else:
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
438
+
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(
449
+ response=response_dict, kwargs=parameter_model.model_dump()
450
+ )
451
+
452
+ self._api_client._verify_response(return_value)
453
+ return return_value
454
+
347
455
  T = TypeVar('T', bound=types.Operation)
348
456
 
349
457
  async def get(
google/genai/pagers.py CHANGED
@@ -25,7 +25,13 @@ from . import types
25
25
  T = TypeVar('T')
26
26
 
27
27
  PagedItem = Literal[
28
- 'batch_jobs', 'models', 'tuning_jobs', 'files', 'cached_contents'
28
+ 'batch_jobs',
29
+ 'models',
30
+ 'tuning_jobs',
31
+ 'files',
32
+ 'cached_contents',
33
+ 'file_search_stores',
34
+ 'documents',
29
35
  ]
30
36
 
31
37
 
google/genai/tokens.py CHANGED
@@ -257,12 +257,7 @@ class Tokens(_api_module.BaseModule):
257
257
  response = self._api_client.request(
258
258
  'post', path, request_dict, http_options
259
259
  )
260
- response_dict = '' if not response.body else json.loads(response.body)
261
-
262
- if not self._api_client.vertexai:
263
- response_dict = tokens_converters._AuthToken_from_mldev(
264
- response_dict
265
- )
260
+ response_dict = {} if not response.body else json.loads(response.body)
266
261
 
267
262
  return_value = types.AuthToken._from_response(
268
263
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -358,12 +353,7 @@ class AsyncTokens(_api_module.BaseModule):
358
353
  request_dict,
359
354
  http_options=http_options,
360
355
  )
361
- response_dict = '' if not response.body else json.loads(response.body)
362
-
363
- if not self._api_client.vertexai:
364
- response_dict = tokens_converters._AuthToken_from_mldev(
365
- response_dict
366
- )
356
+ response_dict = {} if not response.body else json.loads(response.body)
367
357
 
368
358
  return_value = types.AuthToken._from_response(
369
359
  response=response_dict, kwargs=parameter_model.model_dump()