├── docs ├── .nojekyll ├── _static │ ├── scripts │ │ ├── furo-extensions.js │ │ └── furo.js.LICENSE.txt │ ├── file.png │ ├── minus.png │ ├── plus.png │ ├── autodoc_pydantic.css │ ├── documentation_options.js │ ├── css │ │ └── custom.css │ └── debug.css ├── objects.inv └── _sources │ ├── modules.rst.txt │ └── genai.rst.txt ├── google └── genai │ ├── tests │ ├── interactions │ │ └── __init__.py │ ├── errors │ │ └── __init__.py │ ├── chats │ │ └── __init__.py │ ├── data │ │ ├── dog.jpg │ │ ├── man.jpg │ │ ├── animal.mp4 │ │ ├── google.jpg │ │ ├── google.png │ │ ├── pixel.m4a │ │ ├── story.pdf │ │ ├── bridge1.png │ │ ├── checkerboard.png │ │ ├── google_small.png │ │ ├── voice_sample.wav │ │ ├── a-man-and-a-dog.png │ │ ├── google_homepage.png │ │ ├── segmentation_scribble.jpg │ │ ├── skateboard_stop_sign.jpg │ │ └── story.txt │ ├── credentials.json │ ├── models │ │ ├── constants.py │ │ ├── __init__.py │ │ ├── test_generate_content_http_options.py │ │ └── test_generate_content_from_apikey.py │ ├── transformers │ │ ├── test_bytes.py │ │ └── __init__.py │ ├── shared │ │ ├── batches │ │ │ ├── __init__.py │ │ │ ├── test_list.py │ │ │ └── test_create_get_cancel.py │ │ ├── caches │ │ │ ├── __init__.py │ │ │ └── test_list.py │ │ ├── chats │ │ │ ├── __init__.py │ │ │ ├── test_send_message.py │ │ │ └── test_send_message_stream.py │ │ ├── files │ │ │ ├── __init__.py │ │ │ ├── test_list.py │ │ │ └── test_upload_get_delete.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── test_list.py │ │ │ ├── test_generate_videos.py │ │ │ ├── test_embed.py │ │ │ ├── test_count_tokens.py │ │ │ ├── test_generate_content.py │ │ │ ├── test_compute_tokens.py │ │ │ ├── test_generate_images.py │ │ │ ├── test_generate_content_stream.py │ │ │ ├── test_segment_image.py │ │ │ ├── test_upscale_image.py │ │ │ └── test_recontext_image.py │ │ ├── __init__.py │ │ └── tunings │ │ │ ├── __init__.py │ │ │ ├── test_list.py │ │ │ └── test_create.py │ ├── live │ │ └── __init__.py │ ├── tokens │ │ └── __init__.py │ ├── tunings │ │ ├── __init__.py │ │ └── test_cancel.py │ ├── types │ │ ├── __init__.py │ │ └── test_optional_types.py │ ├── operations │ │ ├── __init__.py │ │ └── test_get.py │ ├── client │ │ └── __init__.py │ ├── files │ │ ├── __init__.py │ │ ├── test_get.py │ │ └── test_delete.py │ ├── batches │ │ └── __init__.py │ ├── common │ │ └── __init__.py │ ├── mcp │ │ └── __init__.py │ ├── caches │ │ ├── __init__.py │ │ ├── constants.py │ │ ├── test_get_custom_url.py │ │ └── test_delete_custom_url.py │ ├── documents │ │ ├── __init__.py │ │ └── test_delete.py │ ├── public_samples │ │ ├── __init__.py │ │ └── test_gemini_text_only.py │ ├── local_tokenizer │ │ └── __init__.py │ ├── file_search_stores │ │ └── __init__.py │ ├── __init__.py │ ├── afc │ │ ├── __init__.py │ │ └── test_should_append_afc_history.py │ └── imports │ │ └── test_no_optional_imports.py │ ├── py.typed │ ├── version.py │ ├── interactions.py │ ├── _interactions │ ├── _version.py │ ├── types │ │ ├── thinking_level.py │ │ ├── tool_choice_type.py │ │ ├── image_mime_type.py │ │ ├── audio_mime_type.py │ │ ├── tool_choice.py │ │ ├── image_mime_type_param.py │ │ ├── tool_choice_config.py │ │ ├── audio_mime_type_param.py │ │ ├── url_context_call_arguments.py │ │ ├── tool_choice_param.py │ │ ├── tool_choice_config_param.py │ │ ├── google_search_call_arguments.py │ │ ├── url_context_call_arguments_param.py │ │ ├── url_context_result_param.py │ │ ├── allowed_tools.py │ │ ├── google_search_call_arguments_param.py │ │ ├── video_mime_type.py │ │ ├── code_execution_call_arguments_param.py │ │ ├── content_stop.py │ │ ├── url_context_result.py │ │ ├── code_execution_call_arguments.py │ │ ├── document_content.py │ │ ├── speech_config_param.py │ │ ├── allowed_tools_param.py │ │ ├── video_mime_type_param.py │ │ ├── speech_config.py │ │ ├── google_search_result_param.py │ │ ├── google_search_result.py │ │ ├── deep_research_agent_config_param.py │ │ ├── function_param.py │ │ ├── dynamic_agent_config_param.py │ │ ├── function.py │ │ ├── deep_research_agent_config.py │ │ ├── model.py │ │ ├── audio_content.py │ │ ├── interaction_sse_event.py │ │ ├── text_content.py │ │ ├── interaction_event.py │ │ ├── function_call_content.py │ │ ├── model_param.py │ │ ├── text_content_param.py │ │ ├── interaction_status_update.py │ │ ├── url_context_call_content.py │ │ ├── google_search_call_content.py │ │ ├── url_context_call_content_param.py │ │ ├── code_execution_call_content.py │ │ ├── image_content.py │ │ ├── video_content.py │ │ ├── annotation_param.py │ │ ├── google_search_call_content_param.py │ │ ├── annotation.py │ │ ├── code_execution_call_content_param.py │ │ ├── function_call_content_param.py │ │ ├── mcp_server_tool_call_content.py │ │ ├── error_event.py │ │ ├── code_execution_result_content_param.py │ │ ├── document_content_param.py │ │ ├── code_execution_result_content.py │ │ ├── mcp_server_tool_call_content_param.py │ │ ├── thought_content.py │ │ ├── file_search_result_content.py │ │ ├── file_search_result_content_param.py │ │ ├── url_context_result_content.py │ │ ├── audio_content_param.py │ │ ├── url_context_result_content_param.py │ │ ├── google_search_result_content.py │ │ ├── google_search_result_content_param.py │ │ ├── image_content_param.py │ │ ├── video_content_param.py │ │ ├── interaction_get_params.py │ │ ├── function_result_content.py │ │ ├── thought_content_param.py │ │ ├── dynamic_agent_config.py │ │ ├── mcp_server_tool_result_content.py │ │ └── function_result_content_param.py │ ├── _utils │ │ ├── _streams.py │ │ ├── _resources_proxy.py │ │ └── _logs.py │ ├── _constants.py │ └── resources │ │ └── __init__.py │ ├── __init__.py │ ├── _api_module.py │ ├── _base_transformers.py │ ├── _base_url.py │ └── _adapters.py ├── .github ├── release-trigger.yml ├── release-please.yml └── workflows │ ├── import.yml │ ├── mypy.yml │ └── stale.yml ├── MANIFEST.in ├── CONTRIBUTING.md ├── setup.cfg ├── .gitignore └── requirements.txt /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_static/scripts/furo-extensions.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /google/genai/tests/interactions/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/release-trigger.yml: -------------------------------------------------------------------------------- 1 | enabled: true 2 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md -------------------------------------------------------------------------------- /google/genai/py.typed: -------------------------------------------------------------------------------- 1 | # see: https://peps.python.org/pep-0561/ -------------------------------------------------------------------------------- /google/genai/tests/errors/__init__.py: -------------------------------------------------------------------------------- 1 | """Unit Tests for the error modules.""" -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/docs/objects.inv -------------------------------------------------------------------------------- /google/genai/tests/chats/__init__.py: -------------------------------------------------------------------------------- 1 | """Tests for the Google GenAI SDK's chats module.""" 2 | -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/docs/_static/minus.png -------------------------------------------------------------------------------- /docs/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/docs/_static/plus.png -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | The Google Gen AI SDK will accept contributions in the future. 4 | -------------------------------------------------------------------------------- /docs/_sources/modules.rst.txt: -------------------------------------------------------------------------------- 1 | google 2 | ====== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | genai 8 | -------------------------------------------------------------------------------- /google/genai/tests/data/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/dog.jpg -------------------------------------------------------------------------------- /google/genai/tests/data/man.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/man.jpg -------------------------------------------------------------------------------- /google/genai/tests/data/animal.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/animal.mp4 -------------------------------------------------------------------------------- /google/genai/tests/data/google.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/google.jpg -------------------------------------------------------------------------------- /google/genai/tests/data/google.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/google.png -------------------------------------------------------------------------------- /google/genai/tests/data/pixel.m4a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/pixel.m4a -------------------------------------------------------------------------------- /google/genai/tests/data/story.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/story.pdf -------------------------------------------------------------------------------- /google/genai/tests/data/bridge1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/bridge1.png -------------------------------------------------------------------------------- /google/genai/tests/credentials.json: -------------------------------------------------------------------------------- 1 | // Dummy value to ensure tests can be run for Vertex AI. 2 | { 3 | "type": "service_account" 4 | } 5 | -------------------------------------------------------------------------------- /google/genai/tests/data/checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/checkerboard.png -------------------------------------------------------------------------------- /google/genai/tests/data/google_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/google_small.png -------------------------------------------------------------------------------- /google/genai/tests/data/voice_sample.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/voice_sample.wav -------------------------------------------------------------------------------- /google/genai/tests/data/a-man-and-a-dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/a-man-and-a-dog.png -------------------------------------------------------------------------------- /google/genai/tests/data/google_homepage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/google_homepage.png -------------------------------------------------------------------------------- /.github/release-please.yml: -------------------------------------------------------------------------------- 1 | releaseType: python 2 | handleGHRelease: true 3 | bumpMinorPreMajor: false 4 | extraFiles: 5 | - google/genai/version.py 6 | -------------------------------------------------------------------------------- /google/genai/tests/data/segmentation_scribble.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/segmentation_scribble.jpg -------------------------------------------------------------------------------- /google/genai/tests/data/skateboard_stop_sign.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/python-genai/HEAD/google/genai/tests/data/skateboard_stop_sign.jpg -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [options] 2 | include_package_data = True 3 | 4 | [options.packages.find] 5 | where = 6 | . 7 | include = 8 | google.genai 9 | google.genai.* 10 | exclude = 11 | tests 12 | tests.* -------------------------------------------------------------------------------- /docs/_static/scripts/furo.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * gumshoejs v5.1.2 (patched by @pradyunsg) 3 | * A simple, framework-agnostic scrollspy script. 4 | * (c) 2019 Chris Ferdinandi 5 | * MIT License 6 | * http://github.com/cferdinandi/gumshoe 7 | */ 8 | -------------------------------------------------------------------------------- /docs/_static/autodoc_pydantic.css: -------------------------------------------------------------------------------- 1 | .autodoc_pydantic_validator_arrow { 2 | padding-left: 8px; 3 | } 4 | 5 | .autodoc_pydantic_collapsable_json { 6 | cursor: pointer; 7 | } 8 | 9 | .autodoc_pydantic_collapsable_erd { 10 | cursor: pointer; 11 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build artifacts 2 | *.py[cod] 3 | google_genai.egg-info/ 4 | build/ 5 | dist/ 6 | 7 | # Test files 8 | .nox/ 9 | 10 | # Coverage files 11 | .coverage 12 | coverage.xml 13 | nosetests.xml 14 | 15 | # IDE files 16 | .idea 17 | .vscode 18 | 19 | # macOS 20 | .DS_Store 21 | -------------------------------------------------------------------------------- /google/genai/tests/models/constants.py: -------------------------------------------------------------------------------- 1 | VERTEX_HTTP_OPTIONS = { 2 | 'api_version': 'v1beta1', 3 | 'base_url': 'https://us-central1-aiplatform.googleapis.com/', 4 | } 5 | MLDEV_HTTP_OPTIONS = { 6 | 'api_version': 'v1beta', 7 | 'base_url': 'https://generativelanguage.googleapis.com/', 8 | } 9 | -------------------------------------------------------------------------------- /docs/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | const DOCUMENTATION_OPTIONS = { 2 | VERSION: '', 3 | LANGUAGE: 'en', 4 | COLLAPSE_INDEX: false, 5 | BUILDER: 'html', 6 | FILE_SUFFIX: '.html', 7 | LINK_SUFFIX: '.html', 8 | HAS_SOURCE: true, 9 | SOURCELINK_SUFFIX: '.txt', 10 | NAVIGATION_WITH_KEYS: false, 11 | SHOW_SEARCH_SUMMARY: true, 12 | ENABLE_SEARCH_SHORTCUTS: true, 13 | }; -------------------------------------------------------------------------------- /google/genai/tests/transformers/test_bytes.py: -------------------------------------------------------------------------------- 1 | """Tests t_bytes methods in the _transformers module.""" 2 | 3 | import base64 4 | 5 | from ... import _base_transformers as t 6 | 7 | _RAW_BYTES = ( 8 | b'\xfb\xf6\x9bq\xd7\x9f\x82\x18\xa3\x92Y\xa7\xa2\x9a\xab\xb2\xdb\xaf\xc3\x1c\xb3\x00\x10\x83\x10Q\x87' 9 | b' \x92\x8b0\xd3\x8fA\x14\x93QU\x97a\x9d5\xdb~9\xeb\xbf=' 10 | ) 11 | 12 | 13 | def test_t_bytes(): 14 | assert t.t_bytes(_RAW_BYTES) == base64.b64encode(_RAW_BYTES).decode('ascii') 15 | assert t.t_bytes('string') == 'string' 16 | -------------------------------------------------------------------------------- /google/genai/tests/shared/batches/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | -------------------------------------------------------------------------------- /google/genai/tests/shared/caches/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | -------------------------------------------------------------------------------- /google/genai/tests/shared/chats/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | -------------------------------------------------------------------------------- /google/genai/tests/shared/files/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | -------------------------------------------------------------------------------- /google/genai/tests/live/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | -------------------------------------------------------------------------------- /google/genai/tests/shared/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | -------------------------------------------------------------------------------- /google/genai/tests/tokens/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | -------------------------------------------------------------------------------- /google/genai/tests/tunings/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | -------------------------------------------------------------------------------- /google/genai/tests/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | -------------------------------------------------------------------------------- /google/genai/tests/shared/tunings/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css?family=Google+Sans:400,500|Roboto:400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap'); 2 | 3 | body { 4 | font-weight: 400; 5 | } 6 | 7 | h1 { 8 | font-size: 32px; 9 | font-weight: 400; 10 | } 11 | 12 | h2 { 13 | font-size: 24px; 14 | font-weight: 400; 15 | } 16 | 17 | h3 { 18 | font-size: 20px; 19 | font-weight: 400; 20 | } 21 | 22 | h4 { 23 | font-size: 16px; 24 | font-weight: 400; 25 | } 26 | 27 | .sidebar-brand-text { 28 | font-size: 14px; 29 | } 30 | 31 | .highlight { 32 | box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2); 33 | } -------------------------------------------------------------------------------- /google/genai/version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | __version__ = '1.55.0' # x-release-please-version 17 | -------------------------------------------------------------------------------- /google/genai/tests/operations/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for operations.get.""" 18 | -------------------------------------------------------------------------------- /google/genai/tests/client/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK.""" 18 | -------------------------------------------------------------------------------- /google/genai/tests/files/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's files module.""" -------------------------------------------------------------------------------- /google/genai/tests/batches/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's batches module.""" -------------------------------------------------------------------------------- /google/genai/tests/common/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's _common module.""" -------------------------------------------------------------------------------- /google/genai/tests/mcp/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's _mcp_utils module.""" -------------------------------------------------------------------------------- /google/genai/tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's models module.""" -------------------------------------------------------------------------------- /google/genai/interactions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | """Expose stainless types.""" 16 | 17 | from ._interactions.types import * 18 | -------------------------------------------------------------------------------- /google/genai/tests/caches/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's caches module.""" 18 | -------------------------------------------------------------------------------- /google/genai/tests/documents/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's documents module.""" 18 | -------------------------------------------------------------------------------- /google/genai/tests/transformers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's _transformers module.""" -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | absl-py==2.1.0 2 | annotated-types==0.7.0 3 | anyio==4.8.0 4 | cachetools==5.5.0 5 | certifi==2024.8.30 6 | charset-normalizer==3.4.0 7 | coverage==7.6.9 8 | distro==1.9.0 9 | httpx==0.28.1 10 | google-auth==2.37.0 11 | idna==3.10 12 | iniconfig==2.0.0 13 | packaging==24.2 14 | pillow==11.0.0 15 | pluggy==1.5.0 16 | py==1.11.0 17 | pyasn1==0.6.1 18 | pyasn1_modules==0.4.1 19 | pydantic==2.12.0 20 | pydantic_core==2.41.1 21 | pytest==8.3.4 22 | pytest-asyncio==0.25.0 23 | pytest-cov==6.0.0 24 | pytest-xdist==3.8.0 25 | requests==2.32.4 26 | rsa==4.9 27 | tenacity==8.2.3 28 | typing_extensions>=4.14.1 29 | urllib3==2.5.0 30 | websockets==15.0.0 31 | mcp>=1.14.0; python_version > '3.9' 32 | sentencepiece>=0.2.0 33 | protobuf 34 | -------------------------------------------------------------------------------- /google/genai/tests/public_samples/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Public Samples and Tests for the Google GenAI SDK.""" 18 | -------------------------------------------------------------------------------- /google/genai/tests/local_tokenizer/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's local_tokenizer module.""" 18 | -------------------------------------------------------------------------------- /google/genai/tests/file_search_stores/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK's file search stores module.""" 18 | -------------------------------------------------------------------------------- /google/genai/_interactions/_version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from ..version import __version__ as __version__ 17 | 18 | __title__ = "google.genai._interactions" 19 | -------------------------------------------------------------------------------- /google/genai/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for the Google GenAI SDK.""" 18 | 19 | 20 | import pytest 21 | pytest.register_assert_rewrite('genai.replay_api_client') -------------------------------------------------------------------------------- /google/genai/tests/afc/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """AFC helper function unit tests. 18 | 19 | For AFC end to end test, please write test cases in 20 | test_generate_content_tools.py module 21 | """ 22 | -------------------------------------------------------------------------------- /google/genai/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Google Gen AI SDK""" 17 | 18 | from . import interactions 19 | from . import types 20 | from . import version 21 | from .client import Client 22 | 23 | 24 | __version__ = version.__version__ 25 | 26 | __all__ = ['Client'] 27 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/thinking_level.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing_extensions import Literal, TypeAlias 19 | 20 | __all__ = ["ThinkingLevel"] 21 | 22 | ThinkingLevel: TypeAlias = Literal["low", "high"] 23 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/tool_choice_type.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing_extensions import Literal, TypeAlias 19 | 20 | __all__ = ["ToolChoiceType"] 21 | 22 | ToolChoiceType: TypeAlias = Literal["auto", "any", "none", "validated"] 23 | -------------------------------------------------------------------------------- /.github/workflows/import.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Import Test 3 | 4 | on: 5 | push: 6 | branches: [ main ] 7 | pull_request: 8 | branches: [ main ] 9 | 10 | jobs: 11 | test-import: 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] 17 | 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v4 21 | 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v5 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | pip install setuptools wheel 31 | pip install pytest 32 | pip install . 33 | 34 | - name: Run import test 35 | run: | 36 | pytest google/genai/tests/imports/test_no_optional_imports.py -------------------------------------------------------------------------------- /google/genai/_interactions/_utils/_streams.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from typing import Any 17 | from typing_extensions import Iterator, AsyncIterator 18 | 19 | 20 | def consume_sync_iterator(iterator: Iterator[Any]) -> None: 21 | for _ in iterator: 22 | ... 23 | 24 | 25 | async def consume_async_iterator(iterator: AsyncIterator[Any]) -> None: 26 | async for _ in iterator: 27 | ... 28 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/image_mime_type.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Union 19 | from typing_extensions import Literal, TypeAlias 20 | 21 | __all__ = ["ImageMimeType"] 22 | 23 | ImageMimeType: TypeAlias = Union[Literal["image/png", "image/jpeg", "image/webp", "image/heic", "image/heif"], str] 24 | -------------------------------------------------------------------------------- /google/genai/_api_module.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Utilities for the API Modules of the Google Gen AI SDK.""" 17 | 18 | from typing import Optional 19 | from . import _api_client 20 | 21 | 22 | class BaseModule: 23 | 24 | def __init__(self, api_client_: _api_client.BaseApiClient): 25 | self._api_client = api_client_ 26 | 27 | @property 28 | def vertexai(self) -> Optional[bool]: 29 | return self._api_client.vertexai 30 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/audio_mime_type.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Union 19 | from typing_extensions import Literal, TypeAlias 20 | 21 | __all__ = ["AudioMimeType"] 22 | 23 | AudioMimeType: TypeAlias = Union[ 24 | Literal["audio/wav", "audio/mp3", "audio/aiff", "audio/aac", "audio/ogg", "audio/flac"], str 25 | ] 26 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/tool_choice.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Union 19 | from typing_extensions import TypeAlias 20 | 21 | from .tool_choice_type import ToolChoiceType 22 | from .tool_choice_config import ToolChoiceConfig 23 | 24 | __all__ = ["ToolChoice"] 25 | 26 | ToolChoice: TypeAlias = Union[ToolChoiceType, ToolChoiceConfig] 27 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/image_mime_type_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, TypeAlias 22 | 23 | __all__ = ["ImageMimeTypeParam"] 24 | 25 | ImageMimeTypeParam: TypeAlias = Union[Literal["image/png", "image/jpeg", "image/webp", "image/heic", "image/heif"], str] 26 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/tool_choice_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | 20 | from .._models import BaseModel 21 | from .allowed_tools import AllowedTools 22 | 23 | __all__ = ["ToolChoiceConfig"] 24 | 25 | 26 | class ToolChoiceConfig(BaseModel): 27 | allowed_tools: Optional[AllowedTools] = None 28 | """The configuration for allowed tools.""" 29 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/audio_mime_type_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, TypeAlias 22 | 23 | __all__ = ["AudioMimeTypeParam"] 24 | 25 | AudioMimeTypeParam: TypeAlias = Union[ 26 | Literal["audio/wav", "audio/mp3", "audio/aiff", "audio/aac", "audio/ogg", "audio/flac"], str 27 | ] 28 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_call_arguments.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | 20 | from .._models import BaseModel 21 | 22 | __all__ = ["URLContextCallArguments"] 23 | 24 | 25 | class URLContextCallArguments(BaseModel): 26 | """The arguments to pass to the URL context.""" 27 | 28 | urls: Optional[List[str]] = None 29 | """The URLs to fetch.""" 30 | -------------------------------------------------------------------------------- /.github/workflows/mypy.yml: -------------------------------------------------------------------------------- 1 | # This workflow runs mypy for static type checking. 2 | # See https://mypy.readthedocs.io/en/stable/index.html for more information. 3 | # 4 | # You can adjust the behavior by modifying this file. 5 | name: Run mypy 6 | 7 | on: 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | jobs: 13 | mypy: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] 18 | 19 | steps: 20 | - name: Checkout code 21 | uses: actions/checkout@v4 22 | 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v5 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | 28 | - name: Install dependencies 29 | run: | 30 | python -m pip install --upgrade pip 31 | pip install mypy 32 | sudo apt-get update && sudo apt-get install -y libjpeg-dev zlib1g-dev 33 | pip install -r requirements.txt 34 | 35 | - name: Run mypy ${{ matrix.python-version }} 36 | run: mypy google/genai/ -------------------------------------------------------------------------------- /google/genai/_interactions/types/tool_choice_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import TypeAlias 22 | 23 | from .tool_choice_type import ToolChoiceType 24 | from .tool_choice_config_param import ToolChoiceConfigParam 25 | 26 | __all__ = ["ToolChoiceParam"] 27 | 28 | ToolChoiceParam: TypeAlias = Union[ToolChoiceType, ToolChoiceConfigParam] 29 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/tool_choice_config_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | from .allowed_tools_param import AllowedToolsParam 23 | 24 | __all__ = ["ToolChoiceConfigParam"] 25 | 26 | 27 | class ToolChoiceConfigParam(TypedDict, total=False): 28 | allowed_tools: AllowedToolsParam 29 | """The configuration for allowed tools.""" 30 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_call_arguments.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | 20 | from .._models import BaseModel 21 | 22 | __all__ = ["GoogleSearchCallArguments"] 23 | 24 | 25 | class GoogleSearchCallArguments(BaseModel): 26 | """The arguments to pass to Google Search.""" 27 | 28 | queries: Optional[List[str]] = None 29 | """Web search queries for the following-up web search.""" 30 | -------------------------------------------------------------------------------- /google/genai/tests/caches/constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Constants for caches tests.""" 18 | 19 | CACHED_CONTENT_NAME_MLDEV = 'cachedContents/o239k1gxzz0juy9wqstndhncr85krehehf551hqh' 20 | CACHED_CONTENT_NAME_VERTEX = 'cachedContents/2164089915711684608' 21 | 22 | VERTEX_HTTP_OPTIONS = { 23 | 'api_version': 'v1beta1', 24 | 'base_url': 'https://us-central1-aiplatform.googleapis.com/', 25 | } 26 | MLDEV_HTTP_OPTIONS = { 27 | 'api_version': 'v1beta', 28 | 'base_url': 'https://generativelanguage.googleapis.com/', 29 | } -------------------------------------------------------------------------------- /google/genai/tests/imports/test_no_optional_imports.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import os 17 | import pytest 18 | 19 | IS_NOT_GITHUB_ACTIONS = os.getenv('GITHUB_ACTIONS') != 'true' 20 | 21 | 22 | @pytest.mark.skipif(IS_NOT_GITHUB_ACTIONS, 23 | reason='This test is only run on GitHub Actions.') 24 | def test_library_can_be_imported_without_optional_dependencies(): 25 | """Tests that the library can be imported without optional dependencies. 26 | """ 27 | from google import genai 28 | from google.genai import types 29 | -------------------------------------------------------------------------------- /google/genai/_base_transformers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Base transformers for Google GenAI SDK.""" 17 | import base64 18 | 19 | # Some fields don't accept url safe base64 encoding. 20 | # We shouldn't use this transformer if the backend adhere to Cloud Type 21 | # format https://cloud.google.com/docs/discovery/type-format. 22 | # TODO(b/389133914,b/390320301): Remove the hack after backend fix the issue. 23 | def t_bytes(data: bytes) -> str: 24 | if not isinstance(data, bytes): 25 | return data 26 | return base64.b64encode(data).decode('ascii') 27 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_call_arguments_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | from .._types import SequenceNotStr 23 | 24 | __all__ = ["URLContextCallArgumentsParam"] 25 | 26 | 27 | class URLContextCallArgumentsParam(TypedDict, total=False): 28 | """The arguments to pass to the URL context.""" 29 | 30 | urls: SequenceNotStr[str] 31 | """The URLs to fetch.""" 32 | -------------------------------------------------------------------------------- /google/genai/_interactions/_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | import httpx 19 | 20 | RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response" 21 | OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to" 22 | 23 | # default timeout is 1 minute 24 | DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0) 25 | DEFAULT_MAX_RETRIES = 2 26 | DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20) 27 | 28 | INITIAL_RETRY_DELAY = 0.5 29 | MAX_RETRY_DELAY = 8.0 30 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_result_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, TypedDict 21 | 22 | __all__ = ["URLContextResultParam"] 23 | 24 | 25 | class URLContextResultParam(TypedDict, total=False): 26 | """The result of the URL context.""" 27 | 28 | status: Literal["success", "error", "paywall", "unsafe"] 29 | """The status of the URL retrieval.""" 30 | 31 | url: str 32 | """The URL that was fetched.""" 33 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/allowed_tools.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | 20 | from .._models import BaseModel 21 | from .tool_choice_type import ToolChoiceType 22 | 23 | __all__ = ["AllowedTools"] 24 | 25 | 26 | class AllowedTools(BaseModel): 27 | """The configuration for allowed tools.""" 28 | 29 | mode: Optional[ToolChoiceType] = None 30 | """The mode of the tool choice.""" 31 | 32 | tools: Optional[List[str]] = None 33 | """The names of the allowed tools.""" 34 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_call_arguments_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | from .._types import SequenceNotStr 23 | 24 | __all__ = ["GoogleSearchCallArgumentsParam"] 25 | 26 | 27 | class GoogleSearchCallArgumentsParam(TypedDict, total=False): 28 | """The arguments to pass to Google Search.""" 29 | 30 | queries: SequenceNotStr[str] 31 | """Web search queries for the following-up web search.""" 32 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/video_mime_type.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Union 19 | from typing_extensions import Literal, TypeAlias 20 | 21 | __all__ = ["VideoMimeType"] 22 | 23 | VideoMimeType: TypeAlias = Union[ 24 | Literal[ 25 | "video/mp4", 26 | "video/mpeg", 27 | "video/mov", 28 | "video/avi", 29 | "video/x-flv", 30 | "video/mpg", 31 | "video/webm", 32 | "video/wmv", 33 | "video/3gpp", 34 | ], 35 | str, 36 | ] 37 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_list.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for models.list.""" 18 | 19 | 20 | from .... import types 21 | from ... import pytest_helper 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_list', 26 | parameters=types._ListModelsParameters( 27 | config=types.ListModelsConfig(page_size=1) 28 | ), 29 | ), 30 | ] 31 | 32 | pytestmark = pytest_helper.setup( 33 | file=__file__, 34 | globals_for_file=globals(), 35 | test_method='models.list', 36 | test_table=test_table, 37 | ) 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/code_execution_call_arguments_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, TypedDict 21 | 22 | __all__ = ["CodeExecutionCallArgumentsParam"] 23 | 24 | 25 | class CodeExecutionCallArgumentsParam(TypedDict, total=False): 26 | """The arguments to pass to the code execution.""" 27 | 28 | code: str 29 | """The code to be executed.""" 30 | 31 | language: Literal["python"] 32 | """Programming language of the `code`.""" 33 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/content_stop.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["ContentStop"] 24 | 25 | 26 | class ContentStop(BaseModel): 27 | event_id: Optional[str] = None 28 | """ 29 | The event_id token to be used to resume the interaction stream, from 30 | this event. 31 | """ 32 | 33 | event_type: Optional[Literal["content.stop"]] = None 34 | 35 | index: Optional[int] = None 36 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_result.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["URLContextResult"] 24 | 25 | 26 | class URLContextResult(BaseModel): 27 | """The result of the URL context.""" 28 | 29 | status: Optional[Literal["success", "error", "paywall", "unsafe"]] = None 30 | """The status of the URL retrieval.""" 31 | 32 | url: Optional[str] = None 33 | """The URL that was fetched.""" 34 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/code_execution_call_arguments.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["CodeExecutionCallArguments"] 24 | 25 | 26 | class CodeExecutionCallArguments(BaseModel): 27 | """The arguments to pass to the code execution.""" 28 | 29 | code: Optional[str] = None 30 | """The code to be executed.""" 31 | 32 | language: Optional[Literal["python"]] = None 33 | """Programming language of the `code`.""" 34 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/document_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["DocumentContent"] 24 | 25 | 26 | class DocumentContent(BaseModel): 27 | """A document content block.""" 28 | 29 | type: Literal["document"] 30 | """Used as the OpenAPI type discriminator for the content oneof.""" 31 | 32 | data: Optional[str] = None 33 | 34 | mime_type: Optional[str] = None 35 | 36 | uri: Optional[str] = None 37 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/speech_config_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | __all__ = ["SpeechConfigParam"] 23 | 24 | 25 | class SpeechConfigParam(TypedDict, total=False): 26 | """The configuration for speech interaction.""" 27 | 28 | language: str 29 | """The language of the speech.""" 30 | 31 | speaker: str 32 | """The speaker's name, it should match the speaker name given in the prompt.""" 33 | 34 | voice: str 35 | """The voice of the speaker.""" 36 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/allowed_tools_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | from .._types import SequenceNotStr 23 | from .tool_choice_type import ToolChoiceType 24 | 25 | __all__ = ["AllowedToolsParam"] 26 | 27 | 28 | class AllowedToolsParam(TypedDict, total=False): 29 | """The configuration for allowed tools.""" 30 | 31 | mode: ToolChoiceType 32 | """The mode of the tool choice.""" 33 | 34 | tools: SequenceNotStr[str] 35 | """The names of the allowed tools.""" 36 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/video_mime_type_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, TypeAlias 22 | 23 | __all__ = ["VideoMimeTypeParam"] 24 | 25 | VideoMimeTypeParam: TypeAlias = Union[ 26 | Literal[ 27 | "video/mp4", 28 | "video/mpeg", 29 | "video/mov", 30 | "video/avi", 31 | "video/x-flv", 32 | "video/mpg", 33 | "video/webm", 34 | "video/wmv", 35 | "video/3gpp", 36 | ], 37 | str, 38 | ] 39 | -------------------------------------------------------------------------------- /google/genai/tests/public_samples/test_gemini_text_only.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Test for the code sample for Gemini text-only request.""" 18 | 19 | from .. import pytest_helper 20 | 21 | pytestmark = pytest_helper.setup(file=__file__) 22 | 23 | 24 | def test_sample(client): 25 | # [START generativeaionvertexai_gemini_text_only] 26 | response = client.models.generate_content( 27 | model="gemini-2.5-flash", 28 | contents=( 29 | "What's a good name for a flower shop that specializes in selling" 30 | " bouquets of dried flowers?" 31 | ), 32 | ) 33 | print(response.text) 34 | # [END generativeaionvertexai_gemini_text_only] 35 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/speech_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | 20 | from .._models import BaseModel 21 | 22 | __all__ = ["SpeechConfig"] 23 | 24 | 25 | class SpeechConfig(BaseModel): 26 | """The configuration for speech interaction.""" 27 | 28 | language: Optional[str] = None 29 | """The language of the speech.""" 30 | 31 | speaker: Optional[str] = None 32 | """The speaker's name, it should match the speaker name given in the prompt.""" 33 | 34 | voice: Optional[str] = None 35 | """The voice of the speaker.""" 36 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_result_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | __all__ = ["GoogleSearchResultParam"] 23 | 24 | 25 | class GoogleSearchResultParam(TypedDict, total=False): 26 | """The result of the Google Search.""" 27 | 28 | rendered_content: str 29 | """Web content snippet that can be embedded in a web page or an app webview.""" 30 | 31 | title: str 32 | """Title of the search result.""" 33 | 34 | url: str 35 | """URI reference of the search result.""" 36 | -------------------------------------------------------------------------------- /google/genai/tests/data/story.txt: -------------------------------------------------------------------------------- 1 | The old lighthouse keeper, Silas, squinted at the churning sea. A storm, the likes of which he hadn't seen in fifty years, was brewing. Waves, the size of houses, were crashing against the jagged rocks below. The wind howled like a banshee, and the rain stung his face like a thousand tiny needles. 2 | 3 | He checked the lamp, its beam a comforting, steady light against the growing darkness. It was his duty, his oath, to keep that light burning, no matter what. He'd seen too many ships lost to the treacherous coast. 4 | 5 | Suddenly, a monstrous wave slammed into the lighthouse, shaking it to its foundations. The lamp flickered, and a cold dread washed over Silas. He scrambled to re-ignite the flame, his hands trembling. He had to, for the sake of the ships, and for the memory of all the sailors he had saved. He managed to get it back on just as the next huge wave hit. 6 | 7 | The storm raged for what felt like an eternity. When the first rays of dawn finally broke through the clouds, the sea had calmed, and a small ship, battered but intact, was sailing towards the harbor. Silas, exhausted but relieved, watched the ship safely reach the shore. He knew that his light had guided them through the sh**storm. He smiled, the light reflecting in his kind eyes, and went to make his morning coffee. -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_result.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | 20 | from .._models import BaseModel 21 | 22 | __all__ = ["GoogleSearchResult"] 23 | 24 | 25 | class GoogleSearchResult(BaseModel): 26 | """The result of the Google Search.""" 27 | 28 | rendered_content: Optional[str] = None 29 | """Web content snippet that can be embedded in a web page or an app webview.""" 30 | 31 | title: Optional[str] = None 32 | """Title of the search result.""" 33 | 34 | url: Optional[str] = None 35 | """URI reference of the search result.""" 36 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/deep_research_agent_config_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, TypedDict 21 | 22 | __all__ = ["DeepResearchAgentConfigParam"] 23 | 24 | 25 | class DeepResearchAgentConfigParam(TypedDict, total=False): 26 | """Configuration for the Deep Research agent.""" 27 | 28 | thinking_summaries: Literal["auto", "none"] 29 | """Whether to include thought summaries in the response.""" 30 | 31 | type: Literal["deep-research"] 32 | """Used as the OpenAPI type discriminator for the content oneof.""" 33 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/function_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, Required, TypedDict 21 | 22 | __all__ = ["FunctionParam"] 23 | 24 | 25 | class FunctionParam(TypedDict, total=False): 26 | """A tool that can be used by the model.""" 27 | 28 | type: Required[Literal["function"]] 29 | 30 | description: str 31 | """A description of the function.""" 32 | 33 | name: str 34 | """The name of the function.""" 35 | 36 | parameters: object 37 | """The JSON Schema for the function's parameters.""" 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/dynamic_agent_config_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Dict, Union 21 | from typing_extensions import Literal, TypeAlias, TypedDict 22 | 23 | __all__ = ["DynamicAgentConfigParam"] 24 | 25 | 26 | class DynamicAgentConfigParamTyped(TypedDict, total=False): 27 | """Configuration for dynamic agents.""" 28 | 29 | type: Literal["dynamic"] 30 | """Used as the OpenAPI type discriminator for the content oneof.""" 31 | 32 | 33 | DynamicAgentConfigParam: TypeAlias = Union[DynamicAgentConfigParamTyped, Dict[str, object]] 34 | -------------------------------------------------------------------------------- /google/genai/tests/operations/test_get.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for operations._get.""" 18 | 19 | from .. import pytest_helper 20 | from ... import types 21 | 22 | 23 | def test_project_operation_get(client): 24 | test_operation_id = '3787416390563004416' 25 | if client._api_client.vertexai: 26 | operation = client.operations._get( 27 | operation_id=test_operation_id 28 | ) 29 | assert operation.name.endswith(test_operation_id) 30 | assert operation.done 31 | assert isinstance(operation, types.ProjectOperation) 32 | 33 | 34 | pytestmark = pytest_helper.setup( 35 | file=__file__, 36 | globals_for_file=globals(), 37 | test_method='operations._get', 38 | ) 39 | -------------------------------------------------------------------------------- /google/genai/tests/shared/tunings/test_list.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for tunings.list().""" 18 | 19 | from .... import types as genai_types 20 | from ... import pytest_helper 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_default', 26 | parameters=genai_types._ListTuningJobsParameters( 27 | config=genai_types.ListTuningJobsConfig(page_size=1) 28 | ), 29 | ), 30 | ] 31 | 32 | pytestmark = pytest_helper.setup( 33 | file=__file__, 34 | globals_for_file=globals(), 35 | test_method='tunings.list', 36 | test_table=test_table, 37 | ) 38 | 39 | pytest_plugins = ('pytest_asyncio',) 40 | -------------------------------------------------------------------------------- /google/genai/tests/types/test_optional_types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | from unittest.mock import patch 18 | 19 | 20 | @patch.dict('sys.modules', {'PIL': None, 'PIL.Image': None}) 21 | def test_without_pil_installed_mocked(): 22 | from ... import types 23 | 24 | type_names_in_union = [ 25 | arg.__name__ if hasattr(arg, '__name__') else str(arg) 26 | for arg in types.PartUnion.__args__] 27 | assert 'Image' not in type_names_in_union 28 | 29 | def test_without_pil_installed_mocked(): 30 | from ... import types 31 | 32 | type_names_in_union = [ 33 | arg.__name__ if hasattr(arg, '__name__') else str(arg) 34 | for arg in types.PartUnion.__args__] 35 | 36 | assert 'Image' in type_names_in_union -------------------------------------------------------------------------------- /google/genai/_interactions/types/function.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["Function"] 24 | 25 | 26 | class Function(BaseModel): 27 | """A tool that can be used by the model.""" 28 | 29 | type: Literal["function"] 30 | 31 | description: Optional[str] = None 32 | """A description of the function.""" 33 | 34 | name: Optional[str] = None 35 | """The name of the function.""" 36 | 37 | parameters: Optional[object] = None 38 | """The JSON Schema for the function's parameters.""" 39 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_generate_videos.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | """Tests for generate_videos.""" 16 | 17 | import os 18 | from .... import types 19 | from ... import pytest_helper 20 | 21 | VEO_MODEL_LATEST = "veo-2.0-generate-001" 22 | 23 | 24 | test_table: list[pytest_helper.TestTableItem] = [ 25 | pytest_helper.TestTableItem( 26 | name="test_simple_prompt", 27 | parameters=types._GenerateVideosParameters( 28 | model=VEO_MODEL_LATEST, 29 | prompt="Man with a dog", 30 | ), 31 | ), 32 | ] 33 | pytestmark = pytest_helper.setup( 34 | file=__file__, 35 | globals_for_file=globals(), 36 | test_method="models.generate_videos", 37 | test_table=test_table, 38 | ) -------------------------------------------------------------------------------- /google/genai/_interactions/types/deep_research_agent_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["DeepResearchAgentConfig"] 24 | 25 | 26 | class DeepResearchAgentConfig(BaseModel): 27 | """Configuration for the Deep Research agent.""" 28 | 29 | thinking_summaries: Optional[Literal["auto", "none"]] = None 30 | """Whether to include thought summaries in the response.""" 31 | 32 | type: Optional[Literal["deep-research"]] = None 33 | """Used as the OpenAPI type discriminator for the content oneof.""" 34 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/model.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Union 19 | from typing_extensions import Literal, TypeAlias 20 | 21 | __all__ = ["Model"] 22 | 23 | Model: TypeAlias = Union[ 24 | Literal[ 25 | "gemini-2.5-pro", 26 | "gemini-2.5-flash", 27 | "gemini-2.5-flash-preview-09-2025", 28 | "gemini-2.5-flash-lite", 29 | "gemini-2.5-flash-lite-preview-09-2025", 30 | "gemini-2.5-flash-preview-native-audio-dialog", 31 | "gemini-2.5-flash-image-preview", 32 | "gemini-2.5-pro-preview-tts", 33 | "gemini-3-pro-preview", 34 | ], 35 | str, 36 | ] 37 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_embed.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for models.embed().""" 18 | 19 | from .... import types as genai_types 20 | from ... import pytest_helper 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_embed', 26 | parameters=genai_types._EmbedContentParameters( 27 | model='text-embedding-004', 28 | contents='Hello world!', 29 | ), 30 | ), 31 | ] 32 | 33 | pytestmark = pytest_helper.setup( 34 | file=__file__, 35 | globals_for_file=globals(), 36 | test_method='models.embed_content', 37 | test_table=test_table, 38 | ) 39 | 40 | pytest_plugins = ('pytest_asyncio',) 41 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/audio_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .audio_mime_type import AudioMimeType 23 | 24 | __all__ = ["AudioContent"] 25 | 26 | 27 | class AudioContent(BaseModel): 28 | """An audio content block.""" 29 | 30 | type: Literal["audio"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | data: Optional[str] = None 34 | 35 | mime_type: Optional[AudioMimeType] = None 36 | """The mime type of the audio.""" 37 | 38 | uri: Optional[str] = None 39 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/interaction_sse_event.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Union 19 | from typing_extensions import TypeAlias 20 | 21 | from .error_event import ErrorEvent 22 | from .content_stop import ContentStop 23 | from .content_delta import ContentDelta 24 | from .content_start import ContentStart 25 | from .interaction_event import InteractionEvent 26 | from .interaction_status_update import InteractionStatusUpdate 27 | 28 | __all__ = ["InteractionSSEEvent"] 29 | 30 | InteractionSSEEvent: TypeAlias = Union[ 31 | InteractionEvent, InteractionStatusUpdate, ContentStart, ContentDelta, ContentStop, ErrorEvent 32 | ] 33 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/text_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .annotation import Annotation 23 | 24 | __all__ = ["TextContent"] 25 | 26 | 27 | class TextContent(BaseModel): 28 | """A text content block.""" 29 | 30 | type: Literal["text"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | annotations: Optional[List[Annotation]] = None 34 | """Citation information for model-generated content.""" 35 | 36 | text: Optional[str] = None 37 | """The text content.""" 38 | -------------------------------------------------------------------------------- /google/genai/tests/shared/batches/test_list.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for batches.list().""" 17 | 18 | from .... import types as genai_types 19 | from ... import pytest_helper 20 | 21 | 22 | test_table: list[pytest_helper.TestTableItem] = [ 23 | pytest_helper.TestTableItem( 24 | name='test_list_batch_jobs', 25 | parameters=genai_types._ListBatchJobsParameters( 26 | config=genai_types.ListBatchJobsConfig( 27 | page_size=2, 28 | ), 29 | ), 30 | ), 31 | ] 32 | 33 | pytestmark = pytest_helper.setup( 34 | file=__file__, 35 | globals_for_file=globals(), 36 | test_method='batches.list', 37 | test_table=test_table, 38 | ) 39 | 40 | pytest_plugins = ('pytest_asyncio',) 41 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/interaction_event.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .interaction import Interaction 23 | 24 | __all__ = ["InteractionEvent"] 25 | 26 | 27 | class InteractionEvent(BaseModel): 28 | event_id: Optional[str] = None 29 | """ 30 | The event_id token to be used to resume the interaction stream, from 31 | this event. 32 | """ 33 | 34 | event_type: Optional[Literal["interaction.start", "interaction.complete"]] = None 35 | 36 | interaction: Optional[Interaction] = None 37 | """The Interaction resource.""" 38 | -------------------------------------------------------------------------------- /google/genai/tests/shared/caches/test_list.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for caches.list().""" 17 | 18 | from .... import types as genai_types 19 | from ... import pytest_helper 20 | 21 | 22 | test_table: list[pytest_helper.TestTableItem] = [ 23 | pytest_helper.TestTableItem( 24 | name='test_list_cached_contents', 25 | parameters=genai_types._ListCachedContentsParameters( 26 | config=genai_types.ListCachedContentsConfig( 27 | page_size=2, 28 | ), 29 | ), 30 | ), 31 | ] 32 | 33 | pytestmark = pytest_helper.setup( 34 | file=__file__, 35 | globals_for_file=globals(), 36 | test_method='caches.list', 37 | test_table=test_table, 38 | ) 39 | 40 | pytest_plugins = ('pytest_asyncio',) 41 | -------------------------------------------------------------------------------- /google/genai/_interactions/resources/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from .interactions import ( 19 | InteractionsResource, 20 | AsyncInteractionsResource, 21 | InteractionsResourceWithRawResponse, 22 | AsyncInteractionsResourceWithRawResponse, 23 | InteractionsResourceWithStreamingResponse, 24 | AsyncInteractionsResourceWithStreamingResponse, 25 | ) 26 | 27 | __all__ = [ 28 | "InteractionsResource", 29 | "AsyncInteractionsResource", 30 | "InteractionsResourceWithRawResponse", 31 | "AsyncInteractionsResourceWithRawResponse", 32 | "InteractionsResourceWithStreamingResponse", 33 | "AsyncInteractionsResourceWithStreamingResponse", 34 | ] 35 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues that have had no activity for a specified amount of time. 2 | name: Mark and close stale issues 3 | 4 | on: 5 | schedule: 6 | # Scheduled to run at 1:30 UTC everyday 7 | - cron: '30 1 * * *' 8 | 9 | jobs: 10 | stale: 11 | 12 | runs-on: ubuntu-latest 13 | permissions: 14 | issues: write 15 | 16 | steps: 17 | - uses: actions/stale@v5 18 | with: 19 | repo-token: ${{ secrets.GITHUB_TOKEN }} 20 | days-before-issue-stale: 7 21 | days-before-issue-close: 2 22 | stale-issue-label: "status:stale" 23 | close-issue-reason: not_planned 24 | any-of-labels: "status:awaiting user response" 25 | remove-stale-when-updated: true 26 | labels-to-remove-when-unstale: 'status:awaiting user response,status:stale' 27 | stale-issue-message: > 28 | This issue has been marked as stale because it has been open for 7 days with no activity. It will be closed in 2 days if no further activity occurs. 29 | close-issue-message: > 30 | This issue was closed because it has been inactive for 9 days. 31 | Please post a new issue if you need further assistance. Thanks! 32 | # Label that can be assigned to issues to exclude them from being marked as stale 33 | exempt-issue-labels: 'override-stale' 34 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_count_tokens.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for models.count_tokens().""" 18 | 19 | from .... import types as genai_types 20 | from ... import pytest_helper 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_count_tokens', 26 | parameters=genai_types._CountTokensParameters( 27 | model='gemini-2.5-flash', 28 | contents='The quick brown fox jumps over the lazy dog.', 29 | ), 30 | ), 31 | ] 32 | 33 | pytestmark = pytest_helper.setup( 34 | file=__file__, 35 | globals_for_file=globals(), 36 | test_method='models.count_tokens', 37 | test_table=test_table, 38 | ) 39 | 40 | pytest_plugins = ('pytest_asyncio',) 41 | -------------------------------------------------------------------------------- /google/genai/tests/tunings/test_cancel.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for tunings.cancel().""" 18 | 19 | from ... import types as genai_types 20 | from .. import pytest_helper 21 | 22 | test_table: list[pytest_helper.TestTableItem] = [ 23 | pytest_helper.TestTableItem( 24 | name="test_cancel_vertex", 25 | parameters=genai_types._CancelTuningJobParameters( 26 | name="projects/801452371447/locations/us-central1/tuningJobs/2470687341547618304" 27 | ), 28 | exception_if_mldev="Not Found", 29 | ), 30 | ] 31 | 32 | pytestmark = pytest_helper.setup( 33 | file=__file__, 34 | globals_for_file=globals(), 35 | test_method="tunings.cancel", 36 | test_table=test_table, 37 | ) 38 | 39 | pytest_plugins = ("pytest_asyncio",) 40 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/function_call_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Dict 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["FunctionCallContent"] 24 | 25 | 26 | class FunctionCallContent(BaseModel): 27 | """A function tool call content block.""" 28 | 29 | id: str 30 | """A unique ID for this specific tool call.""" 31 | 32 | arguments: Dict[str, object] 33 | """The arguments to pass to the function.""" 34 | 35 | name: str 36 | """The name of the tool to call.""" 37 | 38 | type: Literal["function_call"] 39 | """Used as the OpenAPI type discriminator for the content oneof.""" 40 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_generate_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for models.generate_content().""" 17 | 18 | from .... import types as genai_types 19 | from ... import pytest_helper 20 | 21 | 22 | test_table: list[pytest_helper.TestTableItem] = [ 23 | pytest_helper.TestTableItem( 24 | name='test_generate_content', 25 | parameters=genai_types._GenerateContentParameters( 26 | model='gemini-2.5-flash', 27 | contents='The quick brown fox jumps over the lazy dog.', 28 | ), 29 | ), 30 | ] 31 | 32 | pytestmark = pytest_helper.setup( 33 | file=__file__, 34 | globals_for_file=globals(), 35 | test_method='models.generate_content', 36 | test_table=test_table, 37 | ) 38 | 39 | pytest_plugins = ('pytest_asyncio',) 40 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/model_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, TypeAlias 22 | 23 | __all__ = ["ModelParam"] 24 | 25 | ModelParam: TypeAlias = Union[ 26 | Literal[ 27 | "gemini-2.5-pro", 28 | "gemini-2.5-flash", 29 | "gemini-2.5-flash-preview-09-2025", 30 | "gemini-2.5-flash-lite", 31 | "gemini-2.5-flash-lite-preview-09-2025", 32 | "gemini-2.5-flash-preview-native-audio-dialog", 33 | "gemini-2.5-flash-image-preview", 34 | "gemini-2.5-pro-preview-tts", 35 | "gemini-3-pro-preview", 36 | ], 37 | str, 38 | ] 39 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/text_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Iterable 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | from .annotation_param import AnnotationParam 24 | 25 | __all__ = ["TextContentParam"] 26 | 27 | 28 | class TextContentParam(TypedDict, total=False): 29 | """A text content block.""" 30 | 31 | type: Required[Literal["text"]] 32 | """Used as the OpenAPI type discriminator for the content oneof.""" 33 | 34 | annotations: Iterable[AnnotationParam] 35 | """Citation information for model-generated content.""" 36 | 37 | text: str 38 | """The text content.""" 39 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/interaction_status_update.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["InteractionStatusUpdate"] 24 | 25 | 26 | class InteractionStatusUpdate(BaseModel): 27 | event_id: Optional[str] = None 28 | """ 29 | The event_id token to be used to resume the interaction stream, from 30 | this event. 31 | """ 32 | 33 | event_type: Optional[Literal["interaction.status_update"]] = None 34 | 35 | interaction_id: Optional[str] = None 36 | 37 | status: Optional[Literal["in_progress", "requires_action", "completed", "failed", "cancelled"]] = None 38 | -------------------------------------------------------------------------------- /google/genai/tests/shared/files/test_list.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for files.list().""" 17 | 18 | from .... import types as genai_types 19 | from ... import pytest_helper 20 | 21 | 22 | test_table: list[pytest_helper.TestTableItem] = [ 23 | pytest_helper.TestTableItem( 24 | name='test_list_files', 25 | parameters=genai_types._ListFilesParameters( 26 | config=genai_types.ListFilesConfig( 27 | page_size=2, 28 | ), 29 | ), 30 | exception_if_vertex='only supported in the Gemini Developer client', 31 | ), 32 | ] 33 | 34 | pytestmark = pytest_helper.setup( 35 | file=__file__, 36 | globals_for_file=globals(), 37 | test_method='files.list', 38 | test_table=test_table, 39 | ) 40 | 41 | pytest_plugins = ('pytest_asyncio',) 42 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_call_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .url_context_call_arguments import URLContextCallArguments 23 | 24 | __all__ = ["URLContextCallContent"] 25 | 26 | 27 | class URLContextCallContent(BaseModel): 28 | """URL context content.""" 29 | 30 | type: Literal["url_context_call"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | id: Optional[str] = None 34 | """A unique ID for this specific tool call.""" 35 | 36 | arguments: Optional[URLContextCallArguments] = None 37 | """The arguments to pass to the URL context.""" 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_call_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .google_search_call_arguments import GoogleSearchCallArguments 23 | 24 | __all__ = ["GoogleSearchCallContent"] 25 | 26 | 27 | class GoogleSearchCallContent(BaseModel): 28 | """Google Search content.""" 29 | 30 | type: Literal["google_search_call"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | id: Optional[str] = None 34 | """A unique ID for this specific tool call.""" 35 | 36 | arguments: Optional[GoogleSearchCallArguments] = None 37 | """The arguments to pass to Google Search.""" 38 | -------------------------------------------------------------------------------- /google/genai/tests/models/test_generate_content_http_options.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | from ... import _transformers as t 18 | from ... import types 19 | from .. import pytest_helper 20 | 21 | test_table: list[pytest_helper.TestTableItem] = [ 22 | pytest_helper.TestTableItem( 23 | name='test_generate_content_with_http_options', 24 | parameters=types._GenerateContentParameters( 25 | model='models/gemini-2.5-flash', 26 | contents=t.t_contents('how are you doing?'), 27 | ), 28 | exception_if_vertex='404', 29 | ), 30 | ] 31 | 32 | pytestmark = pytest_helper.setup( 33 | file=__file__, 34 | globals_for_file=globals(), 35 | test_method='models.generate_content', 36 | test_table=test_table, 37 | http_options={ 38 | 'api_version': 'v1alpha', 39 | }, 40 | ) 41 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_call_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, Required, TypedDict 21 | 22 | from .url_context_call_arguments_param import URLContextCallArgumentsParam 23 | 24 | __all__ = ["URLContextCallContentParam"] 25 | 26 | 27 | class URLContextCallContentParam(TypedDict, total=False): 28 | """URL context content.""" 29 | 30 | type: Required[Literal["url_context_call"]] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | id: str 34 | """A unique ID for this specific tool call.""" 35 | 36 | arguments: URLContextCallArgumentsParam 37 | """The arguments to pass to the URL context.""" 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/code_execution_call_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .code_execution_call_arguments import CodeExecutionCallArguments 23 | 24 | __all__ = ["CodeExecutionCallContent"] 25 | 26 | 27 | class CodeExecutionCallContent(BaseModel): 28 | """Code execution content.""" 29 | 30 | type: Literal["code_execution_call"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | id: Optional[str] = None 34 | """A unique ID for this specific tool call.""" 35 | 36 | arguments: Optional[CodeExecutionCallArguments] = None 37 | """The arguments to pass to the code execution.""" 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/image_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .image_mime_type import ImageMimeType 23 | 24 | __all__ = ["ImageContent"] 25 | 26 | 27 | class ImageContent(BaseModel): 28 | """An image content block.""" 29 | 30 | type: Literal["image"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | data: Optional[str] = None 34 | 35 | mime_type: Optional[ImageMimeType] = None 36 | """The mime type of the image.""" 37 | 38 | resolution: Optional[Literal["low", "medium", "high"]] = None 39 | """The resolution of the media.""" 40 | 41 | uri: Optional[str] = None 42 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/video_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .video_mime_type import VideoMimeType 23 | 24 | __all__ = ["VideoContent"] 25 | 26 | 27 | class VideoContent(BaseModel): 28 | """A video content block.""" 29 | 30 | type: Literal["video"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | data: Optional[str] = None 34 | 35 | mime_type: Optional[VideoMimeType] = None 36 | """The mime type of the video.""" 37 | 38 | resolution: Optional[Literal["low", "medium", "high"]] = None 39 | """The resolution of the media.""" 40 | 41 | uri: Optional[str] = None 42 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_compute_tokens.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for models.compute_tokens().""" 18 | 19 | from .... import types as genai_types 20 | from ... import pytest_helper 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_compute_tokens', 26 | parameters=genai_types._ComputeTokensParameters( 27 | model='gemini-2.5-flash', 28 | contents='The quick brown fox jumps over the lazy dog.', 29 | ), 30 | exception_if_mldev='only supported in the Vertex AI', 31 | ), 32 | ] 33 | 34 | pytestmark = pytest_helper.setup( 35 | file=__file__, 36 | globals_for_file=globals(), 37 | test_method='models.compute_tokens', 38 | test_table=test_table, 39 | ) 40 | 41 | pytest_plugins = ('pytest_asyncio',) 42 | -------------------------------------------------------------------------------- /google/genai/_interactions/_utils/_resources_proxy.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | 18 | from typing import Any 19 | from typing_extensions import override 20 | 21 | from ._proxy import LazyProxy 22 | 23 | 24 | class ResourcesProxy(LazyProxy[Any]): 25 | """A proxy for the `google.genai._interactions.resources` module. 26 | 27 | This is used so that we can lazily import `google.genai._interactions.resources` only when 28 | needed *and* so that users can just import `google.genai._interactions` and reference `google.genai._interactions.resources` 29 | """ 30 | 31 | @override 32 | def __load__(self) -> Any: 33 | import importlib 34 | 35 | mod = importlib.import_module("google.genai._interactions.resources") 36 | return mod 37 | 38 | 39 | resources = ResourcesProxy().__as_proxied__() 40 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/annotation_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import TypedDict 21 | 22 | __all__ = ["AnnotationParam"] 23 | 24 | 25 | class AnnotationParam(TypedDict, total=False): 26 | """Citation information for model-generated content.""" 27 | 28 | end_index: int 29 | """End of the attributed segment, exclusive.""" 30 | 31 | source: str 32 | """Source attributed for a portion of the text. 33 | 34 | Could be a URL, title, or 35 | other identifier. 36 | """ 37 | 38 | start_index: int 39 | """Start of segment of the response that is attributed to this source. 40 | 41 | Index indicates the start of the segment, measured in bytes. 42 | """ 43 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_call_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, Required, TypedDict 21 | 22 | from .google_search_call_arguments_param import GoogleSearchCallArgumentsParam 23 | 24 | __all__ = ["GoogleSearchCallContentParam"] 25 | 26 | 27 | class GoogleSearchCallContentParam(TypedDict, total=False): 28 | """Google Search content.""" 29 | 30 | type: Required[Literal["google_search_call"]] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | id: str 34 | """A unique ID for this specific tool call.""" 35 | 36 | arguments: GoogleSearchCallArgumentsParam 37 | """The arguments to pass to Google Search.""" 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/annotation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | 20 | from .._models import BaseModel 21 | 22 | __all__ = ["Annotation"] 23 | 24 | 25 | class Annotation(BaseModel): 26 | """Citation information for model-generated content.""" 27 | 28 | end_index: Optional[int] = None 29 | """End of the attributed segment, exclusive.""" 30 | 31 | source: Optional[str] = None 32 | """Source attributed for a portion of the text. 33 | 34 | Could be a URL, title, or 35 | other identifier. 36 | """ 37 | 38 | start_index: Optional[int] = None 39 | """Start of segment of the response that is attributed to this source. 40 | 41 | Index indicates the start of the segment, measured in bytes. 42 | """ 43 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/code_execution_call_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, Required, TypedDict 21 | 22 | from .code_execution_call_arguments_param import CodeExecutionCallArgumentsParam 23 | 24 | __all__ = ["CodeExecutionCallContentParam"] 25 | 26 | 27 | class CodeExecutionCallContentParam(TypedDict, total=False): 28 | """Code execution content.""" 29 | 30 | type: Required[Literal["code_execution_call"]] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | id: str 34 | """A unique ID for this specific tool call.""" 35 | 36 | arguments: CodeExecutionCallArgumentsParam 37 | """The arguments to pass to the code execution.""" 38 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/function_call_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Dict 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | __all__ = ["FunctionCallContentParam"] 24 | 25 | 26 | class FunctionCallContentParam(TypedDict, total=False): 27 | """A function tool call content block.""" 28 | 29 | id: Required[str] 30 | """A unique ID for this specific tool call.""" 31 | 32 | arguments: Required[Dict[str, object]] 33 | """The arguments to pass to the function.""" 34 | 35 | name: Required[str] 36 | """The name of the tool to call.""" 37 | 38 | type: Required[Literal["function_call"]] 39 | """Used as the OpenAPI type discriminator for the content oneof.""" 40 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_generate_images.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | """Tests for generate_images.""" 16 | 17 | from .... import types 18 | from ... import pytest_helper 19 | 20 | IMAGEN_MODEL_LATEST = 'imagen-4.0-generate-001' 21 | 22 | test_table: list[pytest_helper.TestTableItem] = [ 23 | pytest_helper.TestTableItem( 24 | name='test_simple_prompt', 25 | parameters=types._GenerateImagesParameters( 26 | model=IMAGEN_MODEL_LATEST, 27 | prompt='Red skateboard', 28 | config=types.GenerateImagesConfig( 29 | number_of_images=1, 30 | output_mime_type='image/jpeg', 31 | ), 32 | ), 33 | ), 34 | ] 35 | pytestmark = pytest_helper.setup( 36 | file=__file__, 37 | globals_for_file=globals(), 38 | test_method='models.generate_images', 39 | test_table=test_table, 40 | ) 41 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/mcp_server_tool_call_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Dict 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["MCPServerToolCallContent"] 24 | 25 | 26 | class MCPServerToolCallContent(BaseModel): 27 | """MCPServer tool call content.""" 28 | 29 | id: str 30 | """A unique ID for this specific tool call.""" 31 | 32 | arguments: Dict[str, object] 33 | """The JSON object of arguments for the function.""" 34 | 35 | name: str 36 | """The name of the tool which was called.""" 37 | 38 | server_name: str 39 | """The name of the used MCP server.""" 40 | 41 | type: Literal["mcp_server_tool_call"] 42 | """Used as the OpenAPI type discriminator for the content oneof.""" 43 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/error_event.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["ErrorEvent", "Error"] 24 | 25 | 26 | class Error(BaseModel): 27 | """Error message from an interaction.""" 28 | 29 | code: Optional[str] = None 30 | """A URI that identifies the error type.""" 31 | 32 | message: Optional[str] = None 33 | """A human-readable error message.""" 34 | 35 | 36 | class ErrorEvent(BaseModel): 37 | error: Optional[Error] = None 38 | """Error message from an interaction.""" 39 | 40 | event_id: Optional[str] = None 41 | """ 42 | The event_id token to be used to resume the interaction stream, from 43 | this event. 44 | """ 45 | 46 | event_type: Optional[Literal["error"]] = None 47 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/code_execution_result_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing_extensions import Literal, Required, TypedDict 21 | 22 | __all__ = ["CodeExecutionResultContentParam"] 23 | 24 | 25 | class CodeExecutionResultContentParam(TypedDict, total=False): 26 | """Code execution result content.""" 27 | 28 | type: Required[Literal["code_execution_result"]] 29 | """Used as the OpenAPI type discriminator for the content oneof.""" 30 | 31 | call_id: str 32 | """ID to match the ID from the code execution call block.""" 33 | 34 | is_error: bool 35 | """Whether the code execution resulted in an error.""" 36 | 37 | result: str 38 | """The output of the code execution.""" 39 | 40 | signature: str 41 | """A signature hash for backend validation.""" 42 | -------------------------------------------------------------------------------- /google/genai/tests/shared/chats/test_send_message.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Table tests for chats.send_message().""" 17 | 18 | from ... import pytest_helper 19 | from pydantic import BaseModel 20 | 21 | 22 | class _SendMessageParameters(BaseModel): 23 | model: str 24 | message: str 25 | 26 | 27 | def send_message(client, parameters): 28 | chat = client.chats.create(model=parameters.model) 29 | chat.send_message(parameters.message) 30 | 31 | test_table: list[pytest_helper.TestTableItem] = [ 32 | pytest_helper.TestTableItem( 33 | name="test_send_message", 34 | parameters=_SendMessageParameters( 35 | model="gemini-2.5-flash", 36 | message="Hello", 37 | ), 38 | ), 39 | ] 40 | 41 | pytestmark = pytest_helper.setup( 42 | file=__file__, 43 | globals_for_file=globals(), 44 | test_method="send_message", 45 | test_table=test_table, 46 | ) 47 | 48 | pytest_plugins = ("pytest_asyncio",) 49 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/document_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, Required, Annotated, TypedDict 22 | 23 | from .._types import Base64FileInput 24 | from .._utils import PropertyInfo 25 | from .._models import set_pydantic_config 26 | 27 | __all__ = ["DocumentContentParam"] 28 | 29 | 30 | class DocumentContentParam(TypedDict, total=False): 31 | """A document content block.""" 32 | 33 | type: Required[Literal["document"]] 34 | """Used as the OpenAPI type discriminator for the content oneof.""" 35 | 36 | data: Annotated[Union[str, Base64FileInput], PropertyInfo(format="base64")] 37 | 38 | mime_type: str 39 | 40 | uri: str 41 | 42 | 43 | set_pydantic_config(DocumentContentParam, {"arbitrary_types_allowed": True}) 44 | -------------------------------------------------------------------------------- /docs/_static/debug.css: -------------------------------------------------------------------------------- 1 | /* 2 | This CSS file should be overridden by the theme authors. It's 3 | meant for debugging and developing the skeleton that this theme provides. 4 | */ 5 | body { 6 | font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, 7 | "Apple Color Emoji", "Segoe UI Emoji"; 8 | background: lavender; 9 | } 10 | .sb-announcement { 11 | background: rgb(131, 131, 131); 12 | } 13 | .sb-announcement__inner { 14 | background: black; 15 | color: white; 16 | } 17 | .sb-header { 18 | background: lightskyblue; 19 | } 20 | .sb-header__inner { 21 | background: royalblue; 22 | color: white; 23 | } 24 | .sb-header-secondary { 25 | background: lightcyan; 26 | } 27 | .sb-header-secondary__inner { 28 | background: cornflowerblue; 29 | color: white; 30 | } 31 | .sb-sidebar-primary { 32 | background: lightgreen; 33 | } 34 | .sb-main { 35 | background: blanchedalmond; 36 | } 37 | .sb-main__inner { 38 | background: antiquewhite; 39 | } 40 | .sb-header-article { 41 | background: lightsteelblue; 42 | } 43 | .sb-article-container { 44 | background: snow; 45 | } 46 | .sb-article-main { 47 | background: white; 48 | } 49 | .sb-footer-article { 50 | background: lightpink; 51 | } 52 | .sb-sidebar-secondary { 53 | background: lightgoldenrodyellow; 54 | } 55 | .sb-footer-content { 56 | background: plum; 57 | } 58 | .sb-footer-content__inner { 59 | background: palevioletred; 60 | } 61 | .sb-footer { 62 | background: pink; 63 | } 64 | .sb-footer__inner { 65 | background: salmon; 66 | } 67 | .sb-article { 68 | background: white; 69 | } 70 | -------------------------------------------------------------------------------- /google/genai/_interactions/_utils/_logs.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import os 17 | import logging 18 | 19 | logger: logging.Logger = logging.getLogger("google.genai._interactions") 20 | httpx_logger: logging.Logger = logging.getLogger("httpx") 21 | 22 | 23 | def _basic_config() -> None: 24 | # e.g. [2023-10-05 14:12:26 - google.genai._interactions._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK" 25 | logging.basicConfig( 26 | format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s", 27 | datefmt="%Y-%m-%d %H:%M:%S", 28 | ) 29 | 30 | 31 | def setup_logging() -> None: 32 | env = os.environ.get("GEMINI_NEXT_GEN_API_LOG") 33 | if env == "debug": 34 | _basic_config() 35 | logger.setLevel(logging.DEBUG) 36 | httpx_logger.setLevel(logging.DEBUG) 37 | elif env == "info": 38 | _basic_config() 39 | logger.setLevel(logging.INFO) 40 | httpx_logger.setLevel(logging.INFO) 41 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/code_execution_result_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["CodeExecutionResultContent"] 24 | 25 | 26 | class CodeExecutionResultContent(BaseModel): 27 | """Code execution result content.""" 28 | 29 | type: Literal["code_execution_result"] 30 | """Used as the OpenAPI type discriminator for the content oneof.""" 31 | 32 | call_id: Optional[str] = None 33 | """ID to match the ID from the code execution call block.""" 34 | 35 | is_error: Optional[bool] = None 36 | """Whether the code execution resulted in an error.""" 37 | 38 | result: Optional[str] = None 39 | """The output of the code execution.""" 40 | 41 | signature: Optional[str] = None 42 | """A signature hash for backend validation.""" 43 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/mcp_server_tool_call_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Dict 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | __all__ = ["MCPServerToolCallContentParam"] 24 | 25 | 26 | class MCPServerToolCallContentParam(TypedDict, total=False): 27 | """MCPServer tool call content.""" 28 | 29 | id: Required[str] 30 | """A unique ID for this specific tool call.""" 31 | 32 | arguments: Required[Dict[str, object]] 33 | """The JSON object of arguments for the function.""" 34 | 35 | name: Required[str] 36 | """The name of the tool which was called.""" 37 | 38 | server_name: Required[str] 39 | """The name of the used MCP server.""" 40 | 41 | type: Required[Literal["mcp_server_tool_call"]] 42 | """Used as the OpenAPI type discriminator for the content oneof.""" 43 | -------------------------------------------------------------------------------- /google/genai/tests/files/test_get.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Test files get method.""" 18 | 19 | import pytest 20 | from ... import types 21 | from .. import pytest_helper 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_get', 26 | parameters=types._GetFileParameters(name='files/vjvu9fwk2qj8'), 27 | exception_if_vertex='only supported in the Gemini Developer client', 28 | skip_in_api_mode=( 29 | 'The files have a TTL, they cannot be reliably retrieved for a long' 30 | ' time.' 31 | ), 32 | ), 33 | ] 34 | 35 | pytestmark = pytest_helper.setup( 36 | file=__file__, 37 | globals_for_file=globals(), 38 | test_method='files.get', 39 | test_table=test_table, 40 | ) 41 | 42 | 43 | @pytest.mark.asyncio 44 | async def test_async(client): 45 | with pytest_helper.exception_if_vertex(client, ValueError): 46 | file = await client.aio.files.get(name='files/vjvu9fwk2qj8') 47 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/thought_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Union, Optional 19 | from typing_extensions import Literal, Annotated, TypeAlias 20 | 21 | from .._utils import PropertyInfo 22 | from .._models import BaseModel 23 | from .text_content import TextContent 24 | from .image_content import ImageContent 25 | 26 | __all__ = ["ThoughtContent", "Summary"] 27 | 28 | Summary: TypeAlias = Annotated[Union[TextContent, ImageContent], PropertyInfo(discriminator="type")] 29 | 30 | 31 | class ThoughtContent(BaseModel): 32 | """A thought content block.""" 33 | 34 | type: Literal["thought"] 35 | """Used as the OpenAPI type discriminator for the content oneof.""" 36 | 37 | signature: Optional[str] = None 38 | """Signature to match the backend source to be part of the generation.""" 39 | 40 | summary: Optional[List[Summary]] = None 41 | """A summary of the thought.""" 42 | -------------------------------------------------------------------------------- /google/genai/tests/files/test_delete.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Test files delete method.""" 18 | 19 | import pytest 20 | from ... import types 21 | from .. import pytest_helper 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_delete', 26 | parameters=types._DeleteFileParameters(name='files/1g583ke2xdsn'), 27 | exception_if_vertex='only supported in the Gemini Developer client', 28 | skip_in_api_mode=( 29 | 'The files have a TTL, they cannot be reliably retrieved for a long' 30 | ' time.' 31 | ), 32 | ), 33 | ] 34 | 35 | pytestmark = pytest_helper.setup( 36 | file=__file__, 37 | globals_for_file=globals(), 38 | test_method='files.delete', 39 | test_table=test_table, 40 | ) 41 | 42 | 43 | @pytest.mark.asyncio 44 | async def test_async(client): 45 | with pytest_helper.exception_if_vertex(client, ValueError): 46 | file = await client.aio.files.get(name='files/n1gls7dyh90q') 47 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/file_search_result_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | 23 | __all__ = ["FileSearchResultContent", "Result"] 24 | 25 | 26 | class Result(BaseModel): 27 | """The result of the File Search.""" 28 | 29 | file_search_store: Optional[str] = None 30 | """The name of the file search store.""" 31 | 32 | text: Optional[str] = None 33 | """The text of the search result.""" 34 | 35 | title: Optional[str] = None 36 | """The title of the search result.""" 37 | 38 | 39 | class FileSearchResultContent(BaseModel): 40 | """File Search result content.""" 41 | 42 | type: Literal["file_search_result"] 43 | """Used as the OpenAPI type discriminator for the content oneof.""" 44 | 45 | result: Optional[List[Result]] = None 46 | """The results of the File Search.""" 47 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/file_search_result_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Iterable 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | __all__ = ["FileSearchResultContentParam", "Result"] 24 | 25 | 26 | class Result(TypedDict, total=False): 27 | """The result of the File Search.""" 28 | 29 | file_search_store: str 30 | """The name of the file search store.""" 31 | 32 | text: str 33 | """The text of the search result.""" 34 | 35 | title: str 36 | """The title of the search result.""" 37 | 38 | 39 | class FileSearchResultContentParam(TypedDict, total=False): 40 | """File Search result content.""" 41 | 42 | type: Required[Literal["file_search_result"]] 43 | """Used as the OpenAPI type discriminator for the content oneof.""" 44 | 45 | result: Iterable[Result] 46 | """The results of the File Search.""" 47 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_result_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .url_context_result import URLContextResult 23 | 24 | __all__ = ["URLContextResultContent"] 25 | 26 | 27 | class URLContextResultContent(BaseModel): 28 | """URL context result content.""" 29 | 30 | type: Literal["url_context_result"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | call_id: Optional[str] = None 34 | """ID to match the ID from the url context call block.""" 35 | 36 | is_error: Optional[bool] = None 37 | """Whether the URL context resulted in an error.""" 38 | 39 | result: Optional[List[URLContextResult]] = None 40 | """The results of the URL context.""" 41 | 42 | signature: Optional[str] = None 43 | """The signature of the URL context result.""" 44 | -------------------------------------------------------------------------------- /docs/_sources/genai.rst.txt: -------------------------------------------------------------------------------- 1 | Submodules 2 | ---------- 3 | 4 | genai.client module 5 | ------------------- 6 | 7 | .. automodule:: genai.client 8 | :members: 9 | :undoc-members: 10 | :show-inheritance: 11 | 12 | genai.batches module 13 | -------------------- 14 | 15 | .. automodule:: genai.batches 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | genai.caches module 21 | ------------------- 22 | 23 | .. automodule:: genai.caches 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | genai.chats module 29 | ------------------ 30 | 31 | .. automodule:: genai.chats 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | genai.files module 37 | ------------------ 38 | 39 | .. automodule:: genai.files 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | genai.live module 45 | ------------------ 46 | 47 | .. automodule:: genai.live 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | 52 | genai.models module 53 | ------------------- 54 | 55 | .. automodule:: genai.models 56 | :members: 57 | :undoc-members: 58 | :show-inheritance: 59 | 60 | genai.tokens module 61 | -------------------- 62 | 63 | .. automodule:: genai.tokens 64 | :members: 65 | :undoc-members: 66 | :show-inheritance: 67 | 68 | 69 | genai.tunings module 70 | -------------------- 71 | 72 | .. automodule:: genai.tunings 73 | :members: 74 | :undoc-members: 75 | :show-inheritance: 76 | 77 | genai.types module 78 | ------------------ 79 | 80 | .. automodule:: genai.types 81 | :members: 82 | :undoc-members: 83 | :show-inheritance: 84 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/audio_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, Required, Annotated, TypedDict 22 | 23 | from .._types import Base64FileInput 24 | from .._utils import PropertyInfo 25 | from .._models import set_pydantic_config 26 | from .audio_mime_type_param import AudioMimeTypeParam 27 | 28 | __all__ = ["AudioContentParam"] 29 | 30 | 31 | class AudioContentParam(TypedDict, total=False): 32 | """An audio content block.""" 33 | 34 | type: Required[Literal["audio"]] 35 | """Used as the OpenAPI type discriminator for the content oneof.""" 36 | 37 | data: Annotated[Union[str, Base64FileInput], PropertyInfo(format="base64")] 38 | 39 | mime_type: AudioMimeTypeParam 40 | """The mime type of the audio.""" 41 | 42 | uri: str 43 | 44 | 45 | set_pydantic_config(AudioContentParam, {"arbitrary_types_allowed": True}) 46 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/url_context_result_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Iterable 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | from .url_context_result_param import URLContextResultParam 24 | 25 | __all__ = ["URLContextResultContentParam"] 26 | 27 | 28 | class URLContextResultContentParam(TypedDict, total=False): 29 | """URL context result content.""" 30 | 31 | type: Required[Literal["url_context_result"]] 32 | """Used as the OpenAPI type discriminator for the content oneof.""" 33 | 34 | call_id: str 35 | """ID to match the ID from the url context call block.""" 36 | 37 | is_error: bool 38 | """Whether the URL context resulted in an error.""" 39 | 40 | result: Iterable[URLContextResultParam] 41 | """The results of the URL context.""" 42 | 43 | signature: str 44 | """The signature of the URL context result.""" 45 | -------------------------------------------------------------------------------- /google/genai/tests/shared/tunings/test_create.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for tunings.tune().""" 18 | 19 | from .... import types as genai_types 20 | from ... import pytest_helper 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | name='test_tune', 26 | parameters=genai_types.CreateTuningJobParameters( 27 | base_model='gemini-2.5-flash', 28 | training_dataset=genai_types.TuningDataset( 29 | gcs_uri='gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_train_data.jsonl', 30 | ), 31 | config=genai_types.CreateTuningJobConfig( 32 | epoch_count=1, 33 | ), 34 | ), 35 | exception_if_mldev='not supported in Gemini API.', 36 | ), 37 | ] 38 | 39 | pytestmark = pytest_helper.setup( 40 | file=__file__, 41 | globals_for_file=globals(), 42 | test_method='tunings.tune', 43 | test_table=test_table, 44 | ) 45 | 46 | pytest_plugins = ('pytest_asyncio',) 47 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_result_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Optional 19 | from typing_extensions import Literal 20 | 21 | from .._models import BaseModel 22 | from .google_search_result import GoogleSearchResult 23 | 24 | __all__ = ["GoogleSearchResultContent"] 25 | 26 | 27 | class GoogleSearchResultContent(BaseModel): 28 | """Google Search result content.""" 29 | 30 | type: Literal["google_search_result"] 31 | """Used as the OpenAPI type discriminator for the content oneof.""" 32 | 33 | call_id: Optional[str] = None 34 | """ID to match the ID from the google search call block.""" 35 | 36 | is_error: Optional[bool] = None 37 | """Whether the Google Search resulted in an error.""" 38 | 39 | result: Optional[List[GoogleSearchResult]] = None 40 | """The results of the Google Search.""" 41 | 42 | signature: Optional[str] = None 43 | """The signature of the Google Search result.""" 44 | -------------------------------------------------------------------------------- /google/genai/tests/shared/chats/test_send_message_stream.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Table tests for chats.send_message_stream().""" 17 | 18 | from ... import pytest_helper 19 | from pydantic import BaseModel 20 | 21 | 22 | class _SendMessageStreamParameters(BaseModel): 23 | model: str 24 | message: str 25 | 26 | 27 | def send_message_stream(client, parameters): 28 | chat = client.chats.create(model=parameters.model) 29 | response = chat.send_message_stream(parameters.message) 30 | for _ in response: 31 | pass 32 | 33 | test_table: list[pytest_helper.TestTableItem] = [ 34 | pytest_helper.TestTableItem( 35 | name="test_send_message_stream", 36 | parameters=_SendMessageStreamParameters( 37 | model="gemini-2.5-flash", 38 | message="Tell a joke.", 39 | ), 40 | ), 41 | ] 42 | 43 | pytestmark = pytest_helper.setup( 44 | file=__file__, 45 | globals_for_file=globals(), 46 | test_method="send_message_stream", 47 | test_table=test_table, 48 | ) 49 | 50 | pytest_plugins = ("pytest_asyncio",) 51 | -------------------------------------------------------------------------------- /google/genai/tests/models/test_generate_content_from_apikey.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from .. import pytest_helper 3 | 4 | pytestmark = pytest_helper.setup( 5 | file=__file__, 6 | globals_for_file=globals(), 7 | test_method='models.generate_content', 8 | ) 9 | 10 | 11 | def test_simple_request(client): 12 | # TODO(b/388917450): Add Vertex AI in Express mode test suite 13 | client._api_client.project = None 14 | client._api_client.location = None 15 | 16 | # To record a replay file, replace with api key (from Vertex AI Express). 17 | # API mode will not work if the API key is a ML Dev API key. 18 | # After recording, change the string back to 'key'. 19 | client._api_client._http_options.headers['x-goog-api-key'] = 'key' 20 | if not client._api_client.vertexai: 21 | return 22 | response = client.models.generate_content( 23 | model='gemini-2.0-flash-001', contents='Tell me a joke.' 24 | ) 25 | assert response.text 26 | 27 | 28 | def test_simple_request_stream(client): 29 | # TODO(b/388917450): Add Vertex AI in Express mode test suite 30 | client._api_client.project = None 31 | client._api_client.location = None 32 | 33 | # To record a replay file, replace with api key (from Vertex AI Express). 34 | # API mode will not work if the API key is a ML Dev API key. 35 | # After recording, change the string back to 'key'. 36 | client._api_client._http_options.headers['x-goog-api-key'] = 'key' 37 | if not client._api_client.vertexai: 38 | return 39 | 40 | response = client.models.generate_content_stream( 41 | model='gemini-2.0-flash-001', contents='Tell me a joke.' 42 | ) 43 | 44 | assert any(chunk.text for chunk in response) 45 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/google_search_result_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Iterable 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | from .google_search_result_param import GoogleSearchResultParam 24 | 25 | __all__ = ["GoogleSearchResultContentParam"] 26 | 27 | 28 | class GoogleSearchResultContentParam(TypedDict, total=False): 29 | """Google Search result content.""" 30 | 31 | type: Required[Literal["google_search_result"]] 32 | """Used as the OpenAPI type discriminator for the content oneof.""" 33 | 34 | call_id: str 35 | """ID to match the ID from the google search call block.""" 36 | 37 | is_error: bool 38 | """Whether the Google Search resulted in an error.""" 39 | 40 | result: Iterable[GoogleSearchResultParam] 41 | """The results of the Google Search.""" 42 | 43 | signature: str 44 | """The signature of the Google Search result.""" 45 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/image_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, Required, Annotated, TypedDict 22 | 23 | from .._types import Base64FileInput 24 | from .._utils import PropertyInfo 25 | from .._models import set_pydantic_config 26 | from .image_mime_type_param import ImageMimeTypeParam 27 | 28 | __all__ = ["ImageContentParam"] 29 | 30 | 31 | class ImageContentParam(TypedDict, total=False): 32 | """An image content block.""" 33 | 34 | type: Required[Literal["image"]] 35 | """Used as the OpenAPI type discriminator for the content oneof.""" 36 | 37 | data: Annotated[Union[str, Base64FileInput], PropertyInfo(format="base64")] 38 | 39 | mime_type: ImageMimeTypeParam 40 | """The mime type of the image.""" 41 | 42 | resolution: Literal["low", "medium", "high"] 43 | """The resolution of the media.""" 44 | 45 | uri: str 46 | 47 | 48 | set_pydantic_config(ImageContentParam, {"arbitrary_types_allowed": True}) 49 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/video_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, Required, Annotated, TypedDict 22 | 23 | from .._types import Base64FileInput 24 | from .._utils import PropertyInfo 25 | from .._models import set_pydantic_config 26 | from .video_mime_type_param import VideoMimeTypeParam 27 | 28 | __all__ = ["VideoContentParam"] 29 | 30 | 31 | class VideoContentParam(TypedDict, total=False): 32 | """A video content block.""" 33 | 34 | type: Required[Literal["video"]] 35 | """Used as the OpenAPI type discriminator for the content oneof.""" 36 | 37 | data: Annotated[Union[str, Base64FileInput], PropertyInfo(format="base64")] 38 | 39 | mime_type: VideoMimeTypeParam 40 | """The mime type of the video.""" 41 | 42 | resolution: Literal["low", "medium", "high"] 43 | """The resolution of the media.""" 44 | 45 | uri: str 46 | 47 | 48 | set_pydantic_config(VideoContentParam, {"arbitrary_types_allowed": True}) 49 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_generate_content_stream.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for models.generate_content_stream().""" 17 | 18 | from .... import types as genai_types 19 | from ... import pytest_helper 20 | from pydantic import BaseModel 21 | 22 | 23 | class _GenerateContentStreamParameters(BaseModel): 24 | model: str 25 | contents: str 26 | 27 | 28 | def generate_content_stream(client, parameters): 29 | response = client.models.generate_content_stream( 30 | model=parameters.model, 31 | contents=parameters.contents, 32 | ) 33 | for _ in response: 34 | pass 35 | 36 | 37 | test_table: list[pytest_helper.TestTableItem] = [ 38 | pytest_helper.TestTableItem( 39 | name='test_generate_content_stream', 40 | parameters=_GenerateContentStreamParameters( 41 | model='gemini-2.5-flash', 42 | contents='The quick brown fox jumps over the lazy dog.', 43 | ), 44 | ), 45 | ] 46 | 47 | pytestmark = pytest_helper.setup( 48 | file=__file__, 49 | globals_for_file=globals(), 50 | test_method='generate_content_stream', 51 | test_table=test_table, 52 | ) 53 | 54 | pytest_plugins = ('pytest_asyncio',) 55 | -------------------------------------------------------------------------------- /google/genai/_base_url.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import os 17 | from typing import Optional 18 | 19 | from .types import HttpOptions 20 | 21 | _default_base_gemini_url = None 22 | _default_base_vertex_url = None 23 | 24 | 25 | def set_default_base_urls( 26 | gemini_url: Optional[str], vertex_url: Optional[str] 27 | ) -> None: 28 | """Overrides the base URLs for the Gemini API and Vertex AI API.""" 29 | global _default_base_gemini_url, _default_base_vertex_url 30 | _default_base_gemini_url = gemini_url 31 | _default_base_vertex_url = vertex_url 32 | 33 | 34 | def get_base_url( 35 | vertexai: bool, 36 | http_options: Optional[HttpOptions] = None, 37 | ) -> Optional[str]: 38 | """Returns the default base URL based on the following priority. 39 | 40 | 1. Base URLs set via HttpOptions. 41 | 2. Base URLs set via the latest call to setDefaultBaseUrls. 42 | 3. Base URLs set via environment variables. 43 | """ 44 | if http_options and http_options.base_url: 45 | return http_options.base_url 46 | 47 | if vertexai: 48 | return _default_base_vertex_url or os.getenv('GOOGLE_VERTEX_BASE_URL') 49 | else: 50 | return _default_base_gemini_url or os.getenv('GOOGLE_GEMINI_BASE_URL') 51 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_segment_image.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for segment_image.""" 18 | 19 | import os 20 | 21 | from .... import types 22 | from ... import pytest_helper 23 | 24 | SEGMENT_IMAGE_MODEL_LATEST = 'image-segmentation-001' 25 | 26 | SOURCE_IMAGE_FILE_PATH1 = os.path.abspath( 27 | os.path.join(os.path.dirname(__file__), '../../data/google.png') 28 | ) 29 | 30 | SOURCE_IMAGE1 = types.Image.from_file(location=SOURCE_IMAGE_FILE_PATH1) 31 | 32 | test_table: list[pytest_helper.TestTableItem] = [ 33 | pytest_helper.TestTableItem( 34 | name='test_segment_background', 35 | exception_if_mldev='only supported in the Vertex AI client', 36 | parameters=types._SegmentImageParameters( 37 | model=SEGMENT_IMAGE_MODEL_LATEST, 38 | source=types.SegmentImageSource( 39 | image=SOURCE_IMAGE1, 40 | ), 41 | config=types.SegmentImageConfig( 42 | mode=types.SegmentMode.BACKGROUND, 43 | ), 44 | ), 45 | ), 46 | ] 47 | pytestmark = pytest_helper.setup( 48 | file=__file__, 49 | globals_for_file=globals(), 50 | test_method='models.segment_image', 51 | test_table=test_table, 52 | ) 53 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/interaction_get_params.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, Required, TypedDict 22 | 23 | __all__ = ["InteractionGetParamsBase", "InteractionGetParamsNonStreaming", "InteractionGetParamsStreaming"] 24 | 25 | 26 | class InteractionGetParamsBase(TypedDict, total=False): 27 | api_version: str 28 | 29 | last_event_id: str 30 | """Optional. 31 | 32 | If set, resumes the interaction stream from the next chunk after the event marked by the event id. Can only be used if `stream` is true. 33 | """ 34 | 35 | 36 | class InteractionGetParamsNonStreaming(InteractionGetParamsBase, total=False): 37 | stream: Literal[False] 38 | """If set to true, the generated content will be streamed incrementally.""" 39 | 40 | 41 | class InteractionGetParamsStreaming(InteractionGetParamsBase): 42 | stream: Required[Literal[True]] 43 | """If set to true, the generated content will be streamed incrementally.""" 44 | 45 | 46 | InteractionGetParams = Union[InteractionGetParamsNonStreaming, InteractionGetParamsStreaming] 47 | -------------------------------------------------------------------------------- /google/genai/tests/shared/files/test_upload_get_delete.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for files.upload(), files.get(), and files.delete().""" 17 | 18 | from pydantic import BaseModel 19 | from ... import pytest_helper 20 | 21 | 22 | class _UploadGetDeleteParameters(BaseModel): 23 | file_path: str 24 | 25 | 26 | def upload_get_delete(client, parameters): 27 | file = None 28 | try: 29 | file = client.files.upload(file=parameters.file_path) 30 | assert file.name 31 | got_file = client.files.get(name=file.name) 32 | assert got_file.name == file.name 33 | finally: 34 | if file and file.name: 35 | client.files.delete(name=file.name) 36 | 37 | test_table: list[pytest_helper.TestTableItem] = [ 38 | pytest_helper.TestTableItem( 39 | name="test_upload_get_delete_image", 40 | parameters=_UploadGetDeleteParameters( 41 | file_path="tests/data/google.png", 42 | ), 43 | exception_if_vertex='only supported in the Gemini Developer client', 44 | ), 45 | ] 46 | 47 | pytestmark = pytest_helper.setup( 48 | file=__file__, 49 | globals_for_file=globals(), 50 | test_method="upload_get_delete", 51 | test_table=test_table, 52 | ) 53 | 54 | pytest_plugins = ("pytest_asyncio",) 55 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/function_result_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Union, Optional 19 | from typing_extensions import Literal, TypeAlias 20 | 21 | from .._models import BaseModel 22 | from .image_content import ImageContent 23 | 24 | __all__ = ["FunctionResultContent", "Result", "ResultItems", "ResultItemsItem"] 25 | 26 | ResultItemsItem: TypeAlias = Union[str, ImageContent] 27 | 28 | 29 | class ResultItems(BaseModel): 30 | items: Optional[List[ResultItemsItem]] = None 31 | 32 | 33 | Result: TypeAlias = Union[ResultItems, str, object] 34 | 35 | 36 | class FunctionResultContent(BaseModel): 37 | """A function tool result content block.""" 38 | 39 | call_id: str 40 | """ID to match the ID from the function call block.""" 41 | 42 | result: Result 43 | """The result of the tool call.""" 44 | 45 | type: Literal["function_result"] 46 | """Used as the OpenAPI type discriminator for the content oneof.""" 47 | 48 | is_error: Optional[bool] = None 49 | """Whether the tool call resulted in an error.""" 50 | 51 | name: Optional[str] = None 52 | """The name of the tool that was called.""" 53 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/thought_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union, Iterable 21 | from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict 22 | 23 | from .._types import Base64FileInput 24 | from .._utils import PropertyInfo 25 | from .._models import set_pydantic_config 26 | from .text_content_param import TextContentParam 27 | from .image_content_param import ImageContentParam 28 | 29 | __all__ = ["ThoughtContentParam", "Summary"] 30 | 31 | Summary: TypeAlias = Union[TextContentParam, ImageContentParam] 32 | 33 | 34 | class ThoughtContentParam(TypedDict, total=False): 35 | """A thought content block.""" 36 | 37 | type: Required[Literal["thought"]] 38 | """Used as the OpenAPI type discriminator for the content oneof.""" 39 | 40 | signature: Annotated[Union[str, Base64FileInput], PropertyInfo(format="base64")] 41 | """Signature to match the backend source to be part of the generation.""" 42 | 43 | summary: Iterable[Summary] 44 | """A summary of the thought.""" 45 | 46 | 47 | set_pydantic_config(ThoughtContentParam, {"arbitrary_types_allowed": True}) 48 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/dynamic_agent_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import TYPE_CHECKING, Dict, Optional 19 | from typing_extensions import Literal 20 | 21 | from pydantic import Field as FieldInfo 22 | 23 | from .._models import BaseModel 24 | 25 | __all__ = ["DynamicAgentConfig"] 26 | 27 | 28 | class DynamicAgentConfig(BaseModel): 29 | """Configuration for dynamic agents.""" 30 | 31 | type: Optional[Literal["dynamic"]] = None 32 | """Used as the OpenAPI type discriminator for the content oneof.""" 33 | 34 | if TYPE_CHECKING: 35 | # Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a 36 | # value to this field, so for compatibility we avoid doing it at runtime. 37 | __pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride] 38 | 39 | # Stub to indicate that arbitrary properties are accepted. 40 | # To access properties that are not valid identifiers you can use `getattr`, e.g. 41 | # `getattr(obj, '$type')` 42 | def __getattr__(self, attr: str) -> object: ... 43 | else: 44 | __pydantic_extra__: Dict[str, object] 45 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/mcp_server_tool_result_content.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from typing import List, Union, Optional 19 | from typing_extensions import Literal, TypeAlias 20 | 21 | from .._models import BaseModel 22 | from .image_content import ImageContent 23 | 24 | __all__ = ["MCPServerToolResultContent", "Result", "ResultItems", "ResultItemsItem"] 25 | 26 | ResultItemsItem: TypeAlias = Union[str, ImageContent] 27 | 28 | 29 | class ResultItems(BaseModel): 30 | items: Optional[List[ResultItemsItem]] = None 31 | 32 | 33 | Result: TypeAlias = Union[ResultItems, str, object] 34 | 35 | 36 | class MCPServerToolResultContent(BaseModel): 37 | """MCPServer tool result content.""" 38 | 39 | call_id: str 40 | """ID to match the ID from the MCP server tool call block.""" 41 | 42 | result: Result 43 | """The result of the tool call.""" 44 | 45 | type: Literal["mcp_server_tool_result"] 46 | """Used as the OpenAPI type discriminator for the content oneof.""" 47 | 48 | name: Optional[str] = None 49 | """Name of the tool which is called for this specific tool call.""" 50 | 51 | server_name: Optional[str] = None 52 | """The name of the used MCP server.""" 53 | -------------------------------------------------------------------------------- /google/genai/tests/afc/test_should_append_afc_history.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for _extra_utils.should_append_afc_history.""" 17 | 18 | from ... import types 19 | from ..._extra_utils import should_append_afc_history 20 | 21 | 22 | def test_should_append_afc_history_with_default_config(): 23 | config = types.GenerateContentConfig() 24 | 25 | assert should_append_afc_history(config) == True 26 | 27 | 28 | def test_should_append_afc_history_with_empty_afc_config(): 29 | config = types.GenerateContentConfig( 30 | automatic_function_calling=types.AutomaticFunctionCallingConfig() 31 | ) 32 | 33 | assert should_append_afc_history(config) == True 34 | 35 | 36 | def test_should_append_afc_history_with_ignore_call_history_true(): 37 | config = types.GenerateContentConfig( 38 | automatic_function_calling=types.AutomaticFunctionCallingConfig( 39 | ignore_call_history=True 40 | ) 41 | ) 42 | 43 | assert should_append_afc_history(config) == False 44 | 45 | 46 | def test_should_append_afc_history_with_ignore_call_history_false(): 47 | config = types.GenerateContentConfig( 48 | automatic_function_calling=types.AutomaticFunctionCallingConfig( 49 | ignore_call_history=False 50 | ) 51 | ) 52 | 53 | assert should_append_afc_history(config) == True 54 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_upscale_image.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for upscale_image.""" 17 | 18 | import os 19 | 20 | from .... import types 21 | from ... import pytest_helper 22 | 23 | IMAGEN_MODEL_LATEST = 'imagen-4.0-upscale-preview' 24 | 25 | IMAGE_FILE_PATH = os.path.abspath( 26 | os.path.join(os.path.dirname(__file__), '../../data/bridge1.png') 27 | ) 28 | 29 | test_table: list[pytest_helper.TestTableItem] = [ 30 | pytest_helper.TestTableItem( 31 | name='test_upscale', 32 | exception_if_mldev='only supported in the Vertex AI client', 33 | parameters=types.UpscaleImageParameters( 34 | model=IMAGEN_MODEL_LATEST, 35 | image=types.Image.from_file(location=IMAGE_FILE_PATH), 36 | upscale_factor='x2', 37 | config=types.UpscaleImageConfig( 38 | include_rai_reason=True, 39 | output_mime_type='image/jpeg', 40 | output_compression_quality=80, 41 | enhance_input_image=True, 42 | image_preservation_factor=0.6, 43 | ), 44 | ), 45 | ), 46 | ] 47 | pytestmark = pytest_helper.setup( 48 | file=__file__, 49 | globals_for_file=globals(), 50 | test_method='models.upscale_image', 51 | test_table=test_table, 52 | ) 53 | -------------------------------------------------------------------------------- /google/genai/tests/caches/test_get_custom_url.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | import pytest 18 | from ... import types 19 | from .. import pytest_helper 20 | from . import constants 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | skip_in_api_mode='Get is not reproducible in the API mode.', 26 | name='test_caches_get_with_vertex_cache_name', 27 | exception_if_mldev='404', 28 | parameters=types._GetCachedContentParameters( 29 | name=constants.CACHED_CONTENT_NAME_VERTEX, 30 | config={ 31 | 'http_options': constants.VERTEX_HTTP_OPTIONS, 32 | }, 33 | ), 34 | ), 35 | pytest_helper.TestTableItem( 36 | skip_in_api_mode='Get is not reproducible in the API mode.', 37 | name='test_caches_get_with_mldev_cache_name', 38 | exception_if_vertex='404', 39 | parameters=types._GetCachedContentParameters( 40 | name=constants.CACHED_CONTENT_NAME_MLDEV, 41 | config={ 42 | 'http_options': constants.MLDEV_HTTP_OPTIONS, 43 | }, 44 | ), 45 | ), 46 | ] 47 | pytestmark = pytest_helper.setup( 48 | file=__file__, 49 | globals_for_file=globals(), 50 | test_method='caches.get', 51 | test_table=test_table, 52 | ) 53 | -------------------------------------------------------------------------------- /google/genai/tests/shared/batches/test_create_get_cancel.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests batches.create(), batches.get(), batches.cancel().""" 18 | 19 | from .... import types as genai_types 20 | from ... import pytest_helper 21 | 22 | 23 | def create_get_cancel(client, parameters): 24 | batch_job = client.batches.create( 25 | model=parameters.model, 26 | src=parameters.src, 27 | config=parameters.config, 28 | ) 29 | batch_job = client.batches.get(name=batch_job.name) 30 | client.batches.cancel(name=batch_job.name) 31 | 32 | 33 | test_table: list[pytest_helper.TestTableItem] = [ 34 | pytest_helper.TestTableItem( 35 | name="test_create_get_cancel_mldev", 36 | parameters=genai_types._CreateBatchJobParameters( 37 | model="gemini-2.5-flash", 38 | src=[{ 39 | "contents": [{ 40 | "parts": [{"text": "Why is the sky blue?"}], 41 | "role": "user", 42 | }] 43 | }], 44 | ), 45 | exception_if_vertex="not supported in Vertex AI.", 46 | ), 47 | ] 48 | 49 | pytestmark = pytest_helper.setup( 50 | file=__file__, 51 | globals_for_file=globals(), 52 | test_method="create_get_cancel", 53 | test_table=test_table, 54 | ) 55 | 56 | pytest_plugins = ("pytest_asyncio",) 57 | -------------------------------------------------------------------------------- /google/genai/tests/documents/test_delete.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | """Tests for documents.delete().""" 17 | 18 | import pytest 19 | 20 | from ... import types 21 | from .. import pytest_helper 22 | 23 | # All tests will be run for both Vertex and MLDev. 24 | test_table: list[pytest_helper.TestTableItem] = [ 25 | pytest_helper.TestTableItem( 26 | name="test_delete", 27 | parameters=types._DeleteDocumentParameters( 28 | name=( 29 | "fileSearchStores/fr3l0ri2so25-a3r1ump9x821/documents/asurveyofmodernistpoetrytxt-01zyb2rig5gu" 30 | ), 31 | config=types.DeleteDocumentConfig(force=True), 32 | ), 33 | exception_if_vertex="only supported in the Gemini Developer client", 34 | ), 35 | ] 36 | 37 | pytestmark = pytest_helper.setup( 38 | file=__file__, 39 | globals_for_file=globals(), 40 | test_method="file_search_stores.documents.delete", 41 | test_table=test_table, 42 | ) 43 | 44 | 45 | @pytest.mark.asyncio 46 | async def test_async_delete(client): 47 | with pytest_helper.exception_if_vertex(client, ValueError): 48 | await client.aio.file_search_stores.documents.delete( 49 | name="fileSearchStores/fr3l0ri2so25-a3r1ump9x821/documents/asurveyofmodernistpoetrytxt-uvmqjtmkm1h2", 50 | config=types.DeleteDocumentConfig(force=True), 51 | ) 52 | -------------------------------------------------------------------------------- /google/genai/_interactions/types/function_result_content_param.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 17 | 18 | from __future__ import annotations 19 | 20 | from typing import Union 21 | from typing_extensions import Literal, Required, TypeAlias, TypedDict 22 | 23 | from .._types import SequenceNotStr 24 | from .image_content_param import ImageContentParam 25 | 26 | __all__ = ["FunctionResultContentParam", "Result", "ResultItems", "ResultItemsItem"] 27 | 28 | ResultItemsItem: TypeAlias = Union[str, ImageContentParam] 29 | 30 | 31 | class ResultItems(TypedDict, total=False): 32 | items: SequenceNotStr[ResultItemsItem] 33 | 34 | 35 | Result: TypeAlias = Union[ResultItems, str, object] 36 | 37 | 38 | class FunctionResultContentParam(TypedDict, total=False): 39 | """A function tool result content block.""" 40 | 41 | call_id: Required[str] 42 | """ID to match the ID from the function call block.""" 43 | 44 | result: Required[Result] 45 | """The result of the tool call.""" 46 | 47 | type: Required[Literal["function_result"]] 48 | """Used as the OpenAPI type discriminator for the content oneof.""" 49 | 50 | is_error: bool 51 | """Whether the tool call resulted in an error.""" 52 | 53 | name: str 54 | """The name of the tool that was called.""" 55 | -------------------------------------------------------------------------------- /google/genai/tests/caches/test_delete_custom_url.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | import pytest 18 | from ... import types 19 | from .. import pytest_helper 20 | from . import constants 21 | 22 | 23 | test_table: list[pytest_helper.TestTableItem] = [ 24 | pytest_helper.TestTableItem( 25 | skip_in_api_mode='Delete is not reproducible in the API mode.', 26 | name='test_caches_delete_with_vertex_cache_name', 27 | exception_if_mldev='404', 28 | parameters=types._DeleteCachedContentParameters( 29 | name=constants.CACHED_CONTENT_NAME_VERTEX, 30 | config={ 31 | 'http_options': constants.VERTEX_HTTP_OPTIONS, 32 | }, 33 | ), 34 | ), 35 | pytest_helper.TestTableItem( 36 | skip_in_api_mode='Delete is not reproducible in the API mode.', 37 | name='test_caches_delete_with_mldev_cache_name', 38 | exception_if_vertex='404', 39 | parameters=types._DeleteCachedContentParameters( 40 | name=constants.CACHED_CONTENT_NAME_MLDEV, 41 | config={ 42 | 'http_options': constants.MLDEV_HTTP_OPTIONS, 43 | }, 44 | ), 45 | ), 46 | ] 47 | pytestmark = pytest_helper.setup( 48 | file=__file__, 49 | globals_for_file=globals(), 50 | test_method='caches.delete', 51 | test_table=test_table, 52 | ) 53 | -------------------------------------------------------------------------------- /google/genai/tests/shared/models/test_recontext_image.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | 17 | """Tests for recontext_image.""" 18 | 19 | from .... import types 20 | from ... import pytest_helper 21 | 22 | PRODUCT_RECONTEXT_MODEL_LATEST = 'imagen-product-recontext-preview-06-30' 23 | 24 | BACKPACK1 = types.Image( 25 | gcs_uri='gs://genai-sdk-tests/inputs/images/backpack1.png', 26 | ) 27 | 28 | test_table: list[pytest_helper.TestTableItem] = [ 29 | pytest_helper.TestTableItem( 30 | name='test_product_recontext', 31 | exception_if_mldev='only supported in the Vertex AI client', 32 | parameters=types._RecontextImageParameters( 33 | model=PRODUCT_RECONTEXT_MODEL_LATEST, 34 | source=types.RecontextImageSource( 35 | prompt='On a school desk', 36 | product_images=[ 37 | types.ProductImage(product_image=BACKPACK1) 38 | ], 39 | ), 40 | config=types.RecontextImageConfig( 41 | number_of_images=1, 42 | add_watermark=True, 43 | output_mime_type='image/jpeg', 44 | ), 45 | ), 46 | ), 47 | ] 48 | 49 | 50 | pytestmark = pytest_helper.setup( 51 | file=__file__, 52 | globals_for_file=globals(), 53 | test_method='models.recontext_image', 54 | test_table=test_table, 55 | ) 56 | -------------------------------------------------------------------------------- /google/genai/_adapters.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import typing 17 | 18 | from ._mcp_utils import mcp_to_gemini_tools 19 | from .types import FunctionCall, Tool 20 | 21 | if typing.TYPE_CHECKING: 22 | from mcp import types as mcp_types 23 | from mcp import ClientSession 24 | 25 | 26 | class McpToGenAiToolAdapter: 27 | """Adapter for working with MCP tools in a GenAI client.""" 28 | 29 | def __init__( 30 | self, 31 | session: "mcp.ClientSession", # type: ignore # noqa: F821 32 | list_tools_result: "mcp_types.ListToolsResult", # type: ignore 33 | ) -> None: 34 | self._mcp_session = session 35 | self._list_tools_result = list_tools_result 36 | 37 | async def call_tool( 38 | self, function_call: FunctionCall 39 | ) -> "mcp_types.CallToolResult": # type: ignore 40 | """Calls a function on the MCP server.""" 41 | name = function_call.name if function_call.name else "" 42 | arguments = dict(function_call.args) if function_call.args else {} 43 | 44 | return typing.cast( 45 | "mcp_types.CallToolResult", 46 | await self._mcp_session.call_tool( 47 | name=name, 48 | arguments=arguments, 49 | ), 50 | ) 51 | 52 | @property 53 | def tools(self) -> list[Tool]: 54 | """Returns a list of Google GenAI tools.""" 55 | return mcp_to_gemini_tools(self._list_tools_result.tools) 56 | --------------------------------------------------------------------------------