google-genai 0.6.0__py3-none-any.whl → 0.7.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/client.py CHANGED
@@ -149,49 +149,43 @@ class Client:
149
149
  ):
150
150
  """Initializes the client.
151
151
 
152
- Args:
153
- vertexai (bool):
154
- Indicates whether the client should use the Vertex AI
155
- API endpoints. Defaults to False (uses Gemini Developer API
156
- endpoints). Applies to the Vertex AI API only.
157
- api_key (str):
158
- The `API key
159
- <https://ai.google.dev/gemini-api/docs/api-key>`_ to use for
160
- authentication. Applies to the Gemini Developer API only.
161
- credentials (google.auth.credentials.Credentials):
162
- The credentials to
163
- use for authentication when calling the Vertex AI APIs. Credentials
164
- can be obtained from environment variables and default credentials.
165
- For more information, see `Set up Application Default Credentials
166
- <https://cloud.google.com/docs/authentication/provide-credentials-adc>`_.
167
- Applies to the Vertex AI API only.
168
- project (str):
169
- The `Google Cloud project ID
170
- <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to
171
- use for quota. Can be obtained from environment variables (for
172
- example, ``GOOGLE_CLOUD_PROJECT``). Applies to the Vertex AI API only.
173
- location (str):
174
- The `location
175
- <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_
176
- to send API requests to (for example, ``us-central1``). Can be
177
- obtained from environment variables. Applies to the Vertex AI API
178
- only.
179
- debug_config (DebugConfig):
180
- Config settings that control network
181
- behavior of the client. This is typically used when running test code.
182
- http_options (Union[HttpOptions, HttpOptionsDict]):
183
- Http options to use for the client. Response_payload can't be
184
- set when passing to the client constructor.
152
+ Args:
153
+ vertexai (bool): Indicates whether the client should use the Vertex AI
154
+ API endpoints. Defaults to False (uses Gemini Developer API endpoints).
155
+ Applies to the Vertex AI API only.
156
+ api_key (str): The `API key
157
+ <https://ai.google.dev/gemini-api/docs/api-key>`_ to use for
158
+ authentication. Applies to the Gemini Developer API only.
159
+ credentials (google.auth.credentials.Credentials): The credentials to use
160
+ for authentication when calling the Vertex AI APIs. Credentials can be
161
+ obtained from environment variables and default credentials. For more
162
+ information, see `Set up Application Default Credentials
163
+ <https://cloud.google.com/docs/authentication/provide-credentials-adc>`_.
164
+ Applies to the Vertex AI API only.
165
+ project (str): The `Google Cloud project ID
166
+ <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to
167
+ use for quota. Can be obtained from environment variables (for example,
168
+ ``GOOGLE_CLOUD_PROJECT``). Applies to the Vertex AI API only.
169
+ location (str): The `location
170
+ <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_
171
+ to send API requests to (for example, ``us-central1``). Can be obtained
172
+ from environment variables. Applies to the Vertex AI API only.
173
+ debug_config (DebugConfig): Config settings that control network behavior
174
+ of the client. This is typically used when running test code.
175
+ http_options (Union[HttpOptions, HttpOptionsDict]): Http options to use
176
+ for the client. The field deprecated_response_payload should not be set
177
+ in http_options.
185
178
  """
186
179
 
187
180
  self._debug_config = debug_config or DebugConfig()
188
181
 
189
- # Throw ValueError if response_payload is set in http_options due to
190
- # unpredictable behavior when running multiple coroutines through
182
+ # Throw ValueError if deprecated_response_payload is set in http_options
183
+ # due to unpredictable behavior when running multiple coroutines through
191
184
  # client.aio.
192
- if http_options and 'response_payload' in http_options:
185
+ if http_options and 'deprecated_response_payload' in http_options:
193
186
  raise ValueError(
194
- 'Setting response_payload in http_options is not supported.'
187
+ 'Setting deprecated_response_payload in http_options is not'
188
+ ' supported.'
195
189
  )
196
190
 
197
191
  self._api_client = self._get_api_client(
google/genai/files.py CHANGED
@@ -21,6 +21,7 @@ import os
21
21
  import pathlib
22
22
  from typing import Optional, Union
23
23
  from urllib.parse import urlencode
24
+ from . import _api_module
24
25
  from . import _common
25
26
  from . import _transformers as t
26
27
  from . import types
@@ -36,8 +37,6 @@ def _ListFilesConfig_to_mldev(
36
37
  parent_object: dict = None,
37
38
  ) -> dict:
38
39
  to_object = {}
39
- if getv(from_object, ['http_options']) is not None:
40
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
41
40
 
42
41
  if getv(from_object, ['page_size']) is not None:
43
42
  setv(
@@ -60,8 +59,6 @@ def _ListFilesConfig_to_vertex(
60
59
  parent_object: dict = None,
61
60
  ) -> dict:
62
61
  to_object = {}
63
- if getv(from_object, ['http_options']) is not None:
64
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
65
62
 
66
63
  if getv(from_object, ['page_size']) is not None:
67
64
  setv(
@@ -252,30 +249,6 @@ def _File_to_vertex(
252
249
  return to_object
253
250
 
254
251
 
255
- def _CreateFileConfig_to_mldev(
256
- api_client: ApiClient,
257
- from_object: Union[dict, object],
258
- parent_object: dict = None,
259
- ) -> dict:
260
- to_object = {}
261
- if getv(from_object, ['http_options']) is not None:
262
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
263
-
264
- return to_object
265
-
266
-
267
- def _CreateFileConfig_to_vertex(
268
- api_client: ApiClient,
269
- from_object: Union[dict, object],
270
- parent_object: dict = None,
271
- ) -> dict:
272
- to_object = {}
273
- if getv(from_object, ['http_options']) is not None:
274
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
275
-
276
- return to_object
277
-
278
-
279
252
  def _CreateFileParameters_to_mldev(
280
253
  api_client: ApiClient,
281
254
  from_object: Union[dict, object],
@@ -290,13 +263,7 @@ def _CreateFileParameters_to_mldev(
290
263
  )
291
264
 
292
265
  if getv(from_object, ['config']) is not None:
293
- setv(
294
- to_object,
295
- ['config'],
296
- _CreateFileConfig_to_mldev(
297
- api_client, getv(from_object, ['config']), to_object
298
- ),
299
- )
266
+ setv(to_object, ['config'], getv(from_object, ['config']))
300
267
 
301
268
  return to_object
302
269
 
@@ -316,30 +283,6 @@ def _CreateFileParameters_to_vertex(
316
283
  return to_object
317
284
 
318
285
 
319
- def _GetFileConfig_to_mldev(
320
- api_client: ApiClient,
321
- from_object: Union[dict, object],
322
- parent_object: dict = None,
323
- ) -> dict:
324
- to_object = {}
325
- if getv(from_object, ['http_options']) is not None:
326
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
327
-
328
- return to_object
329
-
330
-
331
- def _GetFileConfig_to_vertex(
332
- api_client: ApiClient,
333
- from_object: Union[dict, object],
334
- parent_object: dict = None,
335
- ) -> dict:
336
- to_object = {}
337
- if getv(from_object, ['http_options']) is not None:
338
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
339
-
340
- return to_object
341
-
342
-
343
286
  def _GetFileParameters_to_mldev(
344
287
  api_client: ApiClient,
345
288
  from_object: Union[dict, object],
@@ -354,13 +297,7 @@ def _GetFileParameters_to_mldev(
354
297
  )
355
298
 
356
299
  if getv(from_object, ['config']) is not None:
357
- setv(
358
- to_object,
359
- ['config'],
360
- _GetFileConfig_to_mldev(
361
- api_client, getv(from_object, ['config']), to_object
362
- ),
363
- )
300
+ setv(to_object, ['config'], getv(from_object, ['config']))
364
301
 
365
302
  return to_object
366
303
 
@@ -380,30 +317,6 @@ def _GetFileParameters_to_vertex(
380
317
  return to_object
381
318
 
382
319
 
383
- def _DeleteFileConfig_to_mldev(
384
- api_client: ApiClient,
385
- from_object: Union[dict, object],
386
- parent_object: dict = None,
387
- ) -> dict:
388
- to_object = {}
389
- if getv(from_object, ['http_options']) is not None:
390
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
391
-
392
- return to_object
393
-
394
-
395
- def _DeleteFileConfig_to_vertex(
396
- api_client: ApiClient,
397
- from_object: Union[dict, object],
398
- parent_object: dict = None,
399
- ) -> dict:
400
- to_object = {}
401
- if getv(from_object, ['http_options']) is not None:
402
- setv(to_object, ['httpOptions'], getv(from_object, ['http_options']))
403
-
404
- return to_object
405
-
406
-
407
320
  def _DeleteFileParameters_to_mldev(
408
321
  api_client: ApiClient,
409
322
  from_object: Union[dict, object],
@@ -418,13 +331,7 @@ def _DeleteFileParameters_to_mldev(
418
331
  )
419
332
 
420
333
  if getv(from_object, ['config']) is not None:
421
- setv(
422
- to_object,
423
- ['config'],
424
- _DeleteFileConfig_to_mldev(
425
- api_client, getv(from_object, ['config']), to_object
426
- ),
427
- )
334
+ setv(to_object, ['config'], getv(from_object, ['config']))
428
335
 
429
336
  return to_object
430
337
 
@@ -444,6 +351,16 @@ def _DeleteFileParameters_to_vertex(
444
351
  return to_object
445
352
 
446
353
 
354
+ def _FileState_to_vertex_enum_validate(enum_value: any):
355
+ if enum_value in set(['STATE_UNSPECIFIED', 'PROCESSING', 'ACTIVE', 'FAILED']):
356
+ raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
357
+
358
+
359
+ def _FileSource_to_vertex_enum_validate(enum_value: any):
360
+ if enum_value in set(['SOURCE_UNSPECIFIED', 'UPLOADED', 'GENERATED']):
361
+ raise ValueError(f'{enum_value} enum value is not supported in Vertex AI.')
362
+
363
+
447
364
  def _FileStatus_from_mldev(
448
365
  api_client: ApiClient,
449
366
  from_object: Union[dict, object],
@@ -611,7 +528,7 @@ def _DeleteFileResponse_from_vertex(
611
528
  return to_object
612
529
 
613
530
 
614
- class Files(_common.BaseModule):
531
+ class Files(_api_module.BaseModule):
615
532
 
616
533
  def _list(
617
534
  self, *, config: Optional[types.ListFilesConfigOrDict] = None
@@ -649,8 +566,14 @@ class Files(_common.BaseModule):
649
566
  if query_params:
650
567
  path = f'{path}?{urlencode(query_params)}'
651
568
  # TODO: remove the hack that pops config.
652
- config = request_dict.pop('config', None)
653
- http_options = config.pop('httpOptions', None) if config else None
569
+ request_dict.pop('config', None)
570
+
571
+ http_options = None
572
+ if isinstance(config, dict):
573
+ http_options = config.get('http_options', None)
574
+ elif hasattr(config, 'http_options'):
575
+ http_options = config.http_options
576
+
654
577
  request_dict = _common.convert_to_dict(request_dict)
655
578
  request_dict = _common.encode_unserializable_types(request_dict)
656
579
 
@@ -668,7 +591,7 @@ class Files(_common.BaseModule):
668
591
  )
669
592
 
670
593
  return_value = types.ListFilesResponse._from_response(
671
- response_dict, parameter_model
594
+ response=response_dict, kwargs=parameter_model
672
595
  )
673
596
  self._api_client._verify_response(return_value)
674
597
  return return_value
@@ -696,8 +619,14 @@ class Files(_common.BaseModule):
696
619
  if query_params:
697
620
  path = f'{path}?{urlencode(query_params)}'
698
621
  # TODO: remove the hack that pops config.
699
- config = request_dict.pop('config', None)
700
- http_options = config.pop('httpOptions', None) if config else None
622
+ request_dict.pop('config', None)
623
+
624
+ http_options = None
625
+ if isinstance(config, dict):
626
+ http_options = config.get('http_options', None)
627
+ elif hasattr(config, 'http_options'):
628
+ http_options = config.http_options
629
+
701
630
  request_dict = _common.convert_to_dict(request_dict)
702
631
  request_dict = _common.encode_unserializable_types(request_dict)
703
632
 
@@ -715,7 +644,7 @@ class Files(_common.BaseModule):
715
644
  )
716
645
 
717
646
  return_value = types.CreateFileResponse._from_response(
718
- response_dict, parameter_model
647
+ response=response_dict, kwargs=parameter_model
719
648
  )
720
649
  self._api_client._verify_response(return_value)
721
650
  return return_value
@@ -757,8 +686,14 @@ class Files(_common.BaseModule):
757
686
  if query_params:
758
687
  path = f'{path}?{urlencode(query_params)}'
759
688
  # TODO: remove the hack that pops config.
760
- config = request_dict.pop('config', None)
761
- http_options = config.pop('httpOptions', None) if config else None
689
+ request_dict.pop('config', None)
690
+
691
+ http_options = None
692
+ if isinstance(config, dict):
693
+ http_options = config.get('http_options', None)
694
+ elif hasattr(config, 'http_options'):
695
+ http_options = config.http_options
696
+
762
697
  request_dict = _common.convert_to_dict(request_dict)
763
698
  request_dict = _common.encode_unserializable_types(request_dict)
764
699
 
@@ -771,7 +706,9 @@ class Files(_common.BaseModule):
771
706
  else:
772
707
  response_dict = _File_from_mldev(self._api_client, response_dict)
773
708
 
774
- return_value = types.File._from_response(response_dict, parameter_model)
709
+ return_value = types.File._from_response(
710
+ response=response_dict, kwargs=parameter_model
711
+ )
775
712
  self._api_client._verify_response(return_value)
776
713
  return return_value
777
714
 
@@ -811,8 +748,14 @@ class Files(_common.BaseModule):
811
748
  if query_params:
812
749
  path = f'{path}?{urlencode(query_params)}'
813
750
  # TODO: remove the hack that pops config.
814
- config = request_dict.pop('config', None)
815
- http_options = config.pop('httpOptions', None) if config else None
751
+ request_dict.pop('config', None)
752
+
753
+ http_options = None
754
+ if isinstance(config, dict):
755
+ http_options = config.get('http_options', None)
756
+ elif hasattr(config, 'http_options'):
757
+ http_options = config.http_options
758
+
816
759
  request_dict = _common.convert_to_dict(request_dict)
817
760
  request_dict = _common.encode_unserializable_types(request_dict)
818
761
 
@@ -830,7 +773,7 @@ class Files(_common.BaseModule):
830
773
  )
831
774
 
832
775
  return_value = types.DeleteFileResponse._from_response(
833
- response_dict, parameter_model
776
+ response=response_dict, kwargs=parameter_model
834
777
  )
835
778
  self._api_client._verify_response(return_value)
836
779
  return return_value
@@ -909,7 +852,7 @@ class Files(_common.BaseModule):
909
852
  'X-Goog-Upload-Header-Content-Length': f'{file.size_bytes}',
910
853
  'X-Goog-Upload-Header-Content-Type': f'{file.mime_type}',
911
854
  },
912
- 'response_payload': response,
855
+ 'deprecated_response_payload': response,
913
856
  }
914
857
  self._create(file=file, config={'http_options': http_options})
915
858
 
@@ -1015,7 +958,7 @@ class Files(_common.BaseModule):
1015
958
  return data
1016
959
 
1017
960
 
1018
- class AsyncFiles(_common.BaseModule):
961
+ class AsyncFiles(_api_module.BaseModule):
1019
962
 
1020
963
  async def _list(
1021
964
  self, *, config: Optional[types.ListFilesConfigOrDict] = None
@@ -1053,8 +996,14 @@ class AsyncFiles(_common.BaseModule):
1053
996
  if query_params:
1054
997
  path = f'{path}?{urlencode(query_params)}'
1055
998
  # TODO: remove the hack that pops config.
1056
- config = request_dict.pop('config', None)
1057
- http_options = config.pop('httpOptions', None) if config else None
999
+ request_dict.pop('config', None)
1000
+
1001
+ http_options = None
1002
+ if isinstance(config, dict):
1003
+ http_options = config.get('http_options', None)
1004
+ elif hasattr(config, 'http_options'):
1005
+ http_options = config.http_options
1006
+
1058
1007
  request_dict = _common.convert_to_dict(request_dict)
1059
1008
  request_dict = _common.encode_unserializable_types(request_dict)
1060
1009
 
@@ -1072,7 +1021,7 @@ class AsyncFiles(_common.BaseModule):
1072
1021
  )
1073
1022
 
1074
1023
  return_value = types.ListFilesResponse._from_response(
1075
- response_dict, parameter_model
1024
+ response=response_dict, kwargs=parameter_model
1076
1025
  )
1077
1026
  self._api_client._verify_response(return_value)
1078
1027
  return return_value
@@ -1100,8 +1049,14 @@ class AsyncFiles(_common.BaseModule):
1100
1049
  if query_params:
1101
1050
  path = f'{path}?{urlencode(query_params)}'
1102
1051
  # TODO: remove the hack that pops config.
1103
- config = request_dict.pop('config', None)
1104
- http_options = config.pop('httpOptions', None) if config else None
1052
+ request_dict.pop('config', None)
1053
+
1054
+ http_options = None
1055
+ if isinstance(config, dict):
1056
+ http_options = config.get('http_options', None)
1057
+ elif hasattr(config, 'http_options'):
1058
+ http_options = config.http_options
1059
+
1105
1060
  request_dict = _common.convert_to_dict(request_dict)
1106
1061
  request_dict = _common.encode_unserializable_types(request_dict)
1107
1062
 
@@ -1119,7 +1074,7 @@ class AsyncFiles(_common.BaseModule):
1119
1074
  )
1120
1075
 
1121
1076
  return_value = types.CreateFileResponse._from_response(
1122
- response_dict, parameter_model
1077
+ response=response_dict, kwargs=parameter_model
1123
1078
  )
1124
1079
  self._api_client._verify_response(return_value)
1125
1080
  return return_value
@@ -1161,8 +1116,14 @@ class AsyncFiles(_common.BaseModule):
1161
1116
  if query_params:
1162
1117
  path = f'{path}?{urlencode(query_params)}'
1163
1118
  # TODO: remove the hack that pops config.
1164
- config = request_dict.pop('config', None)
1165
- http_options = config.pop('httpOptions', None) if config else None
1119
+ request_dict.pop('config', None)
1120
+
1121
+ http_options = None
1122
+ if isinstance(config, dict):
1123
+ http_options = config.get('http_options', None)
1124
+ elif hasattr(config, 'http_options'):
1125
+ http_options = config.http_options
1126
+
1166
1127
  request_dict = _common.convert_to_dict(request_dict)
1167
1128
  request_dict = _common.encode_unserializable_types(request_dict)
1168
1129
 
@@ -1175,7 +1136,9 @@ class AsyncFiles(_common.BaseModule):
1175
1136
  else:
1176
1137
  response_dict = _File_from_mldev(self._api_client, response_dict)
1177
1138
 
1178
- return_value = types.File._from_response(response_dict, parameter_model)
1139
+ return_value = types.File._from_response(
1140
+ response=response_dict, kwargs=parameter_model
1141
+ )
1179
1142
  self._api_client._verify_response(return_value)
1180
1143
  return return_value
1181
1144
 
@@ -1215,8 +1178,14 @@ class AsyncFiles(_common.BaseModule):
1215
1178
  if query_params:
1216
1179
  path = f'{path}?{urlencode(query_params)}'
1217
1180
  # TODO: remove the hack that pops config.
1218
- config = request_dict.pop('config', None)
1219
- http_options = config.pop('httpOptions', None) if config else None
1181
+ request_dict.pop('config', None)
1182
+
1183
+ http_options = None
1184
+ if isinstance(config, dict):
1185
+ http_options = config.get('http_options', None)
1186
+ elif hasattr(config, 'http_options'):
1187
+ http_options = config.http_options
1188
+
1220
1189
  request_dict = _common.convert_to_dict(request_dict)
1221
1190
  request_dict = _common.encode_unserializable_types(request_dict)
1222
1191
 
@@ -1234,7 +1203,7 @@ class AsyncFiles(_common.BaseModule):
1234
1203
  )
1235
1204
 
1236
1205
  return_value = types.DeleteFileResponse._from_response(
1237
- response_dict, parameter_model
1206
+ response=response_dict, kwargs=parameter_model
1238
1207
  )
1239
1208
  self._api_client._verify_response(return_value)
1240
1209
  return return_value
@@ -1314,7 +1283,7 @@ class AsyncFiles(_common.BaseModule):
1314
1283
  'X-Goog-Upload-Header-Content-Length': f'{file.size_bytes}',
1315
1284
  'X-Goog-Upload-Header-Content-Type': f'{file.mime_type}',
1316
1285
  },
1317
- 'response_payload': response,
1286
+ 'deprecated_response_payload': response,
1318
1287
  }
1319
1288
  await self._create(file=file, config={'http_options': http_options})
1320
1289
  if (
google/genai/live.py CHANGED
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
  #
15
15
 
16
- """Live client."""
16
+ """Live client. The live module is experimental."""
17
17
 
18
18
  import asyncio
19
19
  import base64
@@ -25,6 +25,7 @@ from typing import AsyncIterator, Optional, Sequence, Union
25
25
  import google.auth
26
26
  from websockets import ConnectionClosed
27
27
 
28
+ from . import _api_module
28
29
  from . import _common
29
30
  from . import _transformers as t
30
31
  from . import client
@@ -60,7 +61,7 @@ _FUNCTION_RESPONSE_REQUIRES_ID = (
60
61
 
61
62
 
62
63
  class AsyncSession:
63
- """AsyncSession."""
64
+ """AsyncSession. The live module is experimental."""
64
65
 
65
66
  def __init__(self, api_client: client.ApiClient, websocket: ClientConnection):
66
67
  self._api_client = api_client
@@ -74,7 +75,6 @@ class AsyncSession:
74
75
  types.ContentListUnionDict,
75
76
  types.LiveClientContentOrDict,
76
77
  types.LiveClientRealtimeInputOrDict,
77
- types.LiveClientRealtimeInputOrDict,
78
78
  types.LiveClientToolResponseOrDict,
79
79
  types.FunctionResponseOrDict,
80
80
  Sequence[types.FunctionResponseOrDict],
@@ -111,6 +111,8 @@ class AsyncSession:
111
111
  is function call, user must call `send` with the function response to
112
112
  continue the turn.
113
113
 
114
+ The live module is experimental.
115
+
114
116
  Yields:
115
117
  The model responses from the server.
116
118
 
@@ -142,6 +144,8 @@ class AsyncSession:
142
144
  input stream to the model and the other task will be used to receive the
143
145
  responses from the model.
144
146
 
147
+ The live module is experimental.
148
+
145
149
  Args:
146
150
  stream: An iterator that yields the model response.
147
151
  mime_type: The MIME type of the data in the stream.
@@ -470,8 +474,8 @@ class AsyncSession:
470
474
  await self._ws.close()
471
475
 
472
476
 
473
- class AsyncLive(_common.BaseModule):
474
- """AsyncLive."""
477
+ class AsyncLive(_api_module.BaseModule):
478
+ """AsyncLive. The live module is experimental."""
475
479
 
476
480
  def _LiveSetup_to_mldev(
477
481
  self, model: str, config: Optional[types.LiveConnectConfigOrDict] = None
@@ -638,6 +642,8 @@ class AsyncLive(_common.BaseModule):
638
642
  ) -> AsyncSession:
639
643
  """Connect to the live server.
640
644
 
645
+ The live module is experimental.
646
+
641
647
  Usage:
642
648
 
643
649
  .. code-block:: python