Skip to content

fix(py/google-genai): omit default location in Vertex AI express mode - #7099

Closed
huangjeff5 wants to merge 1 commit into
mainfrom
fix/py-vertexai-express-location
Closed

huangjeff5 wants to merge 1 commit into
mainfrom
fix/py-vertexai-express-location

Conversation

@huangjeff5

Copy link
Copy Markdown
Contributor

Problem

In Vertex AI Express mode (VertexAI(api_key=...) without a GCP project), VertexAI.__init__ previously defaulted self._location to 'us-central1' when no explicit location or environment variable was set. Passing location='us-central1' alongside api_key=... causes the Google GenAI client to target regional endpoints (https://us-central1-aiplatform.googleapis.com/) and generate resource URLs with projects/None/locations/us-central1, causing Express Mode requests to fail.

Mechanism

In VertexAI.__init__, default self._location to const.DEFAULT_REGION only when not in Express Mode (api_key and not self._project). When initializing Express Mode without an explicit location, self._location is None, allowing genai.Client to default to the global express endpoint (https://aiplatform.googleapis.com/).

Verification

  • Added test_api_key_omits_default_location in packages/genkit-google-genai/tests/vertexai_location_test.py verifying that VertexAI(api_key='k') leaves location unset.
  • Ran pytest packages/genkit-google-genai (1518 passed).
  • Verified ruff check, ruff format, and pyright clean.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the VertexAI plugin to omit the default region when in express mode (i.e., when an api_key is provided and no project is set). It also ensures that calls to create_vertex_evaluators fallback to the default region if the location is unset, and adds a unit test to verify this behavior. I have no feedback to provide as there are no review comments.

@huangjeff5

Copy link
Copy Markdown
Contributor Author

Closing: migrated to standalone repository genkit-ai/genkit-python (PR #36): genkit-ai/genkit-python#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant