google-genai 1.47.0__tar.gz → 1.49.0__tar.gz
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-1.47.0/google_genai.egg-info → google_genai-1.49.0}/PKG-INFO +2 -3
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_api_client.py +5 -1
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_extra_utils.py +36 -3
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_live_converters.py +28 -17
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_operations_converters.py +96 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_replay_api_client.py +24 -39
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_tokens_converters.py +15 -7
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/batches.py +20 -7
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/caches.py +21 -10
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/client.py +11 -0
- google_genai-1.49.0/google/genai/documents.py +549 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/errors.py +1 -1
- google_genai-1.49.0/google/genai/file_search_stores.py +1312 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/models.py +139 -23
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/pagers.py +7 -1
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/tunings.py +313 -2
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/types.py +1705 -393
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/version.py +1 -1
- {google_genai-1.47.0 → google_genai-1.49.0/google_genai.egg-info}/PKG-INFO +2 -3
- {google_genai-1.47.0 → google_genai-1.49.0}/google_genai.egg-info/SOURCES.txt +2 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/pyproject.toml +2 -3
- {google_genai-1.47.0 → google_genai-1.49.0}/LICENSE +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/MANIFEST.in +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/README.md +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/__init__.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_adapters.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_api_module.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_automatic_function_calling_util.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_base_transformers.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_base_url.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_common.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_local_tokenizer_loader.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_mcp_utils.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/_transformers.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/chats.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/files.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/live.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/live_music.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/local_tokenizer.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/operations.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/py.typed +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google/genai/tokens.py +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google_genai.egg-info/requires.txt +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/google_genai.egg-info/top_level.txt +0 -0
- {google_genai-1.47.0 → google_genai-1.49.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-genai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.49.0
|
|
4
4
|
Summary: GenAI Python SDK
|
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -9,7 +9,6 @@ Classifier: Intended Audience :: Developers
|
|
|
9
9
|
Classifier: Operating System :: OS Independent
|
|
10
10
|
Classifier: Programming Language :: Python
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -17,7 +16,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
17
|
Classifier: Topic :: Internet
|
|
19
18
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
-
Requires-Python: >=3.
|
|
19
|
+
Requires-Python: >=3.10
|
|
21
20
|
Description-Content-Type: text/markdown
|
|
22
21
|
License-File: LICENSE
|
|
23
22
|
Requires-Dist: anyio<5.0.0,>=4.8.0
|
|
@@ -1493,7 +1493,7 @@ class BaseApiClient:
|
|
|
1493
1493
|
f'All content has been uploaded, but the upload status is not'
|
|
1494
1494
|
f' finalized.'
|
|
1495
1495
|
)
|
|
1496
|
-
|
|
1496
|
+
errors.APIError.raise_for_response(response)
|
|
1497
1497
|
if response.headers.get('x-goog-upload-status') != 'final':
|
|
1498
1498
|
raise ValueError('Failed to upload file: Upload status is not finalized.')
|
|
1499
1499
|
return HttpResponse(response.headers, response_stream=[response.text])
|
|
@@ -1656,6 +1656,8 @@ class BaseApiClient:
|
|
|
1656
1656
|
f'All content has been uploaded, but the upload status is not'
|
|
1657
1657
|
f' finalized.'
|
|
1658
1658
|
)
|
|
1659
|
+
|
|
1660
|
+
await errors.APIError.raise_for_async_response(response)
|
|
1659
1661
|
if (
|
|
1660
1662
|
response is not None
|
|
1661
1663
|
and response.headers.get('X-Goog-Upload-Status') != 'final'
|
|
@@ -1733,6 +1735,8 @@ class BaseApiClient:
|
|
|
1733
1735
|
'All content has been uploaded, but the upload status is not'
|
|
1734
1736
|
' finalized.'
|
|
1735
1737
|
)
|
|
1738
|
+
|
|
1739
|
+
await errors.APIError.raise_for_async_response(client_response)
|
|
1736
1740
|
if (
|
|
1737
1741
|
client_response is not None
|
|
1738
1742
|
and client_response.headers.get('x-goog-upload-status') != 'final'
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
"""Extra utils depending on types that are shared between sync and async modules."""
|
|
17
17
|
|
|
18
|
+
import asyncio
|
|
18
19
|
import inspect
|
|
19
20
|
import io
|
|
20
21
|
import logging
|
|
@@ -117,6 +118,35 @@ def format_destination(
|
|
|
117
118
|
return config
|
|
118
119
|
|
|
119
120
|
|
|
121
|
+
def find_afc_incompatible_tool_indexes(
|
|
122
|
+
config: Optional[types.GenerateContentConfigOrDict] = None,
|
|
123
|
+
) -> list[int]:
|
|
124
|
+
"""Checks if the config contains any AFC incompatible tools.
|
|
125
|
+
|
|
126
|
+
A `types.Tool` object that contains `function_declarations` is considered a
|
|
127
|
+
non-AFC tool for this execution path.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
config: The GenerateContentConfig to check for incompatible tools.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
A list of indexes of the incompatible tools in the config.
|
|
134
|
+
"""
|
|
135
|
+
if not config:
|
|
136
|
+
return []
|
|
137
|
+
config_model = _create_generate_content_config_model(config)
|
|
138
|
+
incompatible_tools_indexes: list[int] = []
|
|
139
|
+
|
|
140
|
+
if not config_model or not config_model.tools:
|
|
141
|
+
return incompatible_tools_indexes
|
|
142
|
+
|
|
143
|
+
for index, tool in enumerate(config_model.tools):
|
|
144
|
+
if isinstance(tool, types.Tool) and tool.function_declarations:
|
|
145
|
+
incompatible_tools_indexes.append(index)
|
|
146
|
+
|
|
147
|
+
return incompatible_tools_indexes
|
|
148
|
+
|
|
149
|
+
|
|
120
150
|
def get_function_map(
|
|
121
151
|
config: Optional[types.GenerateContentConfigOrDict] = None,
|
|
122
152
|
mcp_to_genai_tool_adapters: Optional[
|
|
@@ -371,7 +401,9 @@ async def get_function_response_parts_async(
|
|
|
371
401
|
}
|
|
372
402
|
else:
|
|
373
403
|
func_response = {
|
|
374
|
-
'result':
|
|
404
|
+
'result': await asyncio.to_thread(
|
|
405
|
+
invoke_function_from_dict_args, args, func
|
|
406
|
+
)
|
|
375
407
|
}
|
|
376
408
|
except Exception as e: # pylint: disable=broad-except
|
|
377
409
|
func_response = {'error': str(e)}
|
|
@@ -536,13 +568,14 @@ async def parse_config_for_mcp_sessions(
|
|
|
536
568
|
def append_chunk_contents(
|
|
537
569
|
contents: Union[types.ContentListUnion, types.ContentListUnionDict],
|
|
538
570
|
chunk: types.GenerateContentResponse,
|
|
539
|
-
) ->
|
|
540
|
-
"""Appends the contents of the chunk to the contents list."""
|
|
571
|
+
) -> Union[types.ContentListUnion, types.ContentListUnionDict]:
|
|
572
|
+
"""Appends the contents of the chunk to the contents list and returns it."""
|
|
541
573
|
if chunk is not None and chunk.candidates is not None:
|
|
542
574
|
chunk_content = chunk.candidates[0].content
|
|
543
575
|
contents = t.t_contents(contents) # type: ignore[assignment]
|
|
544
576
|
if isinstance(contents, list) and chunk_content is not None:
|
|
545
577
|
contents.append(chunk_content) # type: ignore[arg-type]
|
|
578
|
+
return contents
|
|
546
579
|
|
|
547
580
|
|
|
548
581
|
def prepare_resumable_upload(
|
|
@@ -127,6 +127,13 @@ def _GenerationConfig_to_vertex(
|
|
|
127
127
|
getv(from_object, ['model_selection_config']),
|
|
128
128
|
)
|
|
129
129
|
|
|
130
|
+
if getv(from_object, ['response_json_schema']) is not None:
|
|
131
|
+
setv(
|
|
132
|
+
to_object,
|
|
133
|
+
['responseJsonSchema'],
|
|
134
|
+
getv(from_object, ['response_json_schema']),
|
|
135
|
+
)
|
|
136
|
+
|
|
130
137
|
if getv(from_object, ['audio_timestamp']) is not None:
|
|
131
138
|
setv(to_object, ['audioTimestamp'], getv(from_object, ['audio_timestamp']))
|
|
132
139
|
|
|
@@ -165,13 +172,6 @@ def _GenerationConfig_to_vertex(
|
|
|
165
172
|
to_object, ['presencePenalty'], getv(from_object, ['presence_penalty'])
|
|
166
173
|
)
|
|
167
174
|
|
|
168
|
-
if getv(from_object, ['response_json_schema']) is not None:
|
|
169
|
-
setv(
|
|
170
|
-
to_object,
|
|
171
|
-
['responseJsonSchema'],
|
|
172
|
-
getv(from_object, ['response_json_schema']),
|
|
173
|
-
)
|
|
174
|
-
|
|
175
175
|
if getv(from_object, ['response_logprobs']) is not None:
|
|
176
176
|
setv(
|
|
177
177
|
to_object,
|
|
@@ -258,6 +258,11 @@ def _GoogleSearch_to_mldev(
|
|
|
258
258
|
'exclude_domains parameter is not supported in Gemini API.'
|
|
259
259
|
)
|
|
260
260
|
|
|
261
|
+
if getv(from_object, ['blocking_confidence']) is not None:
|
|
262
|
+
raise ValueError(
|
|
263
|
+
'blocking_confidence parameter is not supported in Gemini API.'
|
|
264
|
+
)
|
|
265
|
+
|
|
261
266
|
if getv(from_object, ['time_range_filter']) is not None:
|
|
262
267
|
setv(
|
|
263
268
|
to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
|
|
@@ -1264,16 +1269,12 @@ def _Tool_to_mldev(
|
|
|
1264
1269
|
getv(from_object, ['google_search_retrieval']),
|
|
1265
1270
|
)
|
|
1266
1271
|
|
|
1267
|
-
if getv(from_object, ['google_maps']) is not None:
|
|
1268
|
-
setv(
|
|
1269
|
-
to_object,
|
|
1270
|
-
['googleMaps'],
|
|
1271
|
-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
1272
|
-
)
|
|
1273
|
-
|
|
1274
1272
|
if getv(from_object, ['computer_use']) is not None:
|
|
1275
1273
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
1276
1274
|
|
|
1275
|
+
if getv(from_object, ['file_search']) is not None:
|
|
1276
|
+
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
|
|
1277
|
+
|
|
1277
1278
|
if getv(from_object, ['code_execution']) is not None:
|
|
1278
1279
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
1279
1280
|
|
|
@@ -1282,6 +1283,13 @@ def _Tool_to_mldev(
|
|
|
1282
1283
|
'enterprise_web_search parameter is not supported in Gemini API.'
|
|
1283
1284
|
)
|
|
1284
1285
|
|
|
1286
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
1287
|
+
setv(
|
|
1288
|
+
to_object,
|
|
1289
|
+
['googleMaps'],
|
|
1290
|
+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
1291
|
+
)
|
|
1292
|
+
|
|
1285
1293
|
if getv(from_object, ['google_search']) is not None:
|
|
1286
1294
|
setv(
|
|
1287
1295
|
to_object,
|
|
@@ -1320,12 +1328,12 @@ def _Tool_to_vertex(
|
|
|
1320
1328
|
getv(from_object, ['google_search_retrieval']),
|
|
1321
1329
|
)
|
|
1322
1330
|
|
|
1323
|
-
if getv(from_object, ['google_maps']) is not None:
|
|
1324
|
-
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
|
|
1325
|
-
|
|
1326
1331
|
if getv(from_object, ['computer_use']) is not None:
|
|
1327
1332
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
1328
1333
|
|
|
1334
|
+
if getv(from_object, ['file_search']) is not None:
|
|
1335
|
+
raise ValueError('file_search parameter is not supported in Vertex AI.')
|
|
1336
|
+
|
|
1329
1337
|
if getv(from_object, ['code_execution']) is not None:
|
|
1330
1338
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
1331
1339
|
|
|
@@ -1336,6 +1344,9 @@ def _Tool_to_vertex(
|
|
|
1336
1344
|
getv(from_object, ['enterprise_web_search']),
|
|
1337
1345
|
)
|
|
1338
1346
|
|
|
1347
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
1348
|
+
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
|
|
1349
|
+
|
|
1339
1350
|
if getv(from_object, ['google_search']) is not None:
|
|
1340
1351
|
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
|
|
1341
1352
|
|
|
@@ -256,6 +256,102 @@ def _GetOperationParameters_to_vertex(
|
|
|
256
256
|
return to_object
|
|
257
257
|
|
|
258
258
|
|
|
259
|
+
def _ImportFileOperation_from_mldev(
|
|
260
|
+
from_object: Union[dict[str, Any], object],
|
|
261
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
262
|
+
) -> dict[str, Any]:
|
|
263
|
+
to_object: dict[str, Any] = {}
|
|
264
|
+
if getv(from_object, ['name']) is not None:
|
|
265
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
|
266
|
+
|
|
267
|
+
if getv(from_object, ['metadata']) is not None:
|
|
268
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
|
269
|
+
|
|
270
|
+
if getv(from_object, ['done']) is not None:
|
|
271
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
|
272
|
+
|
|
273
|
+
if getv(from_object, ['error']) is not None:
|
|
274
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
|
275
|
+
|
|
276
|
+
if getv(from_object, ['response']) is not None:
|
|
277
|
+
setv(
|
|
278
|
+
to_object,
|
|
279
|
+
['response'],
|
|
280
|
+
_ImportFileResponse_from_mldev(
|
|
281
|
+
getv(from_object, ['response']), to_object
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
return to_object
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _ImportFileResponse_from_mldev(
|
|
289
|
+
from_object: Union[dict[str, Any], object],
|
|
290
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
291
|
+
) -> dict[str, Any]:
|
|
292
|
+
to_object: dict[str, Any] = {}
|
|
293
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
294
|
+
setv(
|
|
295
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
if getv(from_object, ['parent']) is not None:
|
|
299
|
+
setv(to_object, ['parent'], getv(from_object, ['parent']))
|
|
300
|
+
|
|
301
|
+
if getv(from_object, ['documentName']) is not None:
|
|
302
|
+
setv(to_object, ['document_name'], getv(from_object, ['documentName']))
|
|
303
|
+
|
|
304
|
+
return to_object
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _UploadToFileSearchStoreOperation_from_mldev(
|
|
308
|
+
from_object: Union[dict[str, Any], object],
|
|
309
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
310
|
+
) -> dict[str, Any]:
|
|
311
|
+
to_object: dict[str, Any] = {}
|
|
312
|
+
if getv(from_object, ['name']) is not None:
|
|
313
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
|
314
|
+
|
|
315
|
+
if getv(from_object, ['metadata']) is not None:
|
|
316
|
+
setv(to_object, ['metadata'], getv(from_object, ['metadata']))
|
|
317
|
+
|
|
318
|
+
if getv(from_object, ['done']) is not None:
|
|
319
|
+
setv(to_object, ['done'], getv(from_object, ['done']))
|
|
320
|
+
|
|
321
|
+
if getv(from_object, ['error']) is not None:
|
|
322
|
+
setv(to_object, ['error'], getv(from_object, ['error']))
|
|
323
|
+
|
|
324
|
+
if getv(from_object, ['response']) is not None:
|
|
325
|
+
setv(
|
|
326
|
+
to_object,
|
|
327
|
+
['response'],
|
|
328
|
+
_UploadToFileSearchStoreResponse_from_mldev(
|
|
329
|
+
getv(from_object, ['response']), to_object
|
|
330
|
+
),
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
return to_object
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _UploadToFileSearchStoreResponse_from_mldev(
|
|
337
|
+
from_object: Union[dict[str, Any], object],
|
|
338
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
339
|
+
) -> dict[str, Any]:
|
|
340
|
+
to_object: dict[str, Any] = {}
|
|
341
|
+
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
342
|
+
setv(
|
|
343
|
+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
if getv(from_object, ['parent']) is not None:
|
|
347
|
+
setv(to_object, ['parent'], getv(from_object, ['parent']))
|
|
348
|
+
|
|
349
|
+
if getv(from_object, ['documentName']) is not None:
|
|
350
|
+
setv(to_object, ['document_name'], getv(from_object, ['documentName']))
|
|
351
|
+
|
|
352
|
+
return to_object
|
|
353
|
+
|
|
354
|
+
|
|
259
355
|
def _Video_from_mldev(
|
|
260
356
|
from_object: Union[dict[str, Any], object],
|
|
261
357
|
parent_object: Optional[dict[str, Any]] = None,
|
|
@@ -17,17 +17,16 @@
|
|
|
17
17
|
|
|
18
18
|
import base64
|
|
19
19
|
import copy
|
|
20
|
-
import
|
|
20
|
+
import contextlib
|
|
21
21
|
import enum
|
|
22
22
|
import inspect
|
|
23
23
|
import io
|
|
24
24
|
import json
|
|
25
25
|
import os
|
|
26
26
|
import re
|
|
27
|
-
from typing import Any, Literal, Optional, Union
|
|
27
|
+
from typing import Any, Literal, Optional, Union, Iterator, AsyncIterator
|
|
28
28
|
|
|
29
29
|
import google.auth
|
|
30
|
-
from requests.exceptions import HTTPError
|
|
31
30
|
|
|
32
31
|
from . import errors
|
|
33
32
|
from ._api_client import BaseApiClient
|
|
@@ -210,6 +209,22 @@ def pop_undeterministic_headers(headers: dict[str, str]) -> None:
|
|
|
210
209
|
headers.pop('Server-Timing', None) # pytype: disable=attribute-error
|
|
211
210
|
|
|
212
211
|
|
|
212
|
+
@contextlib.contextmanager
|
|
213
|
+
def _record_on_api_error(client: 'ReplayApiClient', http_request: HttpRequest) -> Iterator[None]:
|
|
214
|
+
try:
|
|
215
|
+
yield
|
|
216
|
+
except errors.APIError as e:
|
|
217
|
+
client._record_interaction(http_request, e)
|
|
218
|
+
raise e
|
|
219
|
+
|
|
220
|
+
@contextlib.asynccontextmanager
|
|
221
|
+
async def _async_record_on_api_error(client: 'ReplayApiClient', http_request: HttpRequest) -> AsyncIterator[None]:
|
|
222
|
+
try:
|
|
223
|
+
yield
|
|
224
|
+
except errors.APIError as e:
|
|
225
|
+
client._record_interaction(http_request, e)
|
|
226
|
+
raise e
|
|
227
|
+
|
|
213
228
|
class ReplayRequest(BaseModel):
|
|
214
229
|
"""Represents a single request in a replay."""
|
|
215
230
|
|
|
@@ -512,11 +527,8 @@ class ReplayApiClient(BaseApiClient):
|
|
|
512
527
|
self._initialize_replay_session_if_not_loaded()
|
|
513
528
|
if self._should_call_api():
|
|
514
529
|
_debug_print('api mode request: %s' % http_request)
|
|
515
|
-
|
|
530
|
+
with _record_on_api_error(self, http_request):
|
|
516
531
|
result = super()._request(http_request, http_options, stream)
|
|
517
|
-
except errors.APIError as e:
|
|
518
|
-
self._record_interaction(http_request, e)
|
|
519
|
-
raise e
|
|
520
532
|
if stream:
|
|
521
533
|
result_segments = []
|
|
522
534
|
for segment in result.segments():
|
|
@@ -541,13 +553,10 @@ class ReplayApiClient(BaseApiClient):
|
|
|
541
553
|
self._initialize_replay_session_if_not_loaded()
|
|
542
554
|
if self._should_call_api():
|
|
543
555
|
_debug_print('api mode request: %s' % http_request)
|
|
544
|
-
|
|
556
|
+
async with _async_record_on_api_error(self, http_request):
|
|
545
557
|
result = await super()._async_request(
|
|
546
558
|
http_request, http_options, stream
|
|
547
559
|
)
|
|
548
|
-
except errors.APIError as e:
|
|
549
|
-
self._record_interaction(http_request, e)
|
|
550
|
-
raise e
|
|
551
560
|
if stream:
|
|
552
561
|
result_segments = []
|
|
553
562
|
async for segment in result.async_segments():
|
|
@@ -587,16 +596,10 @@ class ReplayApiClient(BaseApiClient):
|
|
|
587
596
|
)
|
|
588
597
|
if self._should_call_api():
|
|
589
598
|
result: Union[str, HttpResponse]
|
|
590
|
-
|
|
599
|
+
with _record_on_api_error(self, request):
|
|
591
600
|
result = super().upload_file(
|
|
592
601
|
file_path, upload_url, upload_size, http_options=http_options
|
|
593
602
|
)
|
|
594
|
-
except HTTPError as e:
|
|
595
|
-
result = HttpResponse(
|
|
596
|
-
dict(e.response.headers), [json.dumps({'reason': e.response.reason})]
|
|
597
|
-
)
|
|
598
|
-
result.status_code = e.response.status_code
|
|
599
|
-
raise e
|
|
600
603
|
self._record_interaction(request, result)
|
|
601
604
|
return result
|
|
602
605
|
else:
|
|
@@ -626,16 +629,10 @@ class ReplayApiClient(BaseApiClient):
|
|
|
626
629
|
)
|
|
627
630
|
if self._should_call_api():
|
|
628
631
|
result: HttpResponse
|
|
629
|
-
|
|
632
|
+
async with _async_record_on_api_error(self, request):
|
|
630
633
|
result = await super().async_upload_file(
|
|
631
634
|
file_path, upload_url, upload_size, http_options=http_options
|
|
632
635
|
)
|
|
633
|
-
except HTTPError as e:
|
|
634
|
-
result = HttpResponse(
|
|
635
|
-
dict(e.response.headers), [json.dumps({'reason': e.response.reason})]
|
|
636
|
-
)
|
|
637
|
-
result.status_code = e.response.status_code
|
|
638
|
-
raise e
|
|
639
636
|
self._record_interaction(request, result)
|
|
640
637
|
return result
|
|
641
638
|
else:
|
|
@@ -649,14 +646,8 @@ class ReplayApiClient(BaseApiClient):
|
|
|
649
646
|
'get', path=path, request_dict={}, http_options=http_options
|
|
650
647
|
)
|
|
651
648
|
if self._should_call_api():
|
|
652
|
-
|
|
649
|
+
with _record_on_api_error(self, request):
|
|
653
650
|
result = super().download_file(path, http_options=http_options)
|
|
654
|
-
except HTTPError as e:
|
|
655
|
-
result = HttpResponse(
|
|
656
|
-
dict(e.response.headers), [json.dumps({'reason': e.response.reason})]
|
|
657
|
-
)
|
|
658
|
-
result.status_code = e.response.status_code
|
|
659
|
-
raise e
|
|
660
651
|
self._record_interaction(request, result)
|
|
661
652
|
return result
|
|
662
653
|
else:
|
|
@@ -670,16 +661,10 @@ class ReplayApiClient(BaseApiClient):
|
|
|
670
661
|
'get', path=path, request_dict={}, http_options=http_options
|
|
671
662
|
)
|
|
672
663
|
if self._should_call_api():
|
|
673
|
-
|
|
664
|
+
async with _async_record_on_api_error(self, request):
|
|
674
665
|
result = await super().async_download_file(
|
|
675
666
|
path, http_options=http_options
|
|
676
667
|
)
|
|
677
|
-
except HTTPError as e:
|
|
678
|
-
result = HttpResponse(
|
|
679
|
-
dict(e.response.headers), [json.dumps({'reason': e.response.reason})]
|
|
680
|
-
)
|
|
681
|
-
result.status_code = e.response.status_code
|
|
682
|
-
raise e
|
|
683
668
|
self._record_interaction(request, result)
|
|
684
669
|
return result
|
|
685
670
|
else:
|
|
@@ -172,6 +172,11 @@ def _GoogleSearch_to_mldev(
|
|
|
172
172
|
'exclude_domains parameter is not supported in Gemini API.'
|
|
173
173
|
)
|
|
174
174
|
|
|
175
|
+
if getv(from_object, ['blocking_confidence']) is not None:
|
|
176
|
+
raise ValueError(
|
|
177
|
+
'blocking_confidence parameter is not supported in Gemini API.'
|
|
178
|
+
)
|
|
179
|
+
|
|
175
180
|
if getv(from_object, ['time_range_filter']) is not None:
|
|
176
181
|
setv(
|
|
177
182
|
to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
|
|
@@ -449,16 +454,12 @@ def _Tool_to_mldev(
|
|
|
449
454
|
getv(from_object, ['google_search_retrieval']),
|
|
450
455
|
)
|
|
451
456
|
|
|
452
|
-
if getv(from_object, ['google_maps']) is not None:
|
|
453
|
-
setv(
|
|
454
|
-
to_object,
|
|
455
|
-
['googleMaps'],
|
|
456
|
-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
457
|
-
)
|
|
458
|
-
|
|
459
457
|
if getv(from_object, ['computer_use']) is not None:
|
|
460
458
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
461
459
|
|
|
460
|
+
if getv(from_object, ['file_search']) is not None:
|
|
461
|
+
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
|
|
462
|
+
|
|
462
463
|
if getv(from_object, ['code_execution']) is not None:
|
|
463
464
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
464
465
|
|
|
@@ -467,6 +468,13 @@ def _Tool_to_mldev(
|
|
|
467
468
|
'enterprise_web_search parameter is not supported in Gemini API.'
|
|
468
469
|
)
|
|
469
470
|
|
|
471
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
472
|
+
setv(
|
|
473
|
+
to_object,
|
|
474
|
+
['googleMaps'],
|
|
475
|
+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
476
|
+
)
|
|
477
|
+
|
|
470
478
|
if getv(from_object, ['google_search']) is not None:
|
|
471
479
|
setv(
|
|
472
480
|
to_object,
|
|
@@ -328,6 +328,11 @@ def _BatchJob_from_vertex(
|
|
|
328
328
|
),
|
|
329
329
|
)
|
|
330
330
|
|
|
331
|
+
if getv(from_object, ['completionStats']) is not None:
|
|
332
|
+
setv(
|
|
333
|
+
to_object, ['completion_stats'], getv(from_object, ['completionStats'])
|
|
334
|
+
)
|
|
335
|
+
|
|
331
336
|
return to_object
|
|
332
337
|
|
|
333
338
|
|
|
@@ -1040,6 +1045,11 @@ def _GoogleSearch_to_mldev(
|
|
|
1040
1045
|
'exclude_domains parameter is not supported in Gemini API.'
|
|
1041
1046
|
)
|
|
1042
1047
|
|
|
1048
|
+
if getv(from_object, ['blocking_confidence']) is not None:
|
|
1049
|
+
raise ValueError(
|
|
1050
|
+
'blocking_confidence parameter is not supported in Gemini API.'
|
|
1051
|
+
)
|
|
1052
|
+
|
|
1043
1053
|
if getv(from_object, ['time_range_filter']) is not None:
|
|
1044
1054
|
setv(
|
|
1045
1055
|
to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
|
|
@@ -1327,16 +1337,12 @@ def _Tool_to_mldev(
|
|
|
1327
1337
|
getv(from_object, ['google_search_retrieval']),
|
|
1328
1338
|
)
|
|
1329
1339
|
|
|
1330
|
-
if getv(from_object, ['google_maps']) is not None:
|
|
1331
|
-
setv(
|
|
1332
|
-
to_object,
|
|
1333
|
-
['googleMaps'],
|
|
1334
|
-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
1335
|
-
)
|
|
1336
|
-
|
|
1337
1340
|
if getv(from_object, ['computer_use']) is not None:
|
|
1338
1341
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
1339
1342
|
|
|
1343
|
+
if getv(from_object, ['file_search']) is not None:
|
|
1344
|
+
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
|
|
1345
|
+
|
|
1340
1346
|
if getv(from_object, ['code_execution']) is not None:
|
|
1341
1347
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
1342
1348
|
|
|
@@ -1345,6 +1351,13 @@ def _Tool_to_mldev(
|
|
|
1345
1351
|
'enterprise_web_search parameter is not supported in Gemini API.'
|
|
1346
1352
|
)
|
|
1347
1353
|
|
|
1354
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
1355
|
+
setv(
|
|
1356
|
+
to_object,
|
|
1357
|
+
['googleMaps'],
|
|
1358
|
+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
1359
|
+
)
|
|
1360
|
+
|
|
1348
1361
|
if getv(from_object, ['google_search']) is not None:
|
|
1349
1362
|
setv(
|
|
1350
1363
|
to_object,
|
|
@@ -386,6 +386,11 @@ def _GoogleSearch_to_mldev(
|
|
|
386
386
|
'exclude_domains parameter is not supported in Gemini API.'
|
|
387
387
|
)
|
|
388
388
|
|
|
389
|
+
if getv(from_object, ['blocking_confidence']) is not None:
|
|
390
|
+
raise ValueError(
|
|
391
|
+
'blocking_confidence parameter is not supported in Gemini API.'
|
|
392
|
+
)
|
|
393
|
+
|
|
389
394
|
if getv(from_object, ['time_range_filter']) is not None:
|
|
390
395
|
setv(
|
|
391
396
|
to_object, ['timeRangeFilter'], getv(from_object, ['time_range_filter'])
|
|
@@ -586,16 +591,12 @@ def _Tool_to_mldev(
|
|
|
586
591
|
getv(from_object, ['google_search_retrieval']),
|
|
587
592
|
)
|
|
588
593
|
|
|
589
|
-
if getv(from_object, ['google_maps']) is not None:
|
|
590
|
-
setv(
|
|
591
|
-
to_object,
|
|
592
|
-
['googleMaps'],
|
|
593
|
-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
594
|
-
)
|
|
595
|
-
|
|
596
594
|
if getv(from_object, ['computer_use']) is not None:
|
|
597
595
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
598
596
|
|
|
597
|
+
if getv(from_object, ['file_search']) is not None:
|
|
598
|
+
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
|
|
599
|
+
|
|
599
600
|
if getv(from_object, ['code_execution']) is not None:
|
|
600
601
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
601
602
|
|
|
@@ -604,6 +605,13 @@ def _Tool_to_mldev(
|
|
|
604
605
|
'enterprise_web_search parameter is not supported in Gemini API.'
|
|
605
606
|
)
|
|
606
607
|
|
|
608
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
609
|
+
setv(
|
|
610
|
+
to_object,
|
|
611
|
+
['googleMaps'],
|
|
612
|
+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
|
|
613
|
+
)
|
|
614
|
+
|
|
607
615
|
if getv(from_object, ['google_search']) is not None:
|
|
608
616
|
setv(
|
|
609
617
|
to_object,
|
|
@@ -642,12 +650,12 @@ def _Tool_to_vertex(
|
|
|
642
650
|
getv(from_object, ['google_search_retrieval']),
|
|
643
651
|
)
|
|
644
652
|
|
|
645
|
-
if getv(from_object, ['google_maps']) is not None:
|
|
646
|
-
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
|
|
647
|
-
|
|
648
653
|
if getv(from_object, ['computer_use']) is not None:
|
|
649
654
|
setv(to_object, ['computerUse'], getv(from_object, ['computer_use']))
|
|
650
655
|
|
|
656
|
+
if getv(from_object, ['file_search']) is not None:
|
|
657
|
+
raise ValueError('file_search parameter is not supported in Vertex AI.')
|
|
658
|
+
|
|
651
659
|
if getv(from_object, ['code_execution']) is not None:
|
|
652
660
|
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
|
|
653
661
|
|
|
@@ -658,6 +666,9 @@ def _Tool_to_vertex(
|
|
|
658
666
|
getv(from_object, ['enterprise_web_search']),
|
|
659
667
|
)
|
|
660
668
|
|
|
669
|
+
if getv(from_object, ['google_maps']) is not None:
|
|
670
|
+
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
|
|
671
|
+
|
|
661
672
|
if getv(from_object, ['google_search']) is not None:
|
|
662
673
|
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
|
|
663
674
|
|
|
@@ -27,6 +27,7 @@ from ._replay_api_client import ReplayApiClient
|
|
|
27
27
|
from .batches import AsyncBatches, Batches
|
|
28
28
|
from .caches import AsyncCaches, Caches
|
|
29
29
|
from .chats import AsyncChats, Chats
|
|
30
|
+
from .file_search_stores import AsyncFileSearchStores, FileSearchStores
|
|
30
31
|
from .files import AsyncFiles, Files
|
|
31
32
|
from .live import AsyncLive
|
|
32
33
|
from .models import AsyncModels, Models
|
|
@@ -47,6 +48,7 @@ class AsyncClient:
|
|
|
47
48
|
self._caches = AsyncCaches(self._api_client)
|
|
48
49
|
self._batches = AsyncBatches(self._api_client)
|
|
49
50
|
self._files = AsyncFiles(self._api_client)
|
|
51
|
+
self._file_search_stores = AsyncFileSearchStores(self._api_client)
|
|
50
52
|
self._live = AsyncLive(self._api_client)
|
|
51
53
|
self._tokens = AsyncTokens(self._api_client)
|
|
52
54
|
self._operations = AsyncOperations(self._api_client)
|
|
@@ -63,6 +65,10 @@ class AsyncClient:
|
|
|
63
65
|
def caches(self) -> AsyncCaches:
|
|
64
66
|
return self._caches
|
|
65
67
|
|
|
68
|
+
@property
|
|
69
|
+
def file_search_stores(self) -> AsyncFileSearchStores:
|
|
70
|
+
return self._file_search_stores
|
|
71
|
+
|
|
66
72
|
@property
|
|
67
73
|
def batches(self) -> AsyncBatches:
|
|
68
74
|
return self._batches
|
|
@@ -276,6 +282,7 @@ class Client:
|
|
|
276
282
|
self._models = Models(self._api_client)
|
|
277
283
|
self._tunings = Tunings(self._api_client)
|
|
278
284
|
self._caches = Caches(self._api_client)
|
|
285
|
+
self._file_search_stores = FileSearchStores(self._api_client)
|
|
279
286
|
self._batches = Batches(self._api_client)
|
|
280
287
|
self._files = Files(self._api_client)
|
|
281
288
|
self._tokens = Tokens(self._api_client)
|
|
@@ -337,6 +344,10 @@ class Client:
|
|
|
337
344
|
def caches(self) -> Caches:
|
|
338
345
|
return self._caches
|
|
339
346
|
|
|
347
|
+
@property
|
|
348
|
+
def file_search_stores(self) -> FileSearchStores:
|
|
349
|
+
return self._file_search_stores
|
|
350
|
+
|
|
340
351
|
@property
|
|
341
352
|
def batches(self) -> Batches:
|
|
342
353
|
return self._batches
|