-
Notifications
You must be signed in to change notification settings - Fork 928
Fix: Force VERTEXAI_LOCATION for Gemini 2.5 on Vertex AI #1857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Force VERTEXAI_LOCATION for Gemini 2.5 on Vertex AI #1857
Conversation
…Vertex For certain models on Vertex AI, specifically the new Gemini 2.5 Pro Preview (e.g., gemini-2.5-pro-preview-06-05), the VERTEXAI_LOCATION must be set to "global" for the model to function correctly. This change modifies the LiteLLMAIHandler to automatically set litellm.vertex_location and the environment variable VERTEXAI_LOCATION to "global" when such a model is selected and the provider is Vertex AI. This ensures you can use these models without manual configuration or encountering "Publisher Model not found" errors. Addresses the issue highlighted in the discussion around BerriAI/litellm#11447, where users confirmed that os.environ["VERTEXAI_LOCATION"] = "global" resolves the problem.
This commit refines the handling of Vertex AI model locations. Specifically, it ensures that when `gemini-2.5-pro-preview-0605` is used on Vertex AI, the `litellm.vertex_location` and the environment variable `VERTEXAI_LOCATION` are explicitly set to "global". This is necessary because, as per Google's official documentation (https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions), the `gemini-2.5-pro-preview-0605` model is only available in the 'global' location. This change prevents "Publisher Model not found" errors for this specific model. This commit supersedes a previous attempt that had a broader condition and ensures the fix is targeted precisely as per your feedback and documentation.
This commit correctly sets the VERTEXAI_LOCATION to "global" for the Vertex AI model `gemini-2.5-pro-preview-06-05` (with hyphen). The model name `gemini-2.5-pro-preview-06-05` is used as specified in Google's official documentation: https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/2-5-pro This ensures that when this specific model is used, `litellm.vertex_location` and the environment variable `VERTEXAI_LOCATION` are explicitly set to "global", preventing "Publisher Model not found" errors. This commit supersedes previous attempts which either had a too broad condition or used an incorrect model name format (without hyphen). The logic now accurately targets the specified model.
This commit implements specific location handling for two Vertex AI Gemini models: 1. `gemini-2.5-pro-preview-06-05`: - As per Google's documentation, this model is available in the 'global' location. - This change forces `litellm.vertex_location` and the `VERTEXAI_LOCATION` environment variable to "global" when this model is used, overriding other settings to prevent errors. 2. `gemini-2.5-flash-preview-05-20`: - This model is available in specific regions, including `us-central1` for the US, but not all US regions (e.g., not `us-east1` or `us-west1`). - If this model is selected and you have configured a US-based `VERTEXAI_LOCATION` other than `us-central1`, this change automatically corrects the location to `us-central1`. - This helps prevent errors when you inadvertently select an unsupported US region for this model. Both model names are checked with hyphens (e.g., "06-05") as per primary Google documentation. This consolidated fix addresses issues discussed regarding model availability and required location settings on Vertex AI.
This commit implements the definitive specific location handling for two Vertex AI Gemini models, based on your detailed feedback and my investigation: 1. `gemini-2.5-pro-preview-06-05`: - This model requires the 'global' location on Vertex AI. - This change forces `litellm.vertex_location` and the `VERTEXAI_LOCATION` environment variable to "global" when this model is used, overriding other settings. 2. `gemini-2.5-flash-preview-05-20`: - If a US-based `VERTEXAI_LOCATION` (e.g., "us-east1") other than "us-central1" is configured by you, it is automatically corrected to "us-central1". - If any non-US `VERTEXAI_LOCATION` is configured by you and it's not already "global", it is set to "global". - This logic addresses the model's specific availability constraints as per your provided information (US only in us-central1, others via global). Both model names are checked with hyphens (e.g., "06-05") and comparisons are case-insensitive. Appropriate logging is added for when location overrides occur. This commit supersedes all previous attempts and incorporates the most up-to-date understanding of these models' location requirements.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Should not do this here 😅 |
User description
Fix Vertex AI location handling for specific Gemini models
Automatically set appropriate VERTEXAI_LOCATION for two Gemini models:
model is only available globally on Vertex AI
or "global" for non-US regions based on model availability constraints
This prevents "Publisher Model not found" errors by overriding user
configuration when necessary. Both litellm.vertex_location and
VERTEXAI_LOCATION environment variable are updated automatically.
Addresses issues discussed in BerriAI/litellm#11447 where manual
location configuration was required for these specific models.
Summary from GitHub Copilot:
cc #11447
PR Type
Bug fix, Enhancement
Description
Adds automatic Vertex AI location override for Gemini 2.5 models.
VERTEXAI_LOCATION
toglobal
forgemini-2.5-pro-preview-06-05
.VERTEXAI_LOCATION
tous-central1
orglobal
forgemini-2.5-flash-preview-05-20
as needed.Updates both
litellm.vertex_location
and environment variable for compatibility.Improves logging to inform users of location overrides.
Changes diagram
Changes walkthrough 📝
litellm_ai_handler.py
Auto-detect and override Vertex AI location for Gemini 2.5 models
pr_agent/algo/ai_handlers/litellm_ai_handler.py
litellm.vertex_location
andVERTEXAI_LOCATION
asrequired.