fix(genai): support Vertex AI multiregion endpoints#1816
Open
Diego Fernández Gil (diefergil) wants to merge 1 commit into
Open
fix(genai): support Vertex AI multiregion endpoints#1816Diego Fernández Gil (diefergil) wants to merge 1 commit into
Diego Fernández Gil (diefergil) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds automatic resolution of the Vertex AI multiregion (us, eu) REP endpoint when no custom base_url is provided, by extracting the base URL resolution logic into a shared _resolve_base_url helper used by both ChatGoogleGenerativeAI and GoogleGenerativeAIEmbeddings.
Changes:
- Introduce
_resolve_base_urlhelper in_common.pythat handles legacy dict-styleclient_optionsand mapsus/euVertex locations to theaiplatform.{location}.rep.googleapis.comendpoint. - Refactor
chat_models.pyandembeddings.pyto use the shared helper. - Add unit tests covering multiregion endpoint resolution and custom
base_urlpreservation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/genai/langchain_google_genai/_common.py | Adds _resolve_base_url helper and multiregion URL mapping; updates docstring. |
| libs/genai/langchain_google_genai/chat_models.py | Replaces inline base_url parsing with the shared helper. |
| libs/genai/langchain_google_genai/embeddings.py | Uses the shared helper to resolve the base URL passed to HttpOptions. |
| libs/genai/tests/unit_tests/test_chat_models.py | Adds tests for multiregion endpoint and custom base URL preservation. |
| libs/genai/tests/unit_tests/test_embeddings.py | Adds parallel tests for the embeddings client. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+37
to
+42
| def _resolve_base_url( | ||
| base_url: str | dict | None, | ||
| *, | ||
| use_vertexai: bool, | ||
| location: str | None, | ||
| ) -> str | None: |
|
|
||
|
|
||
| def _resolve_base_url( | ||
| base_url: str | dict | None, |
Comment on lines
+203
to
+211
| def test_vertexai_multiregion_location_preserves_custom_base_url() -> None: | ||
| with patch("langchain_google_genai.embeddings.Client") as mock_client: | ||
| GoogleGenerativeAIEmbeddings( | ||
| model=MODEL_NAME, | ||
| vertexai=True, | ||
| project="test-project", | ||
| location="eu", | ||
| base_url="https://gateway.example.com/api/gemini", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Support Vertex AI multiregion locations in
langchain-google-genaiby resolvinglocation="us"andlocation="eu"to the Google mREP hostnames when no custombase_urlis provided.This keeps explicit
base_url/ legacyclient_options={"api_endpoint": ...}behavior intact, while avoiding the SDK's regional hostname pattern for multiregion locations.Relevant issues
Fixes #1799
Type
🐛 Bug Fix
✅ Test
Changes(optional)
usandeumREP endpoint selection and custombase_urlprecedence.Testing(optional)
uv run --group test pytest tests/unit_tests/test_chat_models.py::test_vertexai_multiregion_location_uses_rep_endpoint tests/unit_tests/test_chat_models.py::test_vertexai_multiregion_location_preserves_custom_base_url tests/unit_tests/test_embeddings.py::test_vertexai_multiregion_location_uses_rep_endpoint tests/unit_tests/test_embeddings.py::test_vertexai_multiregion_location_preserves_custom_base_urluv run --group test pytest tests/unit_tests/test_chat_models.py tests/unit_tests/test_embeddings.pyuv run --group lint ruff check langchain_google_genai/_common.py langchain_google_genai/chat_models.py langchain_google_genai/embeddings.py tests/unit_tests/test_chat_models.py tests/unit_tests/test_embeddings.pyuv run --group typing mypy langchain_google_genaiNote(optional)
This contribution was prepared with assistance from an AI coding agent; the changes and test results were reviewed before submission.