google-genai 1.12.0__py3-none-any.whl → 1.13.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/chats.py CHANGED
@@ -246,7 +246,7 @@ class Chat(_BaseChat):
246
246
 
247
247
  .. code-block:: python
248
248
 
249
- chat = client.chats.create(model='gemini-1.5-flash')
249
+ chat = client.chats.create(model='gemini-2.0-flash')
250
250
  response = chat.send_message('tell me a story')
251
251
  """
252
252
 
@@ -298,7 +298,7 @@ class Chat(_BaseChat):
298
298
 
299
299
  .. code-block:: python
300
300
 
301
- chat = client.chats.create(model='gemini-1.5-flash')
301
+ chat = client.chats.create(model='gemini-2.0-flash')
302
302
  for chunk in chat.send_message_stream('tell me a story'):
303
303
  print(chunk.text)
304
304
  """
@@ -409,7 +409,7 @@ class AsyncChat(_BaseChat):
409
409
 
410
410
  .. code-block:: python
411
411
 
412
- chat = client.aio.chats.create(model='gemini-1.5-flash')
412
+ chat = client.aio.chats.create(model='gemini-2.0-flash')
413
413
  response = await chat.send_message('tell me a story')
414
414
  """
415
415
  if not _is_part_type(message):
@@ -459,7 +459,7 @@ class AsyncChat(_BaseChat):
459
459
  Usage:
460
460
 
461
461
  .. code-block:: python
462
- chat = client.aio.chats.create(model='gemini-1.5-flash')
462
+ chat = client.aio.chats.create(model='gemini-2.0-flash')
463
463
  async for chunk in await chat.send_message_stream('tell me a story'):
464
464
  print(chunk.text)
465
465
  """
google/genai/client.py CHANGED
@@ -20,6 +20,7 @@ import google.auth
20
20
  import pydantic
21
21
 
22
22
  from ._api_client import BaseApiClient
23
+ from ._base_url import get_base_url
23
24
  from ._replay_api_client import ReplayApiClient
24
25
  from .batches import AsyncBatches, Batches
25
26
  from .caches import AsyncCaches, Caches
@@ -78,6 +79,7 @@ class AsyncClient:
78
79
  def operations(self) -> AsyncOperations:
79
80
  return self._operations
80
81
 
82
+
81
83
  class DebugConfig(pydantic.BaseModel):
82
84
  """Configuration options that change client network behavior when testing."""
83
85
 
@@ -114,26 +116,29 @@ class Client:
114
116
  Attributes:
115
117
  api_key: The `API key <https://ai.google.dev/gemini-api/docs/api-key>`_ to
116
118
  use for authentication. Applies to the Gemini Developer API only.
117
- vertexai: Indicates whether the client should use the Vertex AI
118
- API endpoints. Defaults to False (uses Gemini Developer API endpoints).
119
+ vertexai: Indicates whether the client should use the Vertex AI API
120
+ endpoints. Defaults to False (uses Gemini Developer API endpoints).
119
121
  Applies to the Vertex AI API only.
120
122
  credentials: The credentials to use for authentication when calling the
121
123
  Vertex AI APIs. Credentials can be obtained from environment variables and
122
- default credentials. For more information, see
123
- `Set up Application Default Credentials
124
+ default credentials. For more information, see `Set up Application Default
125
+ Credentials
124
126
  <https://cloud.google.com/docs/authentication/provide-credentials-adc>`_.
125
127
  Applies to the Vertex AI API only.
126
- project: The `Google Cloud project ID <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to
127
- use for quota. Can be obtained from environment variables (for example,
128
+ project: The `Google Cloud project ID
129
+ <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to use
130
+ for quota. Can be obtained from environment variables (for example,
128
131
  ``GOOGLE_CLOUD_PROJECT``). Applies to the Vertex AI API only.
129
- location: The `location <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_
132
+ Find your `Google Cloud project ID <https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects>`_.
133
+ location: The `location
134
+ <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_
130
135
  to send API requests to (for example, ``us-central1``). Can be obtained
131
136
  from environment variables. Applies to the Vertex AI API only.
132
137
  debug_config: Config settings that control network behavior of the client.
133
138
  This is typically used when running test code.
134
139
  http_options: Http options to use for the client. These options will be
135
- applied to all requests made by the client. Example usage:
136
- `client = genai.Client(http_options=types.HttpOptions(api_version='v1'))`.
140
+ applied to all requests made by the client. Example usage: `client =
141
+ genai.Client(http_options=types.HttpOptions(api_version='v1'))`.
137
142
 
138
143
  Usage for the Gemini Developer API:
139
144
 
@@ -198,6 +203,13 @@ class Client:
198
203
  if isinstance(http_options, dict):
199
204
  http_options = HttpOptions(**http_options)
200
205
 
206
+ base_url = get_base_url(vertexai or False, http_options)
207
+ if base_url:
208
+ if http_options:
209
+ http_options.base_url = base_url
210
+ else:
211
+ http_options = HttpOptions(base_url=base_url)
212
+
201
213
  self._api_client = self._get_api_client(
202
214
  vertexai=vertexai,
203
215
  api_key=api_key,
google/genai/live.py CHANGED
@@ -892,15 +892,18 @@ class AsyncLive(_api_module.BaseModule):
892
892
 
893
893
  request = json.dumps(request_dict)
894
894
  else:
895
- # Get bearer token through Application Default Credentials.
896
- creds, _ = google.auth.default( # type: ignore[no-untyped-call]
895
+ if not self._api_client._credentials:
896
+ # Get bearer token through Application Default Credentials.
897
+ creds, _ = google.auth.default( # type: ignore[no-untyped-call]
897
898
  scopes=['https://www.googleapis.com/auth/cloud-platform']
898
- )
899
-
899
+ )
900
+ else:
901
+ creds = self._api_client._credentials
900
902
  # creds.valid is False, and creds.token is None
901
903
  # Need to refresh credentials to populate those
902
- auth_req = google.auth.transport.requests.Request() # type: ignore[no-untyped-call]
903
- creds.refresh(auth_req)
904
+ if not (creds.token and creds.valid):
905
+ auth_req = google.auth.transport.requests.Request() # type: ignore[no-untyped-call]
906
+ creds.refresh(auth_req)
904
907
  bearer_token = creds.token
905
908
  headers = self._api_client._http_options.headers
906
909
  if headers is not None:
google/genai/models.py CHANGED
@@ -97,85 +97,6 @@ def _Content_to_mldev(
97
97
  return to_object
98
98
 
99
99
 
100
- def _Schema_to_mldev(
101
- api_client: BaseApiClient,
102
- from_object: Union[dict[str, Any], object],
103
- parent_object: Optional[dict[str, Any]] = None,
104
- ) -> dict[str, Any]:
105
- to_object: dict[str, Any] = {}
106
- if getv(from_object, ['example']) is not None:
107
- raise ValueError('example parameter is not supported in Gemini API.')
108
-
109
- if getv(from_object, ['pattern']) is not None:
110
- raise ValueError('pattern parameter is not supported in Gemini API.')
111
-
112
- if getv(from_object, ['default']) is not None:
113
- raise ValueError('default parameter is not supported in Gemini API.')
114
-
115
- if getv(from_object, ['max_length']) is not None:
116
- raise ValueError('max_length parameter is not supported in Gemini API.')
117
-
118
- if getv(from_object, ['min_length']) is not None:
119
- raise ValueError('min_length parameter is not supported in Gemini API.')
120
-
121
- if getv(from_object, ['min_properties']) is not None:
122
- raise ValueError('min_properties parameter is not supported in Gemini API.')
123
-
124
- if getv(from_object, ['max_properties']) is not None:
125
- raise ValueError('max_properties parameter is not supported in Gemini API.')
126
-
127
- if getv(from_object, ['any_of']) is not None:
128
- setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
129
-
130
- if getv(from_object, ['description']) is not None:
131
- setv(to_object, ['description'], getv(from_object, ['description']))
132
-
133
- if getv(from_object, ['enum']) is not None:
134
- setv(to_object, ['enum'], getv(from_object, ['enum']))
135
-
136
- if getv(from_object, ['format']) is not None:
137
- setv(to_object, ['format'], getv(from_object, ['format']))
138
-
139
- if getv(from_object, ['items']) is not None:
140
- setv(to_object, ['items'], getv(from_object, ['items']))
141
-
142
- if getv(from_object, ['max_items']) is not None:
143
- setv(to_object, ['maxItems'], getv(from_object, ['max_items']))
144
-
145
- if getv(from_object, ['maximum']) is not None:
146
- setv(to_object, ['maximum'], getv(from_object, ['maximum']))
147
-
148
- if getv(from_object, ['min_items']) is not None:
149
- setv(to_object, ['minItems'], getv(from_object, ['min_items']))
150
-
151
- if getv(from_object, ['minimum']) is not None:
152
- setv(to_object, ['minimum'], getv(from_object, ['minimum']))
153
-
154
- if getv(from_object, ['nullable']) is not None:
155
- setv(to_object, ['nullable'], getv(from_object, ['nullable']))
156
-
157
- if getv(from_object, ['properties']) is not None:
158
- setv(to_object, ['properties'], getv(from_object, ['properties']))
159
-
160
- if getv(from_object, ['property_ordering']) is not None:
161
- setv(
162
- to_object,
163
- ['propertyOrdering'],
164
- getv(from_object, ['property_ordering']),
165
- )
166
-
167
- if getv(from_object, ['required']) is not None:
168
- setv(to_object, ['required'], getv(from_object, ['required']))
169
-
170
- if getv(from_object, ['title']) is not None:
171
- setv(to_object, ['title'], getv(from_object, ['title']))
172
-
173
- if getv(from_object, ['type']) is not None:
174
- setv(to_object, ['type'], getv(from_object, ['type']))
175
-
176
- return to_object
177
-
178
-
179
100
  def _ModelSelectionConfig_to_mldev(
180
101
  api_client: BaseApiClient,
181
102
  from_object: Union[dict[str, Any], object],
@@ -208,27 +129,6 @@ def _SafetySetting_to_mldev(
208
129
  return to_object
209
130
 
210
131
 
211
- def _FunctionDeclaration_to_mldev(
212
- api_client: BaseApiClient,
213
- from_object: Union[dict[str, Any], object],
214
- parent_object: Optional[dict[str, Any]] = None,
215
- ) -> dict[str, Any]:
216
- to_object: dict[str, Any] = {}
217
- if getv(from_object, ['response']) is not None:
218
- raise ValueError('response parameter is not supported in Gemini API.')
219
-
220
- if getv(from_object, ['description']) is not None:
221
- setv(to_object, ['description'], getv(from_object, ['description']))
222
-
223
- if getv(from_object, ['name']) is not None:
224
- setv(to_object, ['name'], getv(from_object, ['name']))
225
-
226
- if getv(from_object, ['parameters']) is not None:
227
- setv(to_object, ['parameters'], getv(from_object, ['parameters']))
228
-
229
- return to_object
230
-
231
-
232
132
  def _GoogleSearch_to_mldev(
233
133
  api_client: BaseApiClient,
234
134
  from_object: Union[dict[str, Any], object],
@@ -284,16 +184,6 @@ def _Tool_to_mldev(
284
184
  parent_object: Optional[dict[str, Any]] = None,
285
185
  ) -> dict[str, Any]:
286
186
  to_object: dict[str, Any] = {}
287
- if getv(from_object, ['function_declarations']) is not None:
288
- setv(
289
- to_object,
290
- ['functionDeclarations'],
291
- [
292
- _FunctionDeclaration_to_mldev(api_client, item, to_object)
293
- for item in getv(from_object, ['function_declarations'])
294
- ],
295
- )
296
-
297
187
  if getv(from_object, ['retrieval']) is not None:
298
188
  raise ValueError('retrieval parameter is not supported in Gemini API.')
299
189
 
@@ -320,6 +210,13 @@ def _Tool_to_mldev(
320
210
  if getv(from_object, ['code_execution']) is not None:
321
211
  setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
322
212
 
213
+ if getv(from_object, ['function_declarations']) is not None:
214
+ setv(
215
+ to_object,
216
+ ['functionDeclarations'],
217
+ getv(from_object, ['function_declarations']),
218
+ )
219
+
323
220
  return to_object
324
221
 
325
222
 
@@ -504,11 +401,7 @@ def _GenerateContentConfig_to_mldev(
504
401
  setv(
505
402
  to_object,
506
403
  ['responseSchema'],
507
- _Schema_to_mldev(
508
- api_client,
509
- t.t_schema(api_client, getv(from_object, ['response_schema'])),
510
- to_object,
511
- ),
404
+ t.t_schema(api_client, getv(from_object, ['response_schema'])),
512
405
  )
513
406
 
514
407
  if getv(from_object, ['routing_config']) is not None:
@@ -1213,85 +1106,6 @@ def _Content_to_vertex(
1213
1106
  return to_object
1214
1107
 
1215
1108
 
1216
- def _Schema_to_vertex(
1217
- api_client: BaseApiClient,
1218
- from_object: Union[dict[str, Any], object],
1219
- parent_object: Optional[dict[str, Any]] = None,
1220
- ) -> dict[str, Any]:
1221
- to_object: dict[str, Any] = {}
1222
- if getv(from_object, ['example']) is not None:
1223
- setv(to_object, ['example'], getv(from_object, ['example']))
1224
-
1225
- if getv(from_object, ['pattern']) is not None:
1226
- setv(to_object, ['pattern'], getv(from_object, ['pattern']))
1227
-
1228
- if getv(from_object, ['default']) is not None:
1229
- setv(to_object, ['default'], getv(from_object, ['default']))
1230
-
1231
- if getv(from_object, ['max_length']) is not None:
1232
- setv(to_object, ['maxLength'], getv(from_object, ['max_length']))
1233
-
1234
- if getv(from_object, ['min_length']) is not None:
1235
- setv(to_object, ['minLength'], getv(from_object, ['min_length']))
1236
-
1237
- if getv(from_object, ['min_properties']) is not None:
1238
- setv(to_object, ['minProperties'], getv(from_object, ['min_properties']))
1239
-
1240
- if getv(from_object, ['max_properties']) is not None:
1241
- setv(to_object, ['maxProperties'], getv(from_object, ['max_properties']))
1242
-
1243
- if getv(from_object, ['any_of']) is not None:
1244
- setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
1245
-
1246
- if getv(from_object, ['description']) is not None:
1247
- setv(to_object, ['description'], getv(from_object, ['description']))
1248
-
1249
- if getv(from_object, ['enum']) is not None:
1250
- setv(to_object, ['enum'], getv(from_object, ['enum']))
1251
-
1252
- if getv(from_object, ['format']) is not None:
1253
- setv(to_object, ['format'], getv(from_object, ['format']))
1254
-
1255
- if getv(from_object, ['items']) is not None:
1256
- setv(to_object, ['items'], getv(from_object, ['items']))
1257
-
1258
- if getv(from_object, ['max_items']) is not None:
1259
- setv(to_object, ['maxItems'], getv(from_object, ['max_items']))
1260
-
1261
- if getv(from_object, ['maximum']) is not None:
1262
- setv(to_object, ['maximum'], getv(from_object, ['maximum']))
1263
-
1264
- if getv(from_object, ['min_items']) is not None:
1265
- setv(to_object, ['minItems'], getv(from_object, ['min_items']))
1266
-
1267
- if getv(from_object, ['minimum']) is not None:
1268
- setv(to_object, ['minimum'], getv(from_object, ['minimum']))
1269
-
1270
- if getv(from_object, ['nullable']) is not None:
1271
- setv(to_object, ['nullable'], getv(from_object, ['nullable']))
1272
-
1273
- if getv(from_object, ['properties']) is not None:
1274
- setv(to_object, ['properties'], getv(from_object, ['properties']))
1275
-
1276
- if getv(from_object, ['property_ordering']) is not None:
1277
- setv(
1278
- to_object,
1279
- ['propertyOrdering'],
1280
- getv(from_object, ['property_ordering']),
1281
- )
1282
-
1283
- if getv(from_object, ['required']) is not None:
1284
- setv(to_object, ['required'], getv(from_object, ['required']))
1285
-
1286
- if getv(from_object, ['title']) is not None:
1287
- setv(to_object, ['title'], getv(from_object, ['title']))
1288
-
1289
- if getv(from_object, ['type']) is not None:
1290
- setv(to_object, ['type'], getv(from_object, ['type']))
1291
-
1292
- return to_object
1293
-
1294
-
1295
1109
  def _ModelSelectionConfig_to_vertex(
1296
1110
  api_client: BaseApiClient,
1297
1111
  from_object: Union[dict[str, Any], object],
@@ -1326,33 +1140,6 @@ def _SafetySetting_to_vertex(
1326
1140
  return to_object
1327
1141
 
1328
1142
 
1329
- def _FunctionDeclaration_to_vertex(
1330
- api_client: BaseApiClient,
1331
- from_object: Union[dict[str, Any], object],
1332
- parent_object: Optional[dict[str, Any]] = None,
1333
- ) -> dict[str, Any]:
1334
- to_object: dict[str, Any] = {}
1335
- if getv(from_object, ['response']) is not None:
1336
- setv(
1337
- to_object,
1338
- ['response'],
1339
- _Schema_to_vertex(
1340
- api_client, getv(from_object, ['response']), to_object
1341
- ),
1342
- )
1343
-
1344
- if getv(from_object, ['description']) is not None:
1345
- setv(to_object, ['description'], getv(from_object, ['description']))
1346
-
1347
- if getv(from_object, ['name']) is not None:
1348
- setv(to_object, ['name'], getv(from_object, ['name']))
1349
-
1350
- if getv(from_object, ['parameters']) is not None:
1351
- setv(to_object, ['parameters'], getv(from_object, ['parameters']))
1352
-
1353
- return to_object
1354
-
1355
-
1356
1143
  def _GoogleSearch_to_vertex(
1357
1144
  api_client: BaseApiClient,
1358
1145
  from_object: Union[dict[str, Any], object],
@@ -1408,16 +1195,6 @@ def _Tool_to_vertex(
1408
1195
  parent_object: Optional[dict[str, Any]] = None,
1409
1196
  ) -> dict[str, Any]:
1410
1197
  to_object: dict[str, Any] = {}
1411
- if getv(from_object, ['function_declarations']) is not None:
1412
- setv(
1413
- to_object,
1414
- ['functionDeclarations'],
1415
- [
1416
- _FunctionDeclaration_to_vertex(api_client, item, to_object)
1417
- for item in getv(from_object, ['function_declarations'])
1418
- ],
1419
- )
1420
-
1421
1198
  if getv(from_object, ['retrieval']) is not None:
1422
1199
  setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
1423
1200
 
@@ -1444,6 +1221,13 @@ def _Tool_to_vertex(
1444
1221
  if getv(from_object, ['code_execution']) is not None:
1445
1222
  setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
1446
1223
 
1224
+ if getv(from_object, ['function_declarations']) is not None:
1225
+ setv(
1226
+ to_object,
1227
+ ['functionDeclarations'],
1228
+ getv(from_object, ['function_declarations']),
1229
+ )
1230
+
1447
1231
  return to_object
1448
1232
 
1449
1233
 
@@ -1628,11 +1412,7 @@ def _GenerateContentConfig_to_vertex(
1628
1412
  setv(
1629
1413
  to_object,
1630
1414
  ['responseSchema'],
1631
- _Schema_to_vertex(
1632
- api_client,
1633
- t.t_schema(api_client, getv(from_object, ['response_schema'])),
1634
- to_object,
1635
- ),
1415
+ t.t_schema(api_client, getv(from_object, ['response_schema'])),
1636
1416
  )
1637
1417
 
1638
1418
  if getv(from_object, ['routing_config']) is not None: