google-genai 1.54.0__tar.gz → 1.56.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.54.0/google_genai.egg-info → google_genai-1.56.0}/PKG-INFO +226 -22
- {google_genai-1.54.0 → google_genai-1.56.0}/README.md +222 -20
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/__init__.py +1 -0
- google_genai-1.56.0/google/genai/_interactions/__init__.py +117 -0
- google_genai-1.56.0/google/genai/_interactions/_base_client.py +2025 -0
- google_genai-1.56.0/google/genai/_interactions/_client.py +511 -0
- google_genai-1.56.0/google/genai/_interactions/_compat.py +234 -0
- google_genai-1.56.0/google/genai/_interactions/_constants.py +29 -0
- google_genai-1.56.0/google/genai/_interactions/_exceptions.py +122 -0
- google_genai-1.56.0/google/genai/_interactions/_files.py +139 -0
- google_genai-1.56.0/google/genai/_interactions/_models.py +873 -0
- google_genai-1.56.0/google/genai/_interactions/_qs.py +165 -0
- google_genai-1.56.0/google/genai/_interactions/_resource.py +58 -0
- google_genai-1.56.0/google/genai/_interactions/_response.py +847 -0
- google_genai-1.56.0/google/genai/_interactions/_streaming.py +354 -0
- google_genai-1.56.0/google/genai/_interactions/_types.py +276 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/__init__.py +79 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_compat.py +61 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_datetime_parse.py +151 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_logs.py +40 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_proxy.py +80 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_reflection.py +57 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_resources_proxy.py +39 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_streams.py +27 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_sync.py +73 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_transform.py +472 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_typing.py +172 -0
- google_genai-1.56.0/google/genai/_interactions/_utils/_utils.py +437 -0
- google_genai-1.56.0/google/genai/_interactions/_version.py +18 -0
- google_genai-1.56.0/google/genai/_interactions/py.typed +0 -0
- google_genai-1.56.0/google/genai/_interactions/resources/__init__.py +34 -0
- google_genai-1.56.0/google/genai/_interactions/resources/interactions.py +1350 -0
- google_genai-1.56.0/google/genai/_interactions/types/__init__.py +109 -0
- google_genai-1.56.0/google/genai/_interactions/types/allowed_tools.py +33 -0
- google_genai-1.56.0/google/genai/_interactions/types/allowed_tools_param.py +35 -0
- google_genai-1.56.0/google/genai/_interactions/types/annotation.py +42 -0
- google_genai-1.56.0/google/genai/_interactions/types/annotation_param.py +42 -0
- google_genai-1.56.0/google/genai/_interactions/types/audio_content.py +37 -0
- google_genai-1.56.0/google/genai/_interactions/types/audio_content_param.py +44 -0
- google_genai-1.56.0/google/genai/_interactions/types/audio_mime_type.py +25 -0
- google_genai-1.56.0/google/genai/_interactions/types/audio_mime_type_param.py +27 -0
- google_genai-1.56.0/google/genai/_interactions/types/code_execution_call_arguments.py +33 -0
- google_genai-1.56.0/google/genai/_interactions/types/code_execution_call_arguments_param.py +32 -0
- google_genai-1.56.0/google/genai/_interactions/types/code_execution_call_content.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/code_execution_call_content_param.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/code_execution_result_content.py +41 -0
- google_genai-1.56.0/google/genai/_interactions/types/code_execution_result_content_param.py +40 -0
- google_genai-1.56.0/google/genai/_interactions/types/content_delta.py +342 -0
- google_genai-1.56.0/google/genai/_interactions/types/content_start.py +79 -0
- google_genai-1.56.0/google/genai/_interactions/types/content_stop.py +35 -0
- google_genai-1.56.0/google/genai/_interactions/types/deep_research_agent_config.py +32 -0
- google_genai-1.56.0/google/genai/_interactions/types/deep_research_agent_config_param.py +31 -0
- google_genai-1.56.0/google/genai/_interactions/types/document_content.py +37 -0
- google_genai-1.56.0/google/genai/_interactions/types/document_content_param.py +44 -0
- google_genai-1.56.0/google/genai/_interactions/types/document_mime_type.py +23 -0
- google_genai-1.56.0/google/genai/_interactions/types/document_mime_type_param.py +25 -0
- google_genai-1.56.0/google/genai/_interactions/types/dynamic_agent_config.py +43 -0
- google_genai-1.56.0/google/genai/_interactions/types/dynamic_agent_config_param.py +32 -0
- google_genai-1.56.0/google/genai/_interactions/types/error_event.py +46 -0
- google_genai-1.56.0/google/genai/_interactions/types/file_search_result_content.py +45 -0
- google_genai-1.56.0/google/genai/_interactions/types/file_search_result_content_param.py +45 -0
- google_genai-1.56.0/google/genai/_interactions/types/function.py +38 -0
- google_genai-1.56.0/google/genai/_interactions/types/function_call_content.py +38 -0
- google_genai-1.56.0/google/genai/_interactions/types/function_call_content_param.py +38 -0
- google_genai-1.56.0/google/genai/_interactions/types/function_param.py +37 -0
- google_genai-1.56.0/google/genai/_interactions/types/function_result_content.py +51 -0
- google_genai-1.56.0/google/genai/_interactions/types/function_result_content_param.py +53 -0
- google_genai-1.56.0/google/genai/_interactions/types/generation_config.py +57 -0
- google_genai-1.56.0/google/genai/_interactions/types/generation_config_param.py +59 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_call_arguments.py +29 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_call_arguments_param.py +31 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_call_content.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_call_content_param.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_result.py +35 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_result_content.py +42 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_result_content_param.py +43 -0
- google_genai-1.56.0/google/genai/_interactions/types/google_search_result_param.py +35 -0
- google_genai-1.56.0/google/genai/_interactions/types/image_content.py +40 -0
- google_genai-1.56.0/google/genai/_interactions/types/image_content_param.py +47 -0
- google_genai-1.56.0/google/genai/_interactions/types/image_mime_type.py +23 -0
- google_genai-1.56.0/google/genai/_interactions/types/image_mime_type_param.py +25 -0
- google_genai-1.56.0/google/genai/_interactions/types/interaction.py +165 -0
- google_genai-1.56.0/google/genai/_interactions/types/interaction_create_params.py +212 -0
- google_genai-1.56.0/google/genai/_interactions/types/interaction_event.py +37 -0
- google_genai-1.56.0/google/genai/_interactions/types/interaction_get_params.py +46 -0
- google_genai-1.56.0/google/genai/_interactions/types/interaction_sse_event.py +32 -0
- google_genai-1.56.0/google/genai/_interactions/types/interaction_status_update.py +37 -0
- google_genai-1.56.0/google/genai/_interactions/types/mcp_server_tool_call_content.py +41 -0
- google_genai-1.56.0/google/genai/_interactions/types/mcp_server_tool_call_content_param.py +41 -0
- google_genai-1.56.0/google/genai/_interactions/types/mcp_server_tool_result_content.py +51 -0
- google_genai-1.56.0/google/genai/_interactions/types/mcp_server_tool_result_content_param.py +53 -0
- google_genai-1.56.0/google/genai/_interactions/types/model.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/model_param.py +38 -0
- google_genai-1.56.0/google/genai/_interactions/types/speech_config.py +35 -0
- google_genai-1.56.0/google/genai/_interactions/types/speech_config_param.py +35 -0
- google_genai-1.56.0/google/genai/_interactions/types/text_content.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/text_content_param.py +37 -0
- google_genai-1.56.0/google/genai/_interactions/types/thinking_level.py +22 -0
- google_genai-1.56.0/google/genai/_interactions/types/thought_content.py +40 -0
- google_genai-1.56.0/google/genai/_interactions/types/thought_content_param.py +46 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool.py +100 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool_choice.py +26 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool_choice_config.py +28 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool_choice_config_param.py +29 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool_choice_param.py +28 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool_choice_type.py +22 -0
- google_genai-1.56.0/google/genai/_interactions/types/tool_param.py +97 -0
- google_genai-1.56.0/google/genai/_interactions/types/turn.py +76 -0
- google_genai-1.56.0/google/genai/_interactions/types/turn_param.py +73 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_call_arguments.py +29 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_call_arguments_param.py +31 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_call_content.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_call_content_param.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_result.py +33 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_result_content.py +42 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_result_content_param.py +43 -0
- google_genai-1.56.0/google/genai/_interactions/types/url_context_result_param.py +32 -0
- google_genai-1.56.0/google/genai/_interactions/types/usage.py +106 -0
- google_genai-1.56.0/google/genai/_interactions/types/usage_param.py +106 -0
- google_genai-1.56.0/google/genai/_interactions/types/video_content.py +40 -0
- google_genai-1.56.0/google/genai/_interactions/types/video_content_param.py +47 -0
- google_genai-1.56.0/google/genai/_interactions/types/video_mime_type.py +36 -0
- google_genai-1.56.0/google/genai/_interactions/types/video_mime_type_param.py +38 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_live_converters.py +33 -30
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_tokens_converters.py +5 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/batches.py +7 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/client.py +226 -1
- google_genai-1.56.0/google/genai/interactions.py +17 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/live.py +4 -3
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/models.py +14 -29
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/tunings.py +1 -27
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/types.py +92 -22
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/version.py +1 -1
- {google_genai-1.54.0 → google_genai-1.56.0/google_genai.egg-info}/PKG-INFO +226 -22
- google_genai-1.56.0/google_genai.egg-info/SOURCES.txt +167 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google_genai.egg-info/requires.txt +3 -1
- {google_genai-1.54.0 → google_genai-1.56.0}/pyproject.toml +20 -4
- {google_genai-1.54.0 → google_genai-1.56.0}/setup.cfg +10 -3
- google_genai-1.54.0/google_genai.egg-info/SOURCES.txt +0 -46
- {google_genai-1.54.0 → google_genai-1.56.0}/LICENSE +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/MANIFEST.in +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_adapters.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_api_client.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_api_module.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_automatic_function_calling_util.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_base_transformers.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_base_url.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_common.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_extra_utils.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_local_tokenizer_loader.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_mcp_utils.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_operations_converters.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_replay_api_client.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/_transformers.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/caches.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/chats.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/documents.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/errors.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/file_search_stores.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/files.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/live_music.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/local_tokenizer.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/operations.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/pagers.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/py.typed +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google/genai/tokens.py +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.54.0 → google_genai-1.56.0}/google_genai.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-genai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.56.0
|
|
4
4
|
Summary: GenAI Python SDK
|
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -20,13 +20,15 @@ Requires-Python: >=3.10
|
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Requires-Dist: anyio<5.0.0,>=4.8.0
|
|
23
|
-
Requires-Dist: google-auth[requests]<3.0.0,>=2.
|
|
23
|
+
Requires-Dist: google-auth[requests]<3.0.0,>=2.45.0
|
|
24
24
|
Requires-Dist: httpx<1.0.0,>=0.28.1
|
|
25
25
|
Requires-Dist: pydantic<3.0.0,>=2.9.0
|
|
26
26
|
Requires-Dist: requests<3.0.0,>=2.28.1
|
|
27
27
|
Requires-Dist: tenacity<9.2.0,>=8.2.3
|
|
28
28
|
Requires-Dist: websockets<15.1.0,>=13.0.0
|
|
29
29
|
Requires-Dist: typing-extensions<5.0.0,>=4.11.0
|
|
30
|
+
Requires-Dist: distro<2,>=1.7.0
|
|
31
|
+
Requires-Dist: sniffio
|
|
30
32
|
Provides-Extra: aiohttp
|
|
31
33
|
Requires-Dist: aiohttp<3.13.3; extra == "aiohttp"
|
|
32
34
|
Provides-Extra: local-tokenizer
|
|
@@ -55,11 +57,7 @@ APIs.
|
|
|
55
57
|
|
|
56
58
|
Generative models are often unaware of recent API and SDK updates and may suggest outdated or legacy code.
|
|
57
59
|
|
|
58
|
-
We recommend using our Code Generation instructions [codegen_instructions.md](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features.
|
|
59
|
-
|
|
60
|
-
Copy and paste the instructions from [this file](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md)
|
|
61
|
-
into your development environment to provide the model with the necessary
|
|
62
|
-
context
|
|
60
|
+
We recommend using our Code Generation instructions [`codegen_instructions.md`](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features. Copy and paste the instructions into your development environment to provide the model with the necessary context.
|
|
63
61
|
|
|
64
62
|
## Installation
|
|
65
63
|
|
|
@@ -172,7 +170,7 @@ client = genai.Client()
|
|
|
172
170
|
## Close a client
|
|
173
171
|
|
|
174
172
|
Explicitly close the sync client to ensure that resources, such as the
|
|
175
|
-
|
|
173
|
+
underlying HTTP connections, are properly cleaned up and closed.
|
|
176
174
|
|
|
177
175
|
```python
|
|
178
176
|
from google.genai import Client
|
|
@@ -213,7 +211,7 @@ await aclient.aclose()
|
|
|
213
211
|
## Client context managers
|
|
214
212
|
|
|
215
213
|
By using the sync client context manager, it will close the underlying
|
|
216
|
-
|
|
214
|
+
sync client when exiting the with block and avoid httpx "client has been closed" error like [issues#1763](https://github.com/googleapis/python-genai/issues/1763).
|
|
217
215
|
|
|
218
216
|
```python
|
|
219
217
|
from google.genai import Client
|
|
@@ -284,7 +282,7 @@ client = genai.Client(
|
|
|
284
282
|
By default we use httpx for both sync and async client implementations. In order
|
|
285
283
|
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
|
|
286
284
|
SDK we configure `trust_env=True` to match with the default behavior of httpx.
|
|
287
|
-
Additional args of `aiohttp.ClientSession.request()` ([see _RequestOptions args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
|
|
285
|
+
Additional args of `aiohttp.ClientSession.request()` ([see `_RequestOptions` args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
|
|
288
286
|
through the following way:
|
|
289
287
|
|
|
290
288
|
```python
|
|
@@ -299,7 +297,7 @@ client=Client(..., http_options=http_options)
|
|
|
299
297
|
|
|
300
298
|
Both httpx and aiohttp libraries use `urllib.request.getproxies` from
|
|
301
299
|
environment variables. Before client initialization, you may set proxy (and
|
|
302
|
-
optional SSL_CERT_FILE) by setting the environment variables:
|
|
300
|
+
optional `SSL_CERT_FILE`) by setting the environment variables:
|
|
303
301
|
|
|
304
302
|
```bash
|
|
305
303
|
export HTTPS_PROXY='http://username:password@proxy_uri:port'
|
|
@@ -322,7 +320,7 @@ client=Client(..., http_options=http_options)
|
|
|
322
320
|
### Custom base url
|
|
323
321
|
|
|
324
322
|
In some cases you might need a custom base url (for example, API gateway proxy
|
|
325
|
-
|
|
323
|
+
server) and bypass some authentication checks for project, location, or API key.
|
|
326
324
|
You may pass the custom base url like this:
|
|
327
325
|
|
|
328
326
|
```python
|
|
@@ -381,7 +379,8 @@ for part in response.parts:
|
|
|
381
379
|
```
|
|
382
380
|
|
|
383
381
|
#### with uploaded file (Gemini Developer API only)
|
|
384
|
-
|
|
382
|
+
|
|
383
|
+
Download the file in console.
|
|
385
384
|
|
|
386
385
|
```sh
|
|
387
386
|
!wget -q https://storage.googleapis.com/generativeai-downloads/data/a11.txt
|
|
@@ -399,11 +398,13 @@ print(response.text)
|
|
|
399
398
|
```
|
|
400
399
|
|
|
401
400
|
#### How to structure `contents` argument for `generate_content`
|
|
401
|
+
|
|
402
402
|
The SDK always converts the inputs to the `contents` argument into
|
|
403
403
|
`list[types.Content]`.
|
|
404
404
|
The following shows some common ways to provide your inputs.
|
|
405
405
|
|
|
406
406
|
##### Provide a `list[types.Content]`
|
|
407
|
+
|
|
407
408
|
This is the canonical way to provide contents, SDK will not do any conversion.
|
|
408
409
|
|
|
409
410
|
##### Provide a `types.Content` instance
|
|
@@ -449,7 +450,7 @@ The SDK will assume this is a text part, and it converts this into the following
|
|
|
449
450
|
Where a `types.UserContent` is a subclass of `types.Content`, it sets the
|
|
450
451
|
`role` field to be `user`.
|
|
451
452
|
|
|
452
|
-
##### Provide a list of
|
|
453
|
+
##### Provide a list of strings
|
|
453
454
|
|
|
454
455
|
```python
|
|
455
456
|
contents=['Why is the sky blue?', 'Why is the cloud white?']
|
|
@@ -518,7 +519,7 @@ contents = [
|
|
|
518
519
|
]
|
|
519
520
|
```
|
|
520
521
|
|
|
521
|
-
The SDK converts a list of function call parts to
|
|
522
|
+
The SDK converts a list of function call parts to a content with a `model` role:
|
|
522
523
|
|
|
523
524
|
```python
|
|
524
525
|
[
|
|
@@ -710,7 +711,9 @@ response = client.models.generate_content(
|
|
|
710
711
|
|
|
711
712
|
print(response.text)
|
|
712
713
|
```
|
|
714
|
+
|
|
713
715
|
#### Disabling automatic function calling
|
|
716
|
+
|
|
714
717
|
If you pass in a python function as a tool directly, and do not want
|
|
715
718
|
automatic function calling, you can disable automatic function calling
|
|
716
719
|
as follows:
|
|
@@ -942,7 +945,9 @@ including by giving examples of expected JSON output. If you do, the generated
|
|
|
942
945
|
output might be lower in quality.
|
|
943
946
|
|
|
944
947
|
#### JSON Schema support
|
|
948
|
+
|
|
945
949
|
Schemas can be provided as standard JSON schema.
|
|
950
|
+
|
|
946
951
|
```python
|
|
947
952
|
user_profile = {
|
|
948
953
|
'properties': {
|
|
@@ -1069,7 +1074,7 @@ print(response.text)
|
|
|
1069
1074
|
|
|
1070
1075
|
#### JSON Response
|
|
1071
1076
|
|
|
1072
|
-
You can also set response_mime_type to 'application/json'
|
|
1077
|
+
You can also set `response_mime_type` to `'application/json'`, the response will be
|
|
1073
1078
|
identical but in quotes.
|
|
1074
1079
|
|
|
1075
1080
|
```python
|
|
@@ -1559,6 +1564,205 @@ response = client.models.generate_content(
|
|
|
1559
1564
|
print(response.text)
|
|
1560
1565
|
```
|
|
1561
1566
|
|
|
1567
|
+
## Interactions (Preview)
|
|
1568
|
+
|
|
1569
|
+
> **Warning:** The Interactions API is in **Beta**. This is a preview of an experimental feature. Features and schemas are subject to **breaking changes**.
|
|
1570
|
+
|
|
1571
|
+
The Interactions API is a unified interface for interacting with Gemini models and agents. It simplifies state management, tool orchestration, and long-running tasks.
|
|
1572
|
+
|
|
1573
|
+
See the [documentation site](https://ai.google.dev/gemini-api/docs/interactions) for more details.
|
|
1574
|
+
|
|
1575
|
+
### Basic Interaction
|
|
1576
|
+
|
|
1577
|
+
```python
|
|
1578
|
+
interaction = client.interactions.create(
|
|
1579
|
+
model='gemini-2.5-flash',
|
|
1580
|
+
input='Tell me a short joke about programming.'
|
|
1581
|
+
)
|
|
1582
|
+
print(interaction.outputs[-1].text)
|
|
1583
|
+
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
### Stateful Conversation
|
|
1587
|
+
|
|
1588
|
+
The Interactions API supports server-side state management. You can continue a conversation by referencing the `previous_interaction_id`.
|
|
1589
|
+
|
|
1590
|
+
```python
|
|
1591
|
+
# 1. First turn
|
|
1592
|
+
interaction1 = client.interactions.create(
|
|
1593
|
+
model='gemini-2.5-flash',
|
|
1594
|
+
input='Hi, my name is Amir.'
|
|
1595
|
+
)
|
|
1596
|
+
print(f"Model: {interaction1.outputs[-1].text}")
|
|
1597
|
+
|
|
1598
|
+
# 2. Second turn (passing previous_interaction_id)
|
|
1599
|
+
interaction2 = client.interactions.create(
|
|
1600
|
+
model='gemini-2.5-flash',
|
|
1601
|
+
input='What is my name?',
|
|
1602
|
+
previous_interaction_id=interaction1.id
|
|
1603
|
+
)
|
|
1604
|
+
print(f"Model: {interaction2.outputs[-1].text}")
|
|
1605
|
+
|
|
1606
|
+
```
|
|
1607
|
+
|
|
1608
|
+
### Agents (Deep Research)
|
|
1609
|
+
|
|
1610
|
+
You can use specialized agents like `deep-research-pro-preview-12-2025` for complex tasks.
|
|
1611
|
+
|
|
1612
|
+
```python
|
|
1613
|
+
import time
|
|
1614
|
+
|
|
1615
|
+
# 1. Start the Deep Research Agent
|
|
1616
|
+
initial_interaction = client.interactions.create(
|
|
1617
|
+
input='Research the history of the Google TPUs with a focus on 2025 and 2026.',
|
|
1618
|
+
agent='deep-research-pro-preview-12-2025',
|
|
1619
|
+
background=True
|
|
1620
|
+
)
|
|
1621
|
+
print(f"Research started. Interaction ID: {initial_interaction.id}")
|
|
1622
|
+
|
|
1623
|
+
# 2. Poll for results
|
|
1624
|
+
while True:
|
|
1625
|
+
interaction = client.interactions.get(id=initial_interaction.id)
|
|
1626
|
+
print(f"Status: {interaction.status}")
|
|
1627
|
+
|
|
1628
|
+
if interaction.status == "completed":
|
|
1629
|
+
print("\nFinal Report:\n", interaction.outputs[-1].text)
|
|
1630
|
+
break
|
|
1631
|
+
elif interaction.status in ["failed", "cancelled"]:
|
|
1632
|
+
print(f"Failed with status: {interaction.status}")
|
|
1633
|
+
break
|
|
1634
|
+
|
|
1635
|
+
time.sleep(10)
|
|
1636
|
+
|
|
1637
|
+
```
|
|
1638
|
+
|
|
1639
|
+
### Multimodal Input
|
|
1640
|
+
|
|
1641
|
+
You can provide multimodal data (text, images, audio, etc.) in the input list.
|
|
1642
|
+
|
|
1643
|
+
```python
|
|
1644
|
+
import base64
|
|
1645
|
+
|
|
1646
|
+
# Assuming you have an image loaded as bytes
|
|
1647
|
+
# base64_image = ...
|
|
1648
|
+
|
|
1649
|
+
interaction = client.interactions.create(
|
|
1650
|
+
model='gemini-2.5-flash',
|
|
1651
|
+
input=[
|
|
1652
|
+
{'type': 'text', 'text': 'Describe the image.'},
|
|
1653
|
+
{'type': 'image', 'data': base64_image, 'mime_type': 'image/png'}
|
|
1654
|
+
]
|
|
1655
|
+
)
|
|
1656
|
+
print(interaction.outputs[-1].text)
|
|
1657
|
+
|
|
1658
|
+
```
|
|
1659
|
+
|
|
1660
|
+
### Function Calling
|
|
1661
|
+
|
|
1662
|
+
You can define custom functions for the model to use. The Interactions API handles the tool selection, and you provide the execution result back to the model.
|
|
1663
|
+
|
|
1664
|
+
```python
|
|
1665
|
+
# 1. Define the tool
|
|
1666
|
+
def get_weather(location: str):
|
|
1667
|
+
"""Gets the weather for a given location."""
|
|
1668
|
+
return f"The weather in {location} is sunny."
|
|
1669
|
+
|
|
1670
|
+
weather_tool = {
|
|
1671
|
+
'type': 'function',
|
|
1672
|
+
'name': 'get_weather',
|
|
1673
|
+
'description': 'Gets the weather for a given location.',
|
|
1674
|
+
'parameters': {
|
|
1675
|
+
'type': 'object',
|
|
1676
|
+
'properties': {
|
|
1677
|
+
'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}
|
|
1678
|
+
},
|
|
1679
|
+
'required': ['location']
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
# 2. Send the request with tools
|
|
1684
|
+
interaction = client.interactions.create(
|
|
1685
|
+
model='gemini-2.5-flash',
|
|
1686
|
+
input='What is the weather in Mountain View, CA?',
|
|
1687
|
+
tools=[weather_tool]
|
|
1688
|
+
)
|
|
1689
|
+
|
|
1690
|
+
# 3. Handle the tool call
|
|
1691
|
+
for output in interaction.outputs:
|
|
1692
|
+
if output.type == 'function_call':
|
|
1693
|
+
print(f"Tool Call: {output.name}({output.arguments})")
|
|
1694
|
+
|
|
1695
|
+
# Execute your actual function here
|
|
1696
|
+
result = get_weather(**output.arguments)
|
|
1697
|
+
|
|
1698
|
+
# Send result back to the model
|
|
1699
|
+
interaction = client.interactions.create(
|
|
1700
|
+
model='gemini-2.5-flash',
|
|
1701
|
+
previous_interaction_id=interaction.id,
|
|
1702
|
+
input=[{
|
|
1703
|
+
'type': 'function_result',
|
|
1704
|
+
'name': output.name,
|
|
1705
|
+
'call_id': output.id,
|
|
1706
|
+
'result': result
|
|
1707
|
+
}]
|
|
1708
|
+
)
|
|
1709
|
+
print(f"Response: {interaction.outputs[-1].text}")
|
|
1710
|
+
|
|
1711
|
+
```
|
|
1712
|
+
|
|
1713
|
+
### Built-in Tools
|
|
1714
|
+
You can also use Google's built-in tools, such as **Google Search** or **Code Execution**.
|
|
1715
|
+
|
|
1716
|
+
#### Grounding with Google Search
|
|
1717
|
+
|
|
1718
|
+
```python
|
|
1719
|
+
interaction = client.interactions.create(
|
|
1720
|
+
model='gemini-2.5-flash',
|
|
1721
|
+
input='Who won the last Super Bowl?',
|
|
1722
|
+
tools=[{'type': 'google_search'}]
|
|
1723
|
+
)
|
|
1724
|
+
|
|
1725
|
+
# Find the text output (not the GoogleSearchResultContent)
|
|
1726
|
+
text_output = next((o for o in interaction.outputs if o.type == 'text'), None)
|
|
1727
|
+
if text_output:
|
|
1728
|
+
print(text_output.text)
|
|
1729
|
+
|
|
1730
|
+
```
|
|
1731
|
+
|
|
1732
|
+
#### Code Execution
|
|
1733
|
+
|
|
1734
|
+
```python
|
|
1735
|
+
interaction = client.interactions.create(
|
|
1736
|
+
model='gemini-2.5-flash',
|
|
1737
|
+
input='Calculate the 50th Fibonacci number.',
|
|
1738
|
+
tools=[{'type': 'code_execution'}]
|
|
1739
|
+
)
|
|
1740
|
+
print(interaction.outputs[-1].text)
|
|
1741
|
+
|
|
1742
|
+
```
|
|
1743
|
+
|
|
1744
|
+
### Multimodal Output
|
|
1745
|
+
|
|
1746
|
+
The Interactions API can generate multimodal outputs, such as images. You must specify the `response_modalities`.
|
|
1747
|
+
|
|
1748
|
+
```python
|
|
1749
|
+
import base64
|
|
1750
|
+
|
|
1751
|
+
interaction = client.interactions.create(
|
|
1752
|
+
model='gemini-3-pro-image-preview',
|
|
1753
|
+
input='Generate an image of a futuristic city.',
|
|
1754
|
+
response_modalities=['IMAGE']
|
|
1755
|
+
)
|
|
1756
|
+
|
|
1757
|
+
for output in interaction.outputs:
|
|
1758
|
+
if output.type == 'image':
|
|
1759
|
+
print(f"Generated image with mime_type: {output.mime_type}")
|
|
1760
|
+
# Save the image
|
|
1761
|
+
with open("generated_city.png", "wb") as f:
|
|
1762
|
+
f.write(base64.b64decode(output.data))
|
|
1763
|
+
|
|
1764
|
+
```
|
|
1765
|
+
|
|
1562
1766
|
## Tunings
|
|
1563
1767
|
|
|
1564
1768
|
`client.tunings` contains tuning job APIs and supports supervised fine
|
|
@@ -1754,13 +1958,14 @@ job
|
|
|
1754
1958
|
```
|
|
1755
1959
|
|
|
1756
1960
|
In order to create a batch job with file name. Need to upload a json file.
|
|
1757
|
-
For example myrequests.json
|
|
1961
|
+
For example `myrequests.json`:
|
|
1758
1962
|
|
|
1759
|
-
```
|
|
1963
|
+
```json
|
|
1760
1964
|
{"key":"request_1", "request": {"contents": [{"parts": [{"text":
|
|
1761
1965
|
"Explain how AI works in a few words"}]}], "generation_config": {"response_modalities": ["TEXT"]}}}
|
|
1762
1966
|
{"key":"request_2", "request": {"contents": [{"parts": [{"text": "Explain how Crypto works in a few words"}]}]}}
|
|
1763
1967
|
```
|
|
1968
|
+
|
|
1764
1969
|
Then upload the file.
|
|
1765
1970
|
|
|
1766
1971
|
```python
|
|
@@ -1777,7 +1982,6 @@ batch_job = client.batches.create(
|
|
|
1777
1982
|
)
|
|
1778
1983
|
```
|
|
1779
1984
|
|
|
1780
|
-
|
|
1781
1985
|
```python
|
|
1782
1986
|
# Get a job by name
|
|
1783
1987
|
job = client.batches.get(name=job.name)
|
|
@@ -1848,7 +2052,7 @@ delete_job
|
|
|
1848
2052
|
|
|
1849
2053
|
## Error Handling
|
|
1850
2054
|
|
|
1851
|
-
To handle errors raised by the model service, the SDK provides this [APIError](https://github.com/googleapis/python-genai/blob/main/google/genai/errors.py) class.
|
|
2055
|
+
To handle errors raised by the model service, the SDK provides this [`APIError`](https://github.com/googleapis/python-genai/blob/main/google/genai/errors.py) class.
|
|
1852
2056
|
|
|
1853
2057
|
```python
|
|
1854
2058
|
from google.genai import errors
|
|
@@ -1870,8 +2074,8 @@ properties to include in the request body. This can be used to access new or
|
|
|
1870
2074
|
experimental backend features that are not yet formally supported in the SDK.
|
|
1871
2075
|
The structure of the dictionary must match the backend API's request structure.
|
|
1872
2076
|
|
|
1873
|
-
-
|
|
1874
|
-
-
|
|
2077
|
+
- Vertex AI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
|
|
2078
|
+
- Gemini API backend API docs: https://ai.google.dev/api/rest
|
|
1875
2079
|
|
|
1876
2080
|
```python
|
|
1877
2081
|
response = client.models.generate_content(
|