google-genai 1.3.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.
@@ -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 ApiClient
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: ApiClient,
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: ApiClient,
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: ApiClient,
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: ApiClient,
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,11 +108,11 @@ def _FetchPredictOperationParameters_to_vertex(
108
108
 
109
109
 
110
110
  def _Video_from_mldev(
111
- api_client: ApiClient,
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 = {}
115
+ to_object: dict[str, Any] = {}
116
116
  if getv(from_object, ['uri']) is not None:
117
117
  setv(to_object, ['uri'], getv(from_object, ['uri']))
118
118
 
@@ -130,11 +130,11 @@ def _Video_from_mldev(
130
130
 
131
131
 
132
132
  def _Video_from_vertex(
133
- api_client: ApiClient,
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: ApiClient,
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: ApiClient,
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,11 +184,11 @@ def _GeneratedVideo_from_vertex(
184
184
 
185
185
 
186
186
  def _GenerateVideosResponse_from_mldev(
187
- api_client: ApiClient,
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 = {}
191
+ to_object: dict[str, Any] = {}
192
192
  if getv(from_object, ['videos']) is not None:
193
193
  setv(
194
194
  to_object,
@@ -217,11 +217,11 @@ def _GenerateVideosResponse_from_mldev(
217
217
 
218
218
 
219
219
  def _GenerateVideosResponse_from_vertex(
220
- api_client: ApiClient,
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: ApiClient,
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: ApiClient,
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,23 +330,33 @@ 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
- path = '{operationName}'.format_map(request_dict.get('_url'))
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
- path = '{operationName}'.format_map(request_dict.get('_url'))
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
362
  elif hasattr(config, 'http_options'):
@@ -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
- path = '{resourceName}:fetchPredictOperation'.format_map(
397
- request_dict.get('_url')
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,7 +418,7 @@ 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
424
  elif hasattr(config, 'http_options'):
@@ -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,23 +490,33 @@ 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
- path = '{operationName}'.format_map(request_dict.get('_url'))
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
- path = '{operationName}'.format_map(request_dict.get('_url'))
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
522
  elif hasattr(config, 'http_options'):
@@ -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
- path = '{resourceName}:fetchPredictOperation'.format_map(
542
- request_dict.get('_url')
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,7 +578,7 @@ 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
584
  elif hasattr(config, 'http_options'):
@@ -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, Awaitable, Callable, Generic, Iterator, Literal, TypeVar
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[Any, Any],
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[Any, Awaitable[Any]],
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) -> AsyncIterator[T]:
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) -> Awaitable[T]:
205
+ async def __anext__(self) -> T:
206
206
  """Returns the next item asynchronously."""
207
207
  if self._idx >= len(self):
208
208
  try: