diff --git a/.github/workflows/google-contributor-stale.yml b/.github/workflows/google-contributor-stale.yml new file mode 100644 index 000000000..ebff9cfcd --- /dev/null +++ b/.github/workflows/google-contributor-stale.yml @@ -0,0 +1,29 @@ +# This workflow closes PRs that have had no activity for 14 days. +name: Close inactive google-contributor PRs + +on: + schedule: + - cron: "30 2 * * *" + workflow_dispatch: {} + +jobs: + stale: + runs-on: ubuntu-latest + permissions: + pull-requests: write + issues: write + + steps: + - uses: actions/stale@v10 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + any-of-labels: "google-contributor" + days-before-pr-stale: 14 + days-before-pr-close: 0 + operations-per-run: 100 + stale-pr-label: "status:stale" + exempt-pr-labels: "override-stale" + close-pr-message: > + This google-contributor PR has been inactive for 14 days. + days-before-issue-stale: -1 + days-before-issue-close: -1 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 5fdcb436f..97426337d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -3,8 +3,9 @@ name: Mark and close stale issues on: schedule: - # Scheduled to run at 1:30 UTC everyday - - cron: '30 1 * * *' + # Scheduled to run at 1:30 UTC everyday + - cron: '30 1 * * *' + workflow_dispatch: {} jobs: stale: @@ -14,11 +15,12 @@ jobs: issues: write steps: - - uses: actions/stale@v5 + - uses: actions/stale@v10 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-issue-stale: 7 days-before-issue-close: 2 + operations-per-run: 100 stale-issue-label: "status:stale" close-issue-reason: not_planned any-of-labels: "status:awaiting user response" diff --git a/CHANGELOG.md b/CHANGELOG.md index acc50b0dd..a982e3364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,131 @@ # Changelog +## [2.9.0](https://github.com/googleapis/python-genai/compare/v2.9.0-rc1...v2.9.0) (2026-06-19) + +### Major updates + +* **The interactions implementation has been completely replaced**. The public api surface is unchanged. ([d830f16](https://github.com/googleapis/python-genai/commit/d830f165d223ac5f42ab3fa74d2c3d868b0054d8)) + +### Features + +* Add audioOffset to VoiceActivity ([fb785e4](https://github.com/googleapis/python-genai/commit/fb785e402a3aa958b45bf6300f0be972b2f92bf9)) +* Add gemini-3-flash-preview (gemini-3.1, gemini-3.5, gemini-4 are already mapped) to the local tokenizer map. ([749f8a1](https://github.com/googleapis/python-genai/commit/749f8a1b1b5ef06b4b0fc604bc5482f003ef0e1a)), closes [#1972](https://github.com/googleapis/python-genai/issues/1972) +* Add interimInputTranscription to LiveServerContent ([fb785e4](https://github.com/googleapis/python-genai/commit/fb785e402a3aa958b45bf6300f0be972b2f92bf9)) +* Add LanguageAuto, LanguageHints, and adaptationPhrases to AudioTranscriptionConfig ([fb785e4](https://github.com/googleapis/python-genai/commit/fb785e402a3aa958b45bf6300f0be972b2f92bf9)) +* Broaden publisher model path check to support all publishers ([5d282e6](https://github.com/googleapis/python-genai/commit/5d282e662de39d7fb68d258e6ca20446dba16576)) +* Add ServiceTier to UsageMetadata ([45b4963](https://github.com/googleapis/python-genai/commit/45b4963f4cdc8dc01cffe85260c629e50595fbf9)) +* Expose Computer Use API fields ([420b5a7](https://github.com/googleapis/python-genai/commit/420b5a774852501f04c716f74b6c58f466bb71df)) +* Gemma 4 local tokenizer support ([ca97c58](https://github.com/googleapis/python-genai/commit/ca97c5805666f6386d0148848132c07ce81e2c72)) +* **interaction-api:** Add presence_penalty, frequency_penalty, and cached_content to models.proto ([05f16fe](https://github.com/googleapis/python-genai/commit/05f16fea01d4c8bdc4d6ac9c2b7bbed11ada3aee)) +* **interaction-api:** Rename usage to total_usage in StreamMetadata. ([7c331c6](https://github.com/googleapis/python-genai/commit/7c331c6c40825cbbbd7cfc354357c171bdf395f5)) + +### Bug Fixes + +* Add fallback for `aiohttp.readline` without `max_line_length` for backward compatibility because we still want to keep aiohttp as optional dependency ([e99ab99](https://github.com/googleapis/python-genai/commit/e99ab99d63625b2f383a08f5fb91812c096f1c2b)), closes [#2487](https://github.com/googleapis/python-genai/issues/2487) +* Fix header ([f8f9749](https://github.com/googleapis/python-genai/commit/f8f97496965795469888b93f3c70d6ea08296a83)) +* Keep live music API keys out of websocket urls ([#2564](https://github.com/googleapis/python-genai/issues/2564)) ([c754ebf](https://github.com/googleapis/python-genai/commit/c754ebf3973fde9894b24c2425cee67eb2d03b64)) +* Make `transformers` an optional dependency for local tokenizers, also add other dependencies to local-tokenizer-extras. ([528926b](https://github.com/googleapis/python-genai/commit/528926b5a94fb6590846e739e643895016d2c0d0)) +* Use .model_copy() instead of deprecated .copy() ([216369f](https://github.com/googleapis/python-genai/commit/216369f519712285db0902f0b248be3c4faf664c)) + + + + +## [2.9.0-rc1](https://github.com/googleapis/python-genai/compare/v2.9.0-rc0...v2.9.0-rc1) (2026-06-17) + + +### Features + +* Add audioOffset to VoiceActivity ([fb785e4](https://github.com/googleapis/python-genai/commit/fb785e402a3aa958b45bf6300f0be972b2f92bf9)) +* Add gemini-3-flash-preview (gemini-3.1, gemini-3.5, gemini-4 are already mapped) to the local tokenizer map. ([749f8a1](https://github.com/googleapis/python-genai/commit/749f8a1b1b5ef06b4b0fc604bc5482f003ef0e1a)), closes [#1972](https://github.com/googleapis/python-genai/issues/1972) +* Add interimInputTranscription to LiveServerContent ([fb785e4](https://github.com/googleapis/python-genai/commit/fb785e402a3aa958b45bf6300f0be972b2f92bf9)) +* Add LanguageAuto, LanguageHints, and adaptationPhrases to AudioTranscriptionConfig ([fb785e4](https://github.com/googleapis/python-genai/commit/fb785e402a3aa958b45bf6300f0be972b2f92bf9)) +* Broaden publisher model path check to support all publishers ([5d282e6](https://github.com/googleapis/python-genai/commit/5d282e662de39d7fb68d258e6ca20446dba16576)) + + +### Miscellaneous Chores + +* Release 2.9.0-rc1 ([b95f2a8](https://github.com/googleapis/python-genai/commit/b95f2a87213da7b5305d9fb0ea801ca657fb109d)) + +## [2.9.0-rc0](https://github.com/googleapis/python-genai/compare/v2.8.0...v2.9.0-rc0) (2026-06-16) + +### Major updates + +* **The interactions implementation has been completely replaced**. The public api surface should be unchanged. ([d830f16](https://github.com/googleapis/python-genai/commit/d830f165d223ac5f42ab3fa74d2c3d868b0054d8)) + +### Features + +* Add ServiceTier to UsageMetadata ([45b4963](https://github.com/googleapis/python-genai/commit/45b4963f4cdc8dc01cffe85260c629e50595fbf9)) +* Expose Computer Use API fields ([420b5a7](https://github.com/googleapis/python-genai/commit/420b5a774852501f04c716f74b6c58f466bb71df)) +* Gemma 4 local tokenizer support ([ca97c58](https://github.com/googleapis/python-genai/commit/ca97c5805666f6386d0148848132c07ce81e2c72)) +* **interaction-api:** Add presence_penalty, frequency_penalty, and cached_content to models.proto ([05f16fe](https://github.com/googleapis/python-genai/commit/05f16fea01d4c8bdc4d6ac9c2b7bbed11ada3aee)) +* **interaction-api:** Rename usage to total_usage in StreamMetadata. ([7c331c6](https://github.com/googleapis/python-genai/commit/7c331c6c40825cbbbd7cfc354357c171bdf395f5)) + + +### Bug Fixes + +* Add fallback for `aiohttp.readline` without `max_line_length` for backward compatibility because we still want to keep aiohttp as optional dependency ([e99ab99](https://github.com/googleapis/python-genai/commit/e99ab99d63625b2f383a08f5fb91812c096f1c2b)), closes [#2487](https://github.com/googleapis/python-genai/issues/2487) +* Fix header ([f8f9749](https://github.com/googleapis/python-genai/commit/f8f97496965795469888b93f3c70d6ea08296a83)) +* Keep live music API keys out of websocket urls ([#2564](https://github.com/googleapis/python-genai/issues/2564)) ([c754ebf](https://github.com/googleapis/python-genai/commit/c754ebf3973fde9894b24c2425cee67eb2d03b64)) +* Make `transformers` an optional dependency for local tokenizers, also add other dependencies to local-tokenizer-extras. ([528926b](https://github.com/googleapis/python-genai/commit/528926b5a94fb6590846e739e643895016d2c0d0)) +* Use .model_copy() instead of deprecated .copy() ([216369f](https://github.com/googleapis/python-genai/commit/216369f519712285db0902f0b248be3c4faf664c)) + + +### Documentation + +* Announce Automatic Function Calling (AFC) upcoming breaking change warning ([4697258](https://github.com/googleapis/python-genai/commit/4697258417902a5d0074a2247db34bfdf40e5468)) +* Clarify Live API START/END_SENSITIVITY_HIGH/LOW defaults are different in Gemini Live and Gemini Enterprise Agent Platform Live API ([a0ec6ab](https://github.com/googleapis/python-genai/commit/a0ec6abc8f54f9cfc110e9b1dd3271971961f193)), closes [#2555](https://github.com/googleapis/python-genai/issues/2555) +* Regenerate docs for 2.8.0 ([93e7ab1](https://github.com/googleapis/python-genai/commit/93e7ab1e8851dd68e59368d49bc2e3695dfd5148)) + + +## [2.8.0](https://github.com/googleapis/python-genai/compare/v2.7.0...v2.8.0) (2026-06-03) + + +### Features + +* Add Agent Platform MCP support to async generate_content ([e3be9af](https://github.com/googleapis/python-genai/commit/e3be9af3c21c9f8f625aecd890a5ee1f9993fb3d)) +* Add transcription language code. ([53ea3f6](https://github.com/googleapis/python-genai/commit/53ea3f689bf02ecbdbecf8a2a4aff77c48016eb9)) +* Add TranslationConfig for live translation. ([4775314](https://github.com/googleapis/python-genai/commit/47753147a30c10138f1a4e46c1c8e8069ae8e86d)) +* Support ReinforcementTuning in GenAI SDK including ValidateReward API method. ([e0854a6](https://github.com/googleapis/python-genai/commit/e0854a6d1f487435507d2cffd82ad133de8b931d)) + + +### Bug Fixes + +* Include all fields of a single tool ([7b1d498](https://github.com/googleapis/python-genai/commit/7b1d4982f4a61def33db8873feb1334416d4a0e4)) + + +### Documentation + +* A comment for field `enable_widget` in message `GoogleMaps` is changed ([74d81dd](https://github.com/googleapis/python-genai/commit/74d81dd2e3cfe9eb9350751cfbcb597fcd60a479)) +* A comment for field `google_maps_widget_context_token` in message `GroundingMetadata` is changed ([74d81dd](https://github.com/googleapis/python-genai/commit/74d81dd2e3cfe9eb9350751cfbcb597fcd60a479)) +* Remove `codegen_instructions.md` for simpler maintenance, Gemini API Skills should be the single source of truth ([bfa2a49](https://github.com/googleapis/python-genai/commit/bfa2a495e5c7e5acd232c46d3f84913f3a50522a)) +* Update README.md for model/SDK Changes and direct to Gemini API Skills ([47c1a13](https://github.com/googleapis/python-genai/commit/47c1a13e8475b3a2553e699f9ff0823d8757fa92)) +* Update the docs for 2.7 ([bbef98e](https://github.com/googleapis/python-genai/commit/bbef98e64ebf6e12a5ab1aba02302a28ca1faf4f)) + +## [2.7.0](https://github.com/googleapis/python-genai/compare/v2.6.0...v2.7.0) (2026-05-27) + + +### Features + +* Additional computer_use field support for vertex. ([b4828fa](https://github.com/googleapis/python-genai/commit/b4828fa5b085d2dbb47a0adc9c10e4b35d60ad64)) +* **interaction-api:** Allow "text/csv" as a supported document mime type for Interaction API. ([543137b](https://github.com/googleapis/python-genai/commit/543137b78d392c7d81a287f3916e215f13845a72)) +* **interaction-api:** Enable BigQuery tool in Deep Research config. ([5dc17e5](https://github.com/googleapis/python-genai/commit/5dc17e53eec9f3bfbdb39a6a4c8f92a45868167e)) +* Support Reinforcement Tuning in GenAI SDK ([0ead888](https://github.com/googleapis/python-genai/commit/0ead8888695f379ecf35cfc68d69e4b7e8e20403)) + +## [2.6.0](https://github.com/googleapis/python-genai/compare/v2.5.0...v2.6.0) (2026-05-21) + + +### Features + +* Add `enable_prompt_injection_detection` for Computer Use feature for the Gemini API. ([b1f632d](https://github.com/googleapis/python-genai/commit/b1f632d5d617a8e24fd4cb87556a4eb180b6d29b)) +* Add budget_exceeded status ([15443c0](https://github.com/googleapis/python-genai/commit/15443c0211446c41a9ab2705dd2282d324581eb7)) +* Add gemini-3.5-flash ([15443c0](https://github.com/googleapis/python-genai/commit/15443c0211446c41a9ab2705dd2282d324581eb7)) +* Add new fields ([2910346](https://github.com/googleapis/python-genai/commit/291034641aa9cb153f501de0f39db6382186f1c6)) + + +### Documentation + +* Replace `vertexai` with `enterprise` in Client instantiation ([c1c6df7](https://github.com/googleapis/python-genai/commit/c1c6df74e888fd25061ad4364b05977a857b90a3)) + ## [2.5.0](https://github.com/googleapis/python-genai/compare/v2.4.0...v2.5.0) (2026-05-20) diff --git a/README.md b/README.md index 2510fc7a5..c1cdbe5a8 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,31 @@ -------- **Documentation:** https://googleapis.github.io/python-genai/ - ----- Google Gen AI Python SDK provides an interface for developers to integrate -Google's generative models into their Python applications. It supports the -[Gemini Developer API](https://ai.google.dev/gemini-api/docs) and +Google's generative models into their Python applications. It supports +the [Gemini Developer API](https://ai.google.dev/gemini-api/docs) and [Gemini Enterprise Agent Platform](https://docs.cloud.google.com/gemini-enterprise-agent-platform) APIs. -## Code Generation +> [!WARNING] +> **Upcoming Breaking Change to Automatic Function Calling (AFC):** +> We will introduce a breaking change to the Automatic Function Calling (AFC) +> feature in the next major version. Specifically, users will not be able to +> invoke AFC from direct calls to `Models.generate_content` or its stream and +> async variants. Instead, users should invoke AFC from `chats` modules. + +## Agent Skills + +Large Language Models (LLMs) and generative AI coding assistants are often trained on static datasets. As a result, they may be unaware of recent updates and suggest outdated or legacy libraries. + +To ensure your AI coding helper (such as Antigravity, Claude Code, Cursor, or other IDE extensions) generates up-to-date code using the correct SDK syntax and best practices, we recommend equipping your assistant with **Gemini API Skills**. Loading these skills injects the correct patterns and guidelines directly into your AI assistant's context. -Generative models are often unaware of recent API and SDK updates and may suggest outdated or legacy code. +Depending on your target platform, use the corresponding Agent Skill repository: -We recommend using our Code Generation instructions [`codegen_instructions.md`](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features. Copy and paste the instructions into your development environment to provide the model with the necessary context. +* **Gemini Developer API**: Use the [google-gemini/gemini-skills](https://github.com/google-gemini/gemini-skills) repository. +* **Gemini Enterprise Agent Platform (formerly Vertex AI)**: Use the [google/skills](https://github.com/google/skills/tree/main/skills/cloud/gemini-api) repository. ## Installation @@ -43,7 +54,7 @@ from google.genai import types ## Create a client Please run one of the following code blocks to create a client for -different services ([Gemini Developer API](https://ai.google.dev/gemini-api/docs) or [Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/overview)). +different services ([Gemini Developer API](https://ai.google.dev/gemini-api/docs) or [Agent Platform](https://docs.cloud.google.com/gemini-enterprise-agent-platform)). ```python from google import genai @@ -55,9 +66,9 @@ client = genai.Client(api_key='GEMINI_API_KEY') ```python from google import genai -# Only run this block for Vertex AI API +# Only run this block for Agent Platform client = genai.Client( - enterprise=True, project='your-project-id', location='us-central1' + enterprise=True, project='your-project-id', location='global' ) ``` @@ -114,13 +125,13 @@ precedence. export GEMINI_API_KEY='your-api-key' ``` -**Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`, +**Gemini API on Agent Platform:** Set `GOOGLE_GENAI_USE_ENTERPRISE`, `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`, as shown below: ```bash -export GOOGLE_GENAI_USE_VERTEXAI=true +export GOOGLE_GENAI_USE_ENTERPRISE=true export GOOGLE_CLOUD_PROJECT='your-project-id' -export GOOGLE_CLOUD_LOCATION='us-central1' +export GOOGLE_CLOUD_LOCATION='global' ``` ```python @@ -156,7 +167,7 @@ To explicitly close the async client: from google.genai import Client aclient = Client( - enterprise=True, project='my-project-id', location='us-central1' + enterprise=True, project='my-project-id', location='global' ).aio response_1 = await aclient.models.generate_content( model=MODEL_ID, @@ -222,7 +233,7 @@ from google.genai import types client = genai.Client( enterprise=True, project='your-project-id', - location='us-central1', + location='global', http_options=types.HttpOptions(api_version='v1') ) ``` @@ -305,7 +316,6 @@ will not include api version, project, or location. Expected request url will be: https://test-api-gateway-proxy.com/publishers/google/models/gemini-3-pro-preview - ## Types Parameter types can be specified as either dictionaries(`TypedDict`) or @@ -323,7 +333,7 @@ See the 'Create a client' section above to initialize a client. ```python response = client.models.generate_content( - model='gemini-2.5-flash', contents='Why is the sky blue?' + model='gemini-3.5-flash', contents='Why is the sky blue?' ) print(response.text) ``` @@ -334,7 +344,7 @@ print(response.text) from google.genai import types response = client.models.generate_content( - model='gemini-2.5-flash-image', + model='gemini-3.1-flash-image', contents='A cartoon infographic for flying sneakers', config=types.GenerateContentConfig( response_modalities=["IMAGE"], @@ -363,7 +373,7 @@ python code. ```python file = client.files.upload(file='a11.txt') response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents=['Could you summarize this file?', file] ) print(response.text) @@ -596,7 +606,7 @@ we use GenerateContentConfig to specify the desired behavior from the model. from google.genai import types response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='high', config=types.GenerateContentConfig( system_instruction='I say high, you say low', @@ -645,7 +655,7 @@ print(async_pager[0]) from google.genai import types response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='Say something bad.', config=types.GenerateContentConfig( safety_settings=[ @@ -679,7 +689,7 @@ def get_current_weather(location: str) -> str: response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='What is the weather like in Boston?', config=types.GenerateContentConfig(tools=[get_current_weather]), ) @@ -697,7 +707,7 @@ as follows: from google.genai import types response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='What is the weather like in Boston?', config=types.GenerateContentConfig( tools=[get_current_weather], @@ -744,7 +754,7 @@ function = types.FunctionDeclaration( tool = types.Tool(function_declarations=[function]) response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='What is the weather like in Boston?', config=types.GenerateContentConfig(tools=[tool]), ) @@ -788,7 +798,7 @@ function_response_content = types.Content( ) response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents=[ user_prompt_content, function_call_content, @@ -823,7 +833,7 @@ def get_current_weather(location: str) -> str: return "sunny" response = client.models.generate_content( - model="gemini-2.5-flash", + model="gemini-3.5-flash", contents="What is the weather like in Boston?", config=types.GenerateContentConfig( tools=[get_current_weather], @@ -853,7 +863,7 @@ def get_current_weather(location: str) -> str: return "sunny" response = client.models.generate_content( - model="gemini-2.5-flash", + model="gemini-3.5-flash", contents="What is the weather like in Boston?", config=types.GenerateContentConfig( tools=[get_current_weather], @@ -900,10 +910,9 @@ async def run(): # Send request to the model with MCP function declarations response = await client.aio.models.generate_content( - model="gemini-2.5-flash", + model="gemini-3.5-flash", contents=prompt, config=genai.types.GenerateContentConfig( - temperature=0, tools=[session], # uses the session, will automatically call the tool using automatic function calling ), ) @@ -945,7 +954,7 @@ user_profile = { } response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='Give me a random user profile.', config={ 'response_mime_type': 'application/json', @@ -975,7 +984,7 @@ class CountryInfo(BaseModel): response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='Give me information for the United States.', config=types.GenerateContentConfig( response_mime_type='application/json', @@ -989,7 +998,7 @@ print(response.text) from google.genai import types response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='Give me information for the United States.', config=types.GenerateContentConfig( response_mime_type='application/json', @@ -1028,7 +1037,7 @@ to you, rather than being returned as one chunk. ```python for chunk in client.models.generate_content_stream( - model='gemini-2.5-flash', contents='Tell me a story in 300 words.' + model='gemini-3.5-flash', contents='Tell me a story in 300 words.' ): print(chunk.text, end='') ``` @@ -1042,7 +1051,7 @@ you can use the `from_uri` class method to create a `Part` object. from google.genai import types for chunk in client.models.generate_content_stream( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents=[ 'What is this image about?', types.Part.from_uri( @@ -1066,7 +1075,7 @@ with open(YOUR_IMAGE_PATH, 'rb') as f: image_bytes = f.read() for chunk in client.models.generate_content_stream( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents=[ 'What is this image about?', types.Part.from_bytes(data=image_bytes, mime_type=YOUR_IMAGE_MIME_TYPE), @@ -1085,7 +1094,7 @@ of `client.models.generate_content` ```python response = await client.aio.models.generate_content( - model='gemini-2.5-flash', contents='Tell me a story in 300 words.' + model='gemini-3.5-flash', contents='Tell me a story in 300 words.' ) print(response.text) @@ -1095,7 +1104,7 @@ print(response.text) ```python async for chunk in await client.aio.models.generate_content_stream( - model='gemini-2.5-flash', contents='Tell me a story in 300 words.' + model='gemini-3.5-flash', contents='Tell me a story in 300 words.' ): print(chunk.text, end='') ``` @@ -1104,7 +1113,7 @@ async for chunk in await client.aio.models.generate_content_stream( ```python response = client.models.count_tokens( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='why is the sky blue?', ) print(response) @@ -1116,7 +1125,7 @@ Compute tokens is only supported in Vertex AI. ```python response = client.models.compute_tokens( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='why is the sky blue?', ) print(response) @@ -1126,7 +1135,7 @@ print(response) ```python response = await client.aio.models.count_tokens( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='why is the sky blue?', ) print(response) @@ -1137,7 +1146,7 @@ print(response) ```python from google.genai import local_tokenizer -tokenizer = local_tokenizer.LocalTokenizer(model_name='gemini-2.5-flash') +tokenizer = local_tokenizer.LocalTokenizer(model_name='gemini-3.5-flash') result = tokenizer.count_tokens("What is your name?") ``` @@ -1146,7 +1155,7 @@ result = tokenizer.count_tokens("What is your name?") ```python from google.genai import local_tokenizer -tokenizer = local_tokenizer.LocalTokenizer(model_name='gemini-2.5-flash') +tokenizer = local_tokenizer.LocalTokenizer(model_name='gemini-3.5-flash') result = tokenizer.compute_tokens("What is your name?") ``` @@ -1251,8 +1260,6 @@ response3.generated_images[0].image.show() ### Veo -Support for generating videos is considered public preview - #### Generate Videos (Text to Video) ```python @@ -1355,7 +1362,7 @@ that it can reflect on its previous responses (i.e., engage in an ongoing ### Send Message (Synchronous Non-Streaming) ```python -chat = client.chats.create(model='gemini-2.5-flash') +chat = client.chats.create(model='gemini-3.5-flash') response = chat.send_message('tell me a story') print(response.text) response = chat.send_message('summarize the story you told me in 1 sentence') @@ -1365,7 +1372,7 @@ print(response.text) ### Send Message (Synchronous Streaming) ```python -chat = client.chats.create(model='gemini-2.5-flash') +chat = client.chats.create(model='gemini-3.5-flash') for chunk in chat.send_message_stream('tell me a story'): print(chunk.text) ``` @@ -1373,7 +1380,7 @@ for chunk in chat.send_message_stream('tell me a story'): ### Send Message (Asynchronous Non-Streaming) ```python -chat = client.aio.chats.create(model='gemini-2.5-flash') +chat = client.aio.chats.create(model='gemini-3.5-flash') response = await chat.send_message('tell me a story') print(response.text) ``` @@ -1381,7 +1388,7 @@ print(response.text) ### Send Message (Asynchronous Streaming) ```python -chat = client.aio.chats.create(model='gemini-2.5-flash') +chat = client.aio.chats.create(model='gemini-3.5-flash') async for chunk in await chat.send_message_stream('tell me a story'): print(chunk.text) ``` @@ -1440,7 +1447,7 @@ else: file_uris = [file1.uri, file2.uri] cached_content = client.caches.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', config=types.CreateCachedContentConfig( contents=[ types.Content( @@ -1475,7 +1482,7 @@ cached_content = client.caches.get(name=cached_content.name) from google.genai import types response = client.models.generate_content( - model='gemini-2.5-flash', + model='gemini-3.5-flash', contents='Summarize the pdfs', config=types.GenerateContentConfig( cached_content=cached_content.name, @@ -1484,9 +1491,7 @@ response = client.models.generate_content( print(response.text) ``` -## Interactions (Preview) - -> **Warning:** The Interactions API is in **Beta**. This is a preview of an experimental feature. Features and schemas are subject to **breaking changes**. +## Interactions The Interactions API is a unified interface for interacting with Gemini models and agents. It simplifies state management, tool orchestration, and long-running tasks. @@ -1496,7 +1501,7 @@ See the [documentation site](https://ai.google.dev/gemini-api/docs/interactions) ```python interaction = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input='Tell me a short joke about programming.' ) print(interaction.outputs[-1].text) @@ -1510,14 +1515,14 @@ The Interactions API supports server-side state management. You can continue a c ```python # 1. First turn interaction1 = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input='Hi, my name is Amir.' ) print(f"Model: {interaction1.outputs[-1].text}") # 2. Second turn (passing previous_interaction_id) interaction2 = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input='What is my name?', previous_interaction_id=interaction1.id ) @@ -1567,7 +1572,7 @@ import base64 # base64_image = ... interaction = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input=[ {'type': 'text', 'text': 'Describe the image.'}, {'type': 'image', 'data': base64_image, 'mime_type': 'image/png'} @@ -1602,7 +1607,7 @@ weather_tool = { # 2. Send the request with tools interaction = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input='What is the weather in Mountain View, CA?', tools=[weather_tool] ) @@ -1617,7 +1622,7 @@ for output in interaction.outputs: # Send result back to the model interaction = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', previous_interaction_id=interaction.id, input=[{ 'type': 'function_result', @@ -1637,7 +1642,7 @@ You can also use Google's built-in tools, such as **Google Search** or **Code Ex ```python interaction = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input='Who won the last Super Bowl?', tools=[{'type': 'google_search'}] ) @@ -1653,7 +1658,7 @@ if text_output: ```python interaction = client.interactions.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', input='Calculate the 50th Fibonacci number.', tools=[{'type': 'code_execution'}] ) @@ -1696,7 +1701,7 @@ section above to initialize a client. ```python from google.genai import types -model = 'gemini-2.5-flash' +model = 'gemini-3.5-flash' training_dataset = types.TuningDataset( # or gcs_uri=my_vertex_multimodal_dataset gcs_uri='gs://your-gcs-bucket/your-tuning-data.jsonl', @@ -1850,7 +1855,7 @@ Vertex AI: ```python # Specify model and source file only, destination and job display name will be auto-populated job = client.batches.create( - model='gemini-2.5-flash', + model='gemini-3.5-flash', src='bq://my-project.my-dataset.my-table', # or "gs://path/to/input/data" ) @@ -1862,7 +1867,7 @@ Gemini Developer API: ```python # Create a batch job with inlined requests batch_job = client.batches.create( - model="gemini-2.5-flash", + model="gemini-3.5-flash", src=[{ "contents": [{ "parts": [{ @@ -1897,7 +1902,7 @@ file = client.files.upload( # Create a batch job with file name batch_job = client.batches.create( - model="gemini-2.5-flash", + model="gemini-3.5-flash", src="files/test-json", ) ``` diff --git a/codegen_instructions.md b/codegen_instructions.md deleted file mode 100644 index 9f9c1d6d3..000000000 --- a/codegen_instructions.md +++ /dev/null @@ -1,677 +0,0 @@ -# Gemini API Coding Guidelines (Python) - -You are a Gemini API coding expert. Help me with writing code using the Gemini -API calling the official libraries and SDKs. - -Please follow the following guidelines when generating code. - -**Official Documentation:** [ai.google.dev/gemini-api/docs](https://ai.google.dev/gemini-api/docs) - -## Golden Rule: Use the Correct and Current SDK - -Always use the **Google GenAI SDK** (`google-genai`), which is the unified -standard library for all Gemini API requests (AI Studio/Gemini Developer API -and Vertex AI) as of 2025. Do not use legacy libraries and SDKs. - -- **Library Name:** Google GenAI SDK -- **Python Package:** `google-genai` -- **Legacy Library**: (`google-generativeai`) is deprecated. - -**Installation:** - -- **Incorrect:** `pip install google-generativeai` -- **Incorrect:** `pip install google-ai-generativelanguage` -- **Correct:** `pip install google-genai` - -**APIs and Usage:** - -- **Incorrect:** `import google.generativeai as genai`-> **Correct:** `from - google import genai` -- **Incorrect:** `from google.ai import generativelanguage_v1` -> - **Correct:** `from google import genai` -- **Incorrect:** `from google.generativeai` -> **Correct:** `from google - import genai` -- **Incorrect:** `from google.generativeai import types` -> **Correct:** `from - google.genai import types` -- **Incorrect:** `import google.generativeai as genai` -> **Correct:** `from - google import genai` -- **Incorrect:** `genai.configure(api_key=...)` -> **Correct:** `client = - genai.Client(api_key='...')` -- **Incorrect:** `model = genai.GenerativeModel(...)` -- **Incorrect:** `model.generate_content(...)` -> **Correct:** - `client.models.generate_content(...)` -- **Incorrect:** `response = model.generate_content(..., stream=True)` -> - **Correct:** `client.models.generate_content_stream(...)` -- **Incorrect:** `genai.GenerationConfig(...)` -> **Correct:** - `types.GenerateContentConfig(...)` -- **Incorrect:** `safety_settings={...}` -> **Correct:** Use `safety_settings` - inside a `GenerateContentConfig` object. -- **Incorrect:** `from google.api_core.exceptions import GoogleAPIError` -> - **Correct:** `from google.genai.errors import APIError` -- **Incorrect:** `types.ResponseModality.TEXT` - -## Initialization and API Key - -The `google-genai` library requires creating a client object for all API calls. - -- Always use `client = genai.Client()` to create a client object. -- Set `GEMINI_API_KEY` (or `GOOGLE_API_KEY`) environment variable, which will be picked up - automatically. - -```python - -from google import genai - -# Best practice: implicitly use env variable - -client = genai.Client() - -# Alternative: explicit key (avoid hardcoding in production) - -# client = genai.Client(api_key='YOUR_API_KEY') - -``` - -## Customizing API Endpoint (Base URL) - -For advanced use cases, such as using a proxy or a private Vertex AI endpoint, you can customize the base URL for API requests. This is done by passing an `HttpOptions` object to the client constructor. - -```python -from google import genai -from google.genai import types - -# Configure the custom base URL -http_opts = types.HttpOptions( - base_url="https://my.custom.proxy/or/endpoint" -) - -client = genai.Client(http_options=http_opts) -response = client.models.generate_content( - model='gemini-2.5-flash', - contents='why is the sky blue?', -) - -print(response.text) -``` - - -## Models - -- By default, use the following models when using `google-genai`: - - **General Text & Multimodal Tasks:** `gemini-3-flash-preview` - - **Coding and Complex Reasoning Tasks:** `gemini-3-pro-preview` - - **Low Latency & High Volume Tasks:** `gemini-2.5-flash-lite` - - **Fast Image Generation and Editing:** `gemini-2.5-flash-image` (aka Nano Banana) - - **High-Quality Image Generation and Editing:** `gemini-3-pro-image-preview` (aka Nano Banana Pro) - - **High-Fidelity Video Generation:** `veo-3.0-generate-001` or `veo-3.1-generate-preview` - - **Fast Video Generation:** `veo-3.0-fast-generate-001` or `veo-3.1-fast-generate-preview` - - **Advanced Video Editing Tasks:** `veo-3.1-generate-preview` - -- It is also acceptable to use following models if explicitly requested by the - user: - - **Gemini 2.0 Series**: `gemini-2.0-flash`, `gemini-2.0-flash-lite` - - **Gemini 2.5 Series**: `gemini-2.5-flash`, `gemini-2.5-pro` - -- Do not use the following deprecated models (or their variants like - `gemini-1.5-flash-latest`): - - **Prohibited:** `gemini-1.5-flash` - - **Prohibited:** `gemini-1.5-pro` - - **Prohibited:** `gemini-pro` - -## Basic Inference (Text Generation) - -Here's how to generate a response from a text prompt. -Calls are stateless using the `client.models` accessor. - -```python -from google import genai - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents='Why is the sky blue?', -) - -print(response.text) # output is often markdown -``` - -## Multimodal Inputs - -Pass images directly as PIL objects, bytes, or file URIs. - -### Using PIL Images - -```python -from google import genai -from PIL import Image - -client = genai.Client() -image = Image.open('image.jpg') - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents=[image, 'Describe this image in detail.'], -) - -print(response.text) -``` - -### Using Bytes (Best for Web/API Backends) - -You can also use `Part.from_bytes` type to pass a variety of data types (images, -audio, video, pdf). - -```python -from google import genai -from google.genai import types - -client = genai.Client() - -with open('audio_sample.mp3', 'rb') as f: - audio_bytes = f.read() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents=[ - types.Part.from_bytes( - data=audio_bytes, - mime_type='audio/mp3', - ), - 'Transcribe this audio.' - ] -) -print(response.text) -``` - -### File API (For Large Files) - -For video files or long audio, upload to the File API first. - -```python -# Upload -my_file = client.files.upload(file='video.mp4') - -# Generate -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents=[my_file, 'What happens in this video?'] -) -print(response.text) - -# You can delete files after use like this: -client.files.delete(name=my_file.name) -``` - -## Advanced Capabilities - -### Thinking (Reasoning) - -Gemini 2.5 and 3 series models support explicit "thinking" for complex logic. - -#### Gemini 3 - -Thinking is on by default for `gemini-3-pro-preview` and `gemini-3-flash-preview`. -It can be adjusted by using the `thinking_level` parameter. - -- **`MINIMAL`:** (Gemini 3 Flash Only) Constrains the model to use as few tokens as possible for thinking and is best used for low-complexity tasks that wouldn't benefit from extensive reasoning. -- **`LOW`**: Constrains the model to use fewer tokens for thinking and is suitable for simpler tasks where extensive reasoning is not required. -- **`MEDIUM`**: (Gemini 3 Flash only) Offers a balanced approach suitable for tasks of moderate complexity that benefit from reasoning but don't require deep, multi-step planning. -- **`HIGH`**: (Default) Maximizes reasoning depth. The model may take significantly longer to reach a first token, but the output will be more thoroughly vetted. - -```python -from google import genai -from google.genai import types - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-pro-preview', - contents='What is AI?', - config=types.GenerateContentConfig( - thinking_config=types.ThinkingConfig( - thinking_level=types.ThinkingLevel.HIGH - ) - ) -) - -# Access thoughts if returned -for part in response.candidates[0].content.parts: - if part.thought: - print(f"Thought: {part.text}") - else: - print(f"Response: {part.text}") -``` - -#### Gemini 2.5 - -Thinking is on by default for -`gemini-2.5-pro` and `gemini-2.5-flash`. -It can be adjusted by using `thinking_budget` setting. -Setting it to zero turns thinking off, and will reduce latency. - -```python -from google import genai -from google.genai import types - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-2.5-pro', - contents='What is AI?', - config=types.GenerateContentConfig( - thinking_config=types.ThinkingConfig( - thinking_budget=0 - ) - ) -) - -# Access thoughts if returned -for part in response.candidates[0].content.parts: - if part.thought: - print(f"Thought: {part.text}") - else: - print(f"Response: {part.text}") -``` - -IMPORTANT NOTES: - -- Minimum thinking budget for `gemini-2.5-pro` is `128` and thinking can not - be turned off for that model. -- No models (apart from Gemini 2.5/3 series) support thinking or thinking - budgets APIs. Do not try to adjust thinking budgets for other models (such as - `gemini-2.0-flash` or `gemini-2.0-pro`), otherwise it will cause syntax - errors. - -### System Instructions - -Use system instructions to guide model's behavior. - -```python -from google import genai -from google.genai import types - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents='Explain quantum physics.', - config=types.GenerateContentConfig( - system_instruction='You are a pirate', - ) -) -print(response.text) -``` - -### Hyperparameters - -You can also set `temperature` or `max_output_tokens` within -`types.GenerateContentConfig` -**Avoid** setting `max_output_tokens`, `topP`, `topK` unless explicitly -requested by the user. - -### Safety configurations - -Avoid setting safety configurations unless explicitly requested by the user. If -explicitly asked for by the user, here is a sample API: - -```python -from google import genai -from google.genai import types -from PIL import Image - -client = genai.Client() - -img = Image.open('/path/to/img') -response = client.models.generate_content( - model='gemini-2.0-flash', - contents=['Do these look store-bought or homemade?', img], - config=types.GenerateContentConfig( - safety_settings=[ - types.SafetySetting( - category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH, - threshold=types.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, - ), - ] - ) -) - -print(response.text) -``` - -### Streaming - -Use `generate_content_stream` to reduce time-to-first-token. - -```python -from google import genai - -client = genai.Client() - -response = client.models.generate_content_stream( - model='gemini-3-flash-preview', - contents='Write a long story about a space pirate.' -) - -for chunk in response: - print(chunk.text, end='') -``` - -### Chat - -For multi-turn conversations, use the `chats` service to maintain conversation -history. - -```python -from google import genai - -client = genai.Client() -chat = client.chats.create(model='gemini-3-flash-preview') - -response1 = chat.send_message('I have a cat named Whiskers.') -print(response1.text) - -response2 = chat.send_message('What is the name of my pet?') -print(response2.text) - -# To access specific elements in chat history -for message in chat.get_history(): - print(f'role - {message.role}', end=': ') - print(message.parts[0].text) -``` - -### Structured Outputs (Pydantic) - -Enforce a specific JSON schema using standard Python type hints or Pydantic models. - -```python -from google import genai -from google.genai import types -from pydantic import BaseModel - -class Recipe(BaseModel): - name: str - description: str - ingredients: list[str] - steps: list[str] - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents='Provide a classic recipe for chocolate chip cookies.', - config=types.GenerateContentConfig( - response_mime_type='application/json', - response_json_schema=Recipe, - ), -) - -# response.text is guaranteed to be valid JSON matching the schema -print(response.text) - -# Access the response as a Pydantic object -recipe = Recipe.model_validate_json(response.text) -``` - -### Function Calling - -You can provide the model with tools (functions) it can use to bring in external -information to answer a question or act on a request outside the model. - -```python -from google import genai -from google.genai import types - -# Define a function that the model can call (to access external information) -def get_current_weather(city: str) -> str: - """Returns the current weather in a given city. For this example, it's hardcoded.""" - if 'boston' in city.lower(): - return 'The weather in Boston is 15°C and sunny.' - else: - return f'Weather data for {city} is not available.' - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents='What is the weather in Boston?', - config=types.GenerateContentConfig( - tools=[get_current_weather] # Make the function available to the model as a tool - - ), -) - -# The model may respond with a request to call the function -if response.function_calls: - print('Function calls requested by the model:') - for function_call in response.function_calls: - print(f'- Function: {function_call.name}') - print(f'- Args: {dict(function_call.args)}') -else: - print('The model responded directly:') - print(response.text) -``` - -### Grounding (Google Search) - -Connect the model to real-time web data. - -```python -from google import genai -from google.genai import types - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents='What was the score of the latest Olympique Lyonais game?', - config=types.GenerateContentConfig( - tools=[ - types.Tool(google_search=types.GoogleSearch()) - ] - ), -) - -print(response.text) -# Search details -print(f'Search Query: {response.candidates[0].grounding_metadata.web_search_queries}') -# Inspect grounding metadata -print(response.candidates[0].grounding_metadata.search_entry_point.rendered_content) -# Urls used for grounding -print(f"Search Pages: {', '.join([site.web.title for site in response.candidates[0].grounding_metadata.grounding_chunks])}") -``` - -The output `response.text` will likely not be in JSON format, do not attempt to -parse it as JSON. - -## Media Generation - -### Generate Images - -Here's how to generate images using the Nano Banana models. Start with the -Gemini 2.5 Flash Image (Nano Banana) model as it should cover most use-cases. - -```python -from google import genai -from google.genai import types -from PIL import Image - -prompt = "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme" - -client = genai.Client() - -response = client.models.generate_content( - model="gemini-2.5-flash-image", - contents=prompt, -) - -for part in response.parts: - if part.text is not None: - print(part.text) - elif part.inline_data is not None: - image = part.as_image() - image.save("generated_image.png") -``` - -Upgrade to the Gemini 3 Pro image (Nano Banana Pro) model if the user requests -high-resolution images or needs real-time information using the Google Search tool. - -```python -from google import genai -from google.genai import types -from PIL import Image - -prompt = "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day" -aspect_ratio = "16:9" # "1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9" -resolution = "1K" # "1K", "2K", "4K" - -client = genai.Client() - -response = client.models.generate_content( - model="gemini-3-pro-image-preview", - contents=prompt, - config=types.GenerateContentConfig( - image_config=types.ImageConfig( - aspect_ratio=aspect_ratio, - image_size=resolution - ), - # Optional - tools=[ - types.Tool(google_search=types.GoogleSearch()) - ] - ) -) - -for part in response.parts: - if part.text is not None: - print(part.text) - elif image:= part.as_image(): - image.save("weather.png") -``` - -### Edit images - -Editing images is better done using the Gemini native image generation model, -and it is recommended to use chat mode. Configs are not supported in this model -(except modality). - -```python -from google import genai -from PIL import Image -from io import BytesIO - -client = genai.Client() - -prompt = """ -Create a picture of my cat eating a nano-banana in a fancy restaurant under the gemini constellation -""" -image = Image.open('/path/to/image.png') - -# Create the chat -chat = client.chats.create(model='gemini-2.5-flash-image') -# Send the image and ask for it to be edited -response = chat.send_message([prompt, image]) - -# Get the text and the image generated -for i, part in enumerate(response.candidates[0].content.parts): - if part.text is not None: - print(part.text) - elif part.inline_data is not None: - image = part.as_image() - image.save(f'generated_image_{i}.png') # Multiple images can be generated - -# Continue iterating -chat.send_message('Can you make it a bananas foster?') -``` - -### Video Generation (Veo) - -Use the Veo models for video generation. Usage of Veo can be costly, -so after generating code for it, give user a heads up to check pricing for Veo. -Start with the fast model since the result quality is usually sufficient, and -swap to the larger model if needed. - -```python -import time -from google import genai -from google.genai import types -from PIL import Image - -client = genai.Client() - -image = Image.open('path/to/image.png') # Optional - -# Video generation is an async operation -operation = client.models.generate_videos( - model='veo-3.0-fast-generate-001', - prompt='Panning wide shot of a calico kitten sleeping in the sunshine', - image=image, - config=types.GenerateVideosConfig( - person_generation='dont_allow', # 'dont_allow' or 'allow_adult' - aspect_ratio='16:9', # '16:9' or '9:16' - number_of_videos=1, # supported value is 1-4, use 1 by default - duration_seconds=8, # supported value is 5-8 - ), -) - -# Poll for completion -while not operation.done: - time.sleep(20) - operation = client.operations.get(operation) - -for n, generated_video in enumerate(operation.response.generated_videos): - client.files.download(file=generated_video.video) # just file=, no need for path= as it doesn't save yet - generated_video.video.save(f'video{n}.mp4') # saves the video -``` - -## Content and Part Hierarchy - -While the simpler API call is often sufficient, you may run into scenarios where -you need to work directly with the underlying `Content` and `Part` objects for -more explicit control. These are the fundamental building blocks of the -`generate_content` API. - -For instance, the following simple API call: - -```python -from google import genai - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents='How does AI work?' -) -print(response.text) -``` - -is effectively a shorthand for this more explicit structure: - -```python -from google import genai -from google.genai import types - -client = genai.Client() - -response = client.models.generate_content( - model='gemini-3-flash-preview', - contents=[ - types.Content(role='user', parts=[types.Part.from_text(text='How does AI work?')]), - ] -) -print(response.text) -``` - -## Other APIs - -The list of APIs and capabilities above are not comprehensive. If users ask you -to generate code for a capability not provided above, refer them to -ai.google.dev/gemini-api/docs. - -## Useful Links - -- Documentation: ai.google.dev/gemini-api/docs -- API Keys and Authentication: ai.google.dev/gemini-api/docs/api-key -- Models: ai.google.dev/models -- API Pricing: ai.google.dev/pricing -- Rate Limits: ai.google.dev/gemini-api/docs/rate-limits diff --git a/docs/genai.html b/docs/genai.html index 97bbf522d..0a15c20c8 100644 --- a/docs/genai.html +++ b/docs/genai.html @@ -306,6 +306,11 @@

Submodules +
+property agents: AsyncAgentsResource
+
+
property auth_tokens: AsyncTokens
@@ -555,6 +560,11 @@

Submodules +
+property agents: AgentsResource
+

+
property aio: AsyncClient
@@ -2202,7 +2212,7 @@

Submodules
-create(*, api_version=None, input, model=<google.genai._interactions.Omit object>, background=<google.genai._interactions.Omit object>, generation_config=<google.genai._interactions.Omit object>, previous_interaction_id=<google.genai._interactions.Omit object>, response_format=<google.genai._interactions.Omit object>, response_mime_type=<google.genai._interactions.Omit object>, response_modalities=<google.genai._interactions.Omit object>, service_tier=<google.genai._interactions.Omit object>, store=<google.genai._interactions.Omit object>, stream=<google.genai._interactions.Omit object>, system_instruction=<google.genai._interactions.Omit object>, tools=<google.genai._interactions.Omit object>, webhook_config=<google.genai._interactions.Omit object>, agent=<google.genai._interactions.Omit object>, agent_config=<google.genai._interactions.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)
+create(*, api_version=None, input, model=<google.genai._interactions.Omit object>, background=<google.genai._interactions.Omit object>, environment=<google.genai._interactions.Omit object>, generation_config=<google.genai._interactions.Omit object>, previous_interaction_id=<google.genai._interactions.Omit object>, response_format=<google.genai._interactions.Omit object>, response_mime_type=<google.genai._interactions.Omit object>, response_modalities=<google.genai._interactions.Omit object>, service_tier=<google.genai._interactions.Omit object>, store=<google.genai._interactions.Omit object>, stream=<google.genai._interactions.Omit object>, system_instruction=<google.genai._interactions.Omit object>, tools=<google.genai._interactions.Omit object>, webhook_config=<google.genai._interactions.Omit object>, agent=<google.genai._interactions.Omit object>, agent_config=<google.genai._interactions.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)
Return type:

Union[Interaction, AsyncStream[Union[InteractionCreatedEvent, InteractionCompletedEvent, InteractionStatusUpdate, ErrorEvent, StepStart, StepDelta, StepStop]]]

@@ -2283,7 +2293,7 @@

Submodules
-create(*, api_version=None, input, model=<google.genai._interactions.Omit object>, background=<google.genai._interactions.Omit object>, generation_config=<google.genai._interactions.Omit object>, previous_interaction_id=<google.genai._interactions.Omit object>, response_format=<google.genai._interactions.Omit object>, response_mime_type=<google.genai._interactions.Omit object>, response_modalities=<google.genai._interactions.Omit object>, service_tier=<google.genai._interactions.Omit object>, store=<google.genai._interactions.Omit object>, stream=<google.genai._interactions.Omit object>, system_instruction=<google.genai._interactions.Omit object>, tools=<google.genai._interactions.Omit object>, webhook_config=<google.genai._interactions.Omit object>, agent=<google.genai._interactions.Omit object>, agent_config=<google.genai._interactions.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)
+create(*, api_version=None, input, model=<google.genai._interactions.Omit object>, background=<google.genai._interactions.Omit object>, environment=<google.genai._interactions.Omit object>, generation_config=<google.genai._interactions.Omit object>, previous_interaction_id=<google.genai._interactions.Omit object>, response_format=<google.genai._interactions.Omit object>, response_mime_type=<google.genai._interactions.Omit object>, response_modalities=<google.genai._interactions.Omit object>, service_tier=<google.genai._interactions.Omit object>, store=<google.genai._interactions.Omit object>, stream=<google.genai._interactions.Omit object>, system_instruction=<google.genai._interactions.Omit object>, tools=<google.genai._interactions.Omit object>, webhook_config=<google.genai._interactions.Omit object>, agent=<google.genai._interactions.Omit object>, agent_config=<google.genai._interactions.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)
Return type:

Union[Interaction, Stream[Union[InteractionCreatedEvent, InteractionCompletedEvent, InteractionStatusUpdate, ErrorEvent, StepStart, StepDelta, StepStop]]]

@@ -3869,7 +3879,7 @@

Submodulesuses=10, expire_time='2025-05-01T00:00:00Z', ) -auth_token = client.tokens.create(config=config) +auth_token = client.auth_tokens.create(config=config)
# Case 2: If LiveEphemeralParameters is set, lock all fields in
@@ -3877,7 +3887,7 @@ 

Submodules# example, changing `output_audio_transcription` in the Live API # connection will be ignored by the API. -auth_token = client.tokens.create( +auth_token = client.auth_tokens.create( config=types.CreateAuthTokenConfig( uses=10, live_constrained_parameters=types.LiveEphemeralParameters( @@ -3894,7 +3904,7 @@

Submodules# empty, lock LiveConnectConfig with set fields (e.g. # system_instruction in this example) when using the token in Live API # sessions. -auth_token = client.tokens.create( +auth_token = client.auth_tokens.create( config=types.CreateAuthTokenConfig( uses=10, live_constrained_parameters=types.LiveEphemeralParameters( @@ -3911,7 +3921,7 @@

Submodules# set, lock LiveConnectConfig with set and additional fields (e.g. # system_instruction, temperature in this example) when using the token # in Live API sessions. -auth_token = client.tokens.create( +auth_token = client.auth_tokens.create( config=types.CreateAuthTokenConfig( uses=10, live_constrained_parameters=types.LiveEphemeralParameters( @@ -3989,6 +3999,38 @@

Submodules +
+async validate_reward(*, parent, sample_response, example, single_reward_config=None, composite_reward_config=None, config=None)
+

Validates a reinforcement tuning reward configuration.

+

Allows users to validate a reinforcement tuning reward configuration +against a sample response and example before creating a reinforcement +tuning job, so that they can iterate on the reward configuration without +having to create a tuning job each time.

+
+
Return type:
+

ValidateRewardResponse

+
+
Parameters:
+
    +
  • parent – The resource name of the Location to validate the reward in, e.g. +projects/{project}/locations/{location}.

  • +
  • sample_response – The sample response for validating the reward +configuration.

  • +
  • example – The example to validate the reward configuration.

  • +
  • single_reward_config – Single reward function configuration for +reinforcement tuning. Mutually exclusive with composite_reward_config.

  • +
  • composite_reward_config – Composite reward function configuration for +reinforcement tuning. Mutually exclusive with single_reward_config.

  • +
  • config – Optional parameters for the request.

  • +
+
+
Returns:
+

A ValidateRewardResponse with the computed reward(s).

+
+
+

+

@@ -4048,6 +4090,38 @@

Submodules +
+validate_reward(*, parent, sample_response, example, single_reward_config=None, composite_reward_config=None, config=None)
+

Validates a reinforcement tuning reward configuration.

+

Allows users to validate a reinforcement tuning reward configuration +against a sample response and example before creating a reinforcement +tuning job, so that they can iterate on the reward configuration without +having to create a tuning job each time.

+
+
Return type:
+

ValidateRewardResponse

+
+
Parameters:
+
    +
  • parent – The resource name of the Location to validate the reward in, e.g. +projects/{project}/locations/{location}.

  • +
  • sample_response – The sample response for validating the reward +configuration.

  • +
  • example – The example to validate the reward configuration.

  • +
  • single_reward_config – Single reward function configuration for +reinforcement tuning. Mutually exclusive with composite_reward_config.

  • +
  • composite_reward_config – Composite reward function configuration for +reinforcement tuning. Mutually exclusive with single_reward_config.

  • +
  • config – Optional parameters for the request.

  • +
+
+
Returns:
+

A ValidateRewardResponse with the computed reward(s).

+
+
+

+

@@ -7805,7 +7879,7 @@

Submodules } ], "default": null, - "description": "Optional. The IANA standard MIME type of the response. The model will generate output that conforms to this MIME type. Supported values include 'text/plain' (default) and 'application/json'. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature.", + "description": "Optional. The IANA standard MIME type of the response. The model will generate output that conforms to this MIME type. Supported values include 'text/plain' (default) and 'application/json'. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined.", "title": "Responsemimetype" }, "responseModalities": { @@ -9388,7 +9462,7 @@

Submodules } ], "default": null, - "description": "The name of the BigQuery table created, in `predictions_<timestamp>` format, into which the prediction output is written.", + "description": "The name of the BigQuery table created, in `predictions_TIMESTAMP` format, into which the prediction output is written.", "title": "Bigqueryoutputtable" } }, @@ -9717,7 +9791,7 @@

Submodules }, "CodeExecutionResult": { "additionalProperties": false, - "description": "Result of executing the `ExecutableCode`.\n\nGenerated only when the `CodeExecution` tool is used.", + "description": "Result of executing the ExecutableCode.\n\nGenerated only when the `CodeExecution` tool is used.", "properties": { "outcome": { "anyOf": [ @@ -9754,7 +9828,7 @@

Submodules } ], "default": null, - "description": "The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id.", + "description": "Optional. The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -9930,7 +10004,7 @@

Submodules }, "ExecutableCode": { "additionalProperties": false, - "description": "Model-generated code executed server-side, results returned to the model.\n\nOnly generated when using the `CodeExecution` tool, in which the code will\nbe automatically executed, and a corresponding `CodeExecutionResult` will\nalso be generated.", + "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the `CodeExecution` tool, in which the code will be\nautomatically executed, and a corresponding CodeExecutionResult will also be\ngenerated.", "properties": { "code": { "anyOf": [ @@ -9967,7 +10041,7 @@

Submodules } ], "default": null, - "description": "Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`.", + "description": "Optional. Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -10047,7 +10121,7 @@

Submodules }, "FunctionCall": { "additionalProperties": false, - "description": "A function call.", + "description": "A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name and a structured JSON object containing the parameters and their values.", "properties": { "id": { "anyOf": [ @@ -10059,7 +10133,7 @@

Submodules } ], "default": null, - "description": "The unique id of the function call. If populated, the client to execute the\n `function_call` and return the response with the matching `id`.", + "description": "Optional. The unique id of the function call. If populated, the client to execute the `function_call` and return the response with the matching `id`.", "title": "Id" }, "args": { @@ -10073,7 +10147,7 @@

Submodules } ], "default": null, - "description": "Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.", + "description": "Optional. The function parameters and values in JSON object format. See FunctionDeclaration.parameters for parameter details.", "title": "Args" }, "name": { @@ -10086,7 +10160,7 @@

Submodules } ], "default": null, - "description": "Optional. The name of the function to call. Matches [FunctionDeclaration.name].", + "description": "Optional. The name of the function to call. Matches FunctionDeclaration.name.", "title": "Name" }, "partialArgs": { @@ -10124,7 +10198,7 @@

Submodules }, "FunctionResponse": { "additionalProperties": false, - "description": "A function response.", + "description": "The result output from a FunctionCall that contains a string representing the FunctionDeclaration.name and a structured JSON object containing any output from the function is used as context to the model.\n\nThis should contain the result of a `FunctionCall` made based on model\nprediction.", "properties": { "willContinue": { "anyOf": [ @@ -10136,7 +10210,7 @@

Submodules } ], "default": null, - "description": "Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls (see FunctionDeclaration.behavior for details), ignored otherwise. If false, the default, future responses will not be considered. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished.", + "description": "Optional. Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished. This may still trigger the model generation. To avoid triggering the generation and finish the function call, additionally set `scheduling` to `SILENT`. This field is not supported in Vertex AI.", "title": "Willcontinue" }, "scheduling": { @@ -10149,7 +10223,7 @@

Submodules } ], "default": null, - "description": "Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE." + "description": "Optional. Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE." }, "parts": { "anyOf": [ @@ -10164,7 +10238,7 @@

Submodules } ], "default": null, - "description": "List of parts that constitute a function response. Each part may\n have a different IANA MIME type.", + "description": "Optional. Ordered `Parts` that constitute a function response. Parts may have different IANA MIME types.", "title": "Parts" }, "id": { @@ -10190,7 +10264,7 @@

Submodules } ], "default": null, - "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].", + "description": "Required. The name of the function to call. Matches FunctionDeclaration.name and FunctionCall.name.", "title": "Name" }, "response": { @@ -10213,7 +10287,7 @@

Submodules }, "FunctionResponseBlob": { "additionalProperties": false, - "description": "Raw media bytes for function response.\n\nText should not be sent as raw bytes, use the FunctionResponse.response\nfield.", + "description": "Raw media bytes for function response.\n\nText should not be sent as raw bytes, use the 'text' field.", "properties": { "mimeType": { "anyOf": [ @@ -10239,7 +10313,7 @@

Submodules } ], "default": null, - "description": "Required. Inline media bytes.", + "description": "Required. Raw bytes.", "title": "Data" }, "displayName": { @@ -10252,7 +10326,7 @@

Submodules } ], "default": null, - "description": "Optional. Display name of the blob.\n Used to provide a label or filename to distinguish blobs.", + "description": "Optional. Display name of the blob. Used to provide a label or filename to distinguish blobs. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled. This field is not supported in Gemini API.", "title": "Displayname" } }, @@ -10261,7 +10335,7 @@

Submodules }, "FunctionResponseFileData": { "additionalProperties": false, - "description": "URI based data for function response.", + "description": "URI based data for function response.\n\nThis data type is not supported in Gemini API.", "properties": { "fileUri": { "anyOf": [ @@ -10299,7 +10373,7 @@

Submodules } ], "default": null, - "description": "Optional. Display name of the file.\n Used to provide a label or filename to distinguish files.", + "description": "Optional. Display name of the file data. Used to provide a label or filename to distinguish file datas. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.", "title": "Displayname" } }, @@ -10308,7 +10382,7 @@

Submodules }, "FunctionResponsePart": { "additionalProperties": false, - "description": "A datatype containing media that is part of a `FunctionResponse` message.\n\nA `FunctionResponsePart` consists of data which has an associated datatype. A\n`FunctionResponsePart` can only contain one of the accepted types in\n`FunctionResponsePart.data`.\n\nA `FunctionResponsePart` must have a fixed IANA MIME type identifying the\ntype and subtype of the media if the `inline_data` field is filled with raw\nbytes.", + "description": "A datatype containing media that is part of a `FunctionResponse` message.\n\nA `FunctionResponsePart` consists of data which has an associated datatype. A\n`FunctionResponsePart` can only contain one of the accepted types in\n`FunctionResponsePart.data`. A `FunctionResponsePart` must have a fixed IANA\nMIME type identifying the type and subtype of the media if the `inline_data`\nfield is filled with raw bytes.", "properties": { "inlineData": { "anyOf": [ @@ -10320,7 +10394,7 @@

Submodules } ], "default": null, - "description": "Optional. Inline media bytes." + "description": "Inline media bytes." }, "fileData": { "anyOf": [ @@ -10332,14 +10406,14 @@

Submodules } ], "default": null, - "description": "Optional. URI based data." + "description": "URI based data. This field is not supported in Gemini API." } }, "title": "FunctionResponsePart", "type": "object" }, "FunctionResponseScheduling": { - "description": "Specifies how the response should be scheduled in the conversation.", + "description": "Specifies how the response should be scheduled in the conversation.\n\nOnly applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults\nto WHEN_IDLE.", "enum": [ "SCHEDULING_UNSPECIFIED", "SILENT", @@ -11367,7 +11441,7 @@

Submodules } ], "default": null, - "description": "Optional. Page number of the retrieved context. This field is not supported in Vertex AI.", + "description": "Optional. Page number of the retrieved context, if applicable. This field is not supported in Vertex AI.", "title": "Pagenumber" }, "mediaId": { @@ -11380,7 +11454,7 @@

Submodules } ], "default": null, - "description": "Optional. Media ID. This field is not supported in Vertex AI.", + "description": "Optional. The media blob resource name for multimodal file search results. Format: fileSearchStores/{file_search_store_id}/media/{blob_id}. This field is not supported in Vertex AI.", "title": "Mediaid" } }, @@ -12550,6 +12624,32 @@

Submodules "default": null, "description": "The content of the chunk.", "title": "Text" + }, + "chunkId": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The ID of the chunk.", + "title": "Chunkid" + }, + "fileId": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The ID of the file that the chunk belongs to.", + "title": "Fileid" } }, "title": "RagChunk", @@ -13745,7 +13845,7 @@

Submodules }, "CodeExecutionResult": { "additionalProperties": false, - "description": "Result of executing the `ExecutableCode`.\n\nGenerated only when the `CodeExecution` tool is used.", + "description": "Result of executing the ExecutableCode.\n\nGenerated only when the `CodeExecution` tool is used.", "properties": { "outcome": { "anyOf": [ @@ -13782,7 +13882,7 @@

Submodules } ], "default": null, - "description": "The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id.", + "description": "Optional. The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -13898,7 +13998,7 @@

Submodules }, "ExecutableCode": { "additionalProperties": false, - "description": "Model-generated code executed server-side, results returned to the model.\n\nOnly generated when using the `CodeExecution` tool, in which the code will\nbe automatically executed, and a corresponding `CodeExecutionResult` will\nalso be generated.", + "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the `CodeExecution` tool, in which the code will be\nautomatically executed, and a corresponding CodeExecutionResult will also be\ngenerated.", "properties": { "code": { "anyOf": [ @@ -13935,7 +14035,7 @@

Submodules } ], "default": null, - "description": "Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`.", + "description": "Optional. Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -14015,7 +14115,7 @@

Submodules }, "FunctionCall": { "additionalProperties": false, - "description": "A function call.", + "description": "A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name and a structured JSON object containing the parameters and their values.", "properties": { "id": { "anyOf": [ @@ -14027,7 +14127,7 @@

Submodules } ], "default": null, - "description": "The unique id of the function call. If populated, the client to execute the\n `function_call` and return the response with the matching `id`.", + "description": "Optional. The unique id of the function call. If populated, the client to execute the `function_call` and return the response with the matching `id`.", "title": "Id" }, "args": { @@ -14041,7 +14141,7 @@

Submodules } ], "default": null, - "description": "Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.", + "description": "Optional. The function parameters and values in JSON object format. See FunctionDeclaration.parameters for parameter details.", "title": "Args" }, "name": { @@ -14054,7 +14154,7 @@

Submodules } ], "default": null, - "description": "Optional. The name of the function to call. Matches [FunctionDeclaration.name].", + "description": "Optional. The name of the function to call. Matches FunctionDeclaration.name.", "title": "Name" }, "partialArgs": { @@ -14092,7 +14192,7 @@

Submodules }, "FunctionResponse": { "additionalProperties": false, - "description": "A function response.", + "description": "The result output from a FunctionCall that contains a string representing the FunctionDeclaration.name and a structured JSON object containing any output from the function is used as context to the model.\n\nThis should contain the result of a `FunctionCall` made based on model\nprediction.", "properties": { "willContinue": { "anyOf": [ @@ -14104,7 +14204,7 @@

Submodules } ], "default": null, - "description": "Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls (see FunctionDeclaration.behavior for details), ignored otherwise. If false, the default, future responses will not be considered. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished.", + "description": "Optional. Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished. This may still trigger the model generation. To avoid triggering the generation and finish the function call, additionally set `scheduling` to `SILENT`. This field is not supported in Vertex AI.", "title": "Willcontinue" }, "scheduling": { @@ -14117,7 +14217,7 @@

Submodules } ], "default": null, - "description": "Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE." + "description": "Optional. Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE." }, "parts": { "anyOf": [ @@ -14132,7 +14232,7 @@

Submodules } ], "default": null, - "description": "List of parts that constitute a function response. Each part may\n have a different IANA MIME type.", + "description": "Optional. Ordered `Parts` that constitute a function response. Parts may have different IANA MIME types.", "title": "Parts" }, "id": { @@ -14158,7 +14258,7 @@

Submodules } ], "default": null, - "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].", + "description": "Required. The name of the function to call. Matches FunctionDeclaration.name and FunctionCall.name.", "title": "Name" }, "response": { @@ -14181,7 +14281,7 @@

Submodules }, "FunctionResponseBlob": { "additionalProperties": false, - "description": "Raw media bytes for function response.\n\nText should not be sent as raw bytes, use the FunctionResponse.response\nfield.", + "description": "Raw media bytes for function response.\n\nText should not be sent as raw bytes, use the 'text' field.", "properties": { "mimeType": { "anyOf": [ @@ -14207,7 +14307,7 @@

Submodules } ], "default": null, - "description": "Required. Inline media bytes.", + "description": "Required. Raw bytes.", "title": "Data" }, "displayName": { @@ -14220,7 +14320,7 @@

Submodules } ], "default": null, - "description": "Optional. Display name of the blob.\n Used to provide a label or filename to distinguish blobs.", + "description": "Optional. Display name of the blob. Used to provide a label or filename to distinguish blobs. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled. This field is not supported in Gemini API.", "title": "Displayname" } }, @@ -14229,7 +14329,7 @@

Submodules }, "FunctionResponseFileData": { "additionalProperties": false, - "description": "URI based data for function response.", + "description": "URI based data for function response.\n\nThis data type is not supported in Gemini API.", "properties": { "fileUri": { "anyOf": [ @@ -14267,7 +14367,7 @@

Submodules } ], "default": null, - "description": "Optional. Display name of the file.\n Used to provide a label or filename to distinguish files.", + "description": "Optional. Display name of the file data. Used to provide a label or filename to distinguish file datas. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.", "title": "Displayname" } }, @@ -14276,7 +14376,7 @@

Submodules }, "FunctionResponsePart": { "additionalProperties": false, - "description": "A datatype containing media that is part of a `FunctionResponse` message.\n\nA `FunctionResponsePart` consists of data which has an associated datatype. A\n`FunctionResponsePart` can only contain one of the accepted types in\n`FunctionResponsePart.data`.\n\nA `FunctionResponsePart` must have a fixed IANA MIME type identifying the\ntype and subtype of the media if the `inline_data` field is filled with raw\nbytes.", + "description": "A datatype containing media that is part of a `FunctionResponse` message.\n\nA `FunctionResponsePart` consists of data which has an associated datatype. A\n`FunctionResponsePart` can only contain one of the accepted types in\n`FunctionResponsePart.data`. A `FunctionResponsePart` must have a fixed IANA\nMIME type identifying the type and subtype of the media if the `inline_data`\nfield is filled with raw bytes.", "properties": { "inlineData": { "anyOf": [ @@ -14288,7 +14388,7 @@

Submodules } ], "default": null, - "description": "Optional. Inline media bytes." + "description": "Inline media bytes." }, "fileData": { "anyOf": [ @@ -14300,14 +14400,14 @@

Submodules } ], "default": null, - "description": "Optional. URI based data." + "description": "URI based data. This field is not supported in Gemini API." } }, "title": "FunctionResponsePart", "type": "object" }, "FunctionResponseScheduling": { - "description": "Specifies how the response should be scheduled in the conversation.", + "description": "Specifies how the response should be scheduled in the conversation.\n\nOnly applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults\nto WHEN_IDLE.", "enum": [ "SCHEDULING_UNSPECIFIED", "SILENT", @@ -15335,7 +15435,7 @@

Submodules } ], "default": null, - "description": "Optional. Page number of the retrieved context. This field is not supported in Vertex AI.", + "description": "Optional. Page number of the retrieved context, if applicable. This field is not supported in Vertex AI.", "title": "Pagenumber" }, "mediaId": { @@ -15348,7 +15448,7 @@

Submodules } ], "default": null, - "description": "Optional. Media ID. This field is not supported in Vertex AI.", + "description": "Optional. The media blob resource name for multimodal file search results. Format: fileSearchStores/{file_search_store_id}/media/{blob_id}. This field is not supported in Vertex AI.", "title": "Mediaid" } }, @@ -16499,6 +16599,32 @@

Submodules "default": null, "description": "The content of the chunk.", "title": "Text" + }, + "chunkId": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The ID of the chunk.", + "title": "Chunkid" + }, + "fileId": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The ID of the file that the chunk belongs to.", + "title": "Fileid" } }, "title": "RagChunk", @@ -17367,7 +17493,7 @@

Submodules } ], "default": null, - "description": "The name of the BigQuery table created, in `predictions_<timestamp>` format, into which the prediction output is written.", + "description": "The name of the BigQuery table created, in `predictions_TIMESTAMP` format, into which the prediction output is written.", "title": "Bigqueryoutputtable" } }, @@ -17389,7 +17515,7 @@

Submodules
field bigquery_output_table: Optional[str] = None (alias 'bigqueryOutputTable')
-

The name of the BigQuery table created, in predictions_<timestamp> format, into which the prediction output is written.

+

The name of the BigQuery table created, in predictions_TIMESTAMP format, into which the prediction output is written.

Validated by:
    @@ -17435,7 +17561,7 @@

    Submodules
    bigquery_output_table: Optional[str]
    -

    The name of the BigQuery table created, in predictions_<timestamp> format, into which the prediction output is written.

    +

    The name of the BigQuery table created, in predictions_TIMESTAMP format, into which the prediction output is written.

@@ -19234,7 +19360,7 @@

Submodules }, "CodeExecutionResult": { "additionalProperties": false, - "description": "Result of executing the `ExecutableCode`.\n\nGenerated only when the `CodeExecution` tool is used.", + "description": "Result of executing the ExecutableCode.\n\nGenerated only when the `CodeExecution` tool is used.", "properties": { "outcome": { "anyOf": [ @@ -19271,7 +19397,7 @@

Submodules } ], "default": null, - "description": "The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id.", + "description": "Optional. The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -19317,7 +19443,7 @@

Submodules }, "ExecutableCode": { "additionalProperties": false, - "description": "Model-generated code executed server-side, results returned to the model.\n\nOnly generated when using the `CodeExecution` tool, in which the code will\nbe automatically executed, and a corresponding `CodeExecutionResult` will\nalso be generated.", + "description": "Code generated by the model that is meant to be executed, and the result returned to the model.\n\nGenerated when using the `CodeExecution` tool, in which the code will be\nautomatically executed, and a corresponding CodeExecutionResult will also be\ngenerated.", "properties": { "code": { "anyOf": [ @@ -19354,7 +19480,7 @@

Submodules } ], "default": null, - "description": "Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`.", + "description": "Optional. Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -19434,7 +19560,7 @@

Submodules }, "FunctionCall": { "additionalProperties": false, - "description": "A function call.", + "description": "A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name and a structured JSON object containing the parameters and their values.", "properties": { "id": { "anyOf": [ @@ -19446,7 +19572,7 @@

Submodules } ], "default": null, - "description": "The unique id of the function call. If populated, the client to execute the\n `function_call` and return the response with the matching `id`.", + "description": "Optional. The unique id of the function call. If populated, the client to execute the `function_call` and return the response with the matching `id`.", "title": "Id" }, "args": { @@ -19460,7 +19586,7 @@

Submodules } ], "default": null, - "description": "Optional. The function parameters and values in JSON object format. See [FunctionDeclaration.parameters] for parameter details.", + "description": "Optional. The function parameters and values in JSON object format. See FunctionDeclaration.parameters for parameter details.", "title": "Args" }, "name": { @@ -19473,7 +19599,7 @@

Submodules } ], "default": null, - "description": "Optional. The name of the function to call. Matches [FunctionDeclaration.name].", + "description": "Optional. The name of the function to call. Matches FunctionDeclaration.name.", "title": "Name" }, "partialArgs": { @@ -19511,7 +19637,7 @@

Submodules }, "FunctionResponse": { "additionalProperties": false, - "description": "A function response.", + "description": "The result output from a FunctionCall that contains a string representing the FunctionDeclaration.name and a structured JSON object containing any output from the function is used as context to the model.\n\nThis should contain the result of a `FunctionCall` made based on model\nprediction.", "properties": { "willContinue": { "anyOf": [ @@ -19523,7 +19649,7 @@

Submodules } ], "default": null, - "description": "Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls (see FunctionDeclaration.behavior for details), ignored otherwise. If false, the default, future responses will not be considered. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished.", + "description": "Optional. Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished. This may still trigger the model generation. To avoid triggering the generation and finish the function call, additionally set `scheduling` to `SILENT`. This field is not supported in Vertex AI.", "title": "Willcontinue" }, "scheduling": { @@ -19536,7 +19662,7 @@

Submodules } ], "default": null, - "description": "Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE." + "description": "Optional. Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE." }, "parts": { "anyOf": [ @@ -19551,7 +19677,7 @@

Submodules } ], "default": null, - "description": "List of parts that constitute a function response. Each part may\n have a different IANA MIME type.", + "description": "Optional. Ordered `Parts` that constitute a function response. Parts may have different IANA MIME types.", "title": "Parts" }, "id": { @@ -19577,7 +19703,7 @@

Submodules } ], "default": null, - "description": "Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name].", + "description": "Required. The name of the function to call. Matches FunctionDeclaration.name and FunctionCall.name.", "title": "Name" }, "response": { @@ -19600,7 +19726,7 @@

Submodules }, "FunctionResponseBlob": { "additionalProperties": false, - "description": "Raw media bytes for function response.\n\nText should not be sent as raw bytes, use the FunctionResponse.response\nfield.", + "description": "Raw media bytes for function response.\n\nText should not be sent as raw bytes, use the 'text' field.", "properties": { "mimeType": { "anyOf": [ @@ -19626,7 +19752,7 @@

Submodules } ], "default": null, - "description": "Required. Inline media bytes.", + "description": "Required. Raw bytes.", "title": "Data" }, "displayName": { @@ -19639,7 +19765,7 @@

Submodules } ], "default": null, - "description": "Optional. Display name of the blob.\n Used to provide a label or filename to distinguish blobs.", + "description": "Optional. Display name of the blob. Used to provide a label or filename to distinguish blobs. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled. This field is not supported in Gemini API.", "title": "Displayname" } }, @@ -19648,7 +19774,7 @@

Submodules }, "FunctionResponseFileData": { "additionalProperties": false, - "description": "URI based data for function response.", + "description": "URI based data for function response.\n\nThis data type is not supported in Gemini API.", "properties": { "fileUri": { "anyOf": [ @@ -19686,7 +19812,7 @@

Submodules } ], "default": null, - "description": "Optional. Display name of the file.\n Used to provide a label or filename to distinguish files.", + "description": "Optional. Display name of the file data. Used to provide a label or filename to distinguish file datas. This field is only returned in PromptMessage for prompt management. It is currently used in the Gemini GenerateContent calls only when server side tools (code_execution, google_search, and url_context) are enabled.", "title": "Displayname" } }, @@ -19695,7 +19821,7 @@

Submodules }, "FunctionResponsePart": { "additionalProperties": false, - "description": "A datatype containing media that is part of a `FunctionResponse` message.\n\nA `FunctionResponsePart` consists of data which has an associated datatype. A\n`FunctionResponsePart` can only contain one of the accepted types in\n`FunctionResponsePart.data`.\n\nA `FunctionResponsePart` must have a fixed IANA MIME type identifying the\ntype and subtype of the media if the `inline_data` field is filled with raw\nbytes.", + "description": "A datatype containing media that is part of a `FunctionResponse` message.\n\nA `FunctionResponsePart` consists of data which has an associated datatype. A\n`FunctionResponsePart` can only contain one of the accepted types in\n`FunctionResponsePart.data`. A `FunctionResponsePart` must have a fixed IANA\nMIME type identifying the type and subtype of the media if the `inline_data`\nfield is filled with raw bytes.", "properties": { "inlineData": { "anyOf": [ @@ -19707,7 +19833,7 @@

Submodules } ], "default": null, - "description": "Optional. Inline media bytes." + "description": "Inline media bytes." }, "fileData": { "anyOf": [ @@ -19719,14 +19845,14 @@

Submodules } ], "default": null, - "description": "Optional. URI based data." + "description": "URI based data. This field is not supported in Gemini API." } }, "title": "FunctionResponsePart", "type": "object" }, "FunctionResponseScheduling": { - "description": "Specifies how the response should be scheduled in the conversation.", + "description": "Specifies how the response should be scheduled in the conversation.\n\nOnly applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults\nto WHEN_IDLE.", "enum": [ "SCHEDULING_UNSPECIFIED", "SILENT", @@ -20394,7 +20520,7 @@

Submodules } ], "default": null, - "description": "Optional. Page number of the retrieved context. This field is not supported in Vertex AI.", + "description": "Optional. Page number of the retrieved context, if applicable. This field is not supported in Vertex AI.", "title": "Pagenumber" }, "mediaId": { @@ -20407,7 +20533,7 @@

Submodules } ], "default": null, - "description": "Optional. Media ID. This field is not supported in Vertex AI.", + "description": "Optional. The media blob resource name for multimodal file search results. Format: fileSearchStores/{file_search_store_id}/media/{blob_id}. This field is not supported in Vertex AI.", "title": "Mediaid" } }, @@ -21269,6 +21395,32 @@

Submodules "default": null, "description": "The content of the chunk.", "title": "Text" + }, + "chunkId": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The ID of the chunk.", + "title": "Chunkid" + }, + "fileId": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The ID of the file that the chunk belongs to.", + "title": "Fileid" } }, "title": "RagChunk", @@ -22733,7 +22885,7 @@

Submodules pydantic model genai.types.CodeExecutionResult

Bases: BaseModel

-

Result of executing the ExecutableCode.

+

Result of executing the ExecutableCode.

Generated only when the CodeExecution tool is used.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be @@ -22742,7 +22894,7 @@

Submodules Show JSON schema
{
    "title": "CodeExecutionResult",
-   "description": "Result of executing the `ExecutableCode`.\n\nGenerated only when the `CodeExecution` tool is used.",
+   "description": "Result of executing the ExecutableCode.\n\nGenerated only when the `CodeExecution` tool is used.",
    "type": "object",
    "properties": {
       "outcome": {
@@ -22780,7 +22932,7 @@ 

Submodules } ], "default": null, - "description": "The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id.", + "description": "Optional. The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id. This field is not supported in Vertex AI.", "title": "Id" } }, @@ -22815,7 +22967,7 @@

Submodules
field id: Optional[str] = None
-

The identifier of the ExecutableCode part this result is for. Only populated if the corresponding ExecutableCode has an id.

+

Optional. The identifier of the ExecutableCode part this result is for. Only populated if the corresponding ExecutableCode has an id. This field is not supported in Vertex AI.

Validated by:

+
+

+
Fields:
+
+
+
Validators:
+

+
+
+
+field base_teacher_model: Optional[str] = None (alias 'baseTeacherModel')
+

The base teacher model that is being distilled. See [Supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/tuning#supported_models).

Validated by: