This commit is contained in:
Paul Merlin 2026-09-03 20:34:04 +00:00 committed by GitHub
commit 672f11d06e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 37 additions and 22 deletions

View file

@ -104,19 +104,8 @@ class VertexBase:
supported_regions: Final = model_info.get("supported_regions")
if supported_regions and len(supported_regions) > 0:
# If user didn't specify region, use the first supported region
if vertex_region is None:
return supported_regions[0]
# If user specified a region not supported by this model, override it
if vertex_region not in supported_regions:
verbose_logger.warning(
"Vertex AI model '%s' does not support region '%s' (supported: %s). Routing to '%s'.",
model,
vertex_region,
supported_regions,
supported_regions[0],
)
return supported_regions[0]
return vertex_region
return vertex_region or "us-central1"

View file

@ -23499,6 +23499,11 @@
"supported_output_modalities": [
"text"
],
"supported_regions": [
"global",
"us",
"eu"
],
"supports_audio_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,

View file

@ -23499,6 +23499,11 @@
"supported_output_modalities": [
"text"
],
"supported_regions": [
"global",
"us",
"eu"
],
"supports_audio_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,

View file

@ -664,10 +664,8 @@ def test_get_vertex_url_global_region(stream, expected_endpoint_suffix):
[
# Model with supported_regions=["global"], no user region -> use "global"
({"supported_regions": ["global"]}, None, "global"),
# Model with supported_regions=["global"], user passes unsupported region -> override to "global"
({"supported_regions": ["global"]}, "us-central1", "global"),
# Model with supported_regions=["global"], user passes unsupported region -> override to "global"
({"supported_regions": ["global"]}, "europe-west1", "global"),
({"supported_regions": ["global"]}, "us-central1", "us-central1"),
({"supported_regions": ["global"]}, "europe-west1", "europe-west1"),
# Model with supported_regions=["us-west2"], no user region -> use "us-west2"
({"supported_regions": ["us-west2"]}, None, "us-west2"),
# Model with supported_regions=["us-west2", "us-central1"], user passes supported region -> respect it
@ -676,11 +674,10 @@ def test_get_vertex_url_global_region(stream, expected_endpoint_suffix):
"us-central1",
"us-central1",
),
# Model with supported_regions=["us-west2", "us-central1"], user passes unsupported region -> override
(
{"supported_regions": ["us-west2", "us-central1"]},
"europe-west1",
"us-west2",
"europe-west1",
),
# No model_cost entry, no user region -> default us-central1
({}, None, "us-central1"),
@ -711,6 +708,25 @@ def test_get_vertex_region_global_only_model(
assert result == expected_region
@pytest.mark.parametrize(
"vertex_region, expected_region",
[
(None, "global"),
("global", "global"),
("us", "us"),
("eu", "eu"),
("us-central1", "us-central1"),
],
)
def test_get_vertex_region_gemini_3_7_flash(vertex_region, expected_region):
from litellm.llms.vertex_ai.vertex_llm_base import VertexBase
assert (
VertexBase.get_vertex_region(vertex_region=vertex_region, model="gemini-3.7-flash")
== expected_region
)
def test_vertex_filter_format_uri():
import json

View file

@ -105,7 +105,7 @@ class TestVertexBaseGetVertexRegionGemma:
)
assert result == "global"
def test_global_model_with_unsupported_user_region_overrides(self):
def test_global_model_preserves_explicit_user_region(self):
vertex_base = VertexBase()
with patch.dict(
@ -121,7 +121,7 @@ class TestVertexBaseGetVertexRegionGemma:
vertex_region="us-central1",
model="google/gemma-4-26b-a4b-it-maas",
)
assert result == "global"
assert result == "us-central1"
class TestCreateVertexURLGemma:

View file

@ -64,8 +64,8 @@ class TestVertexBaseGetVertexRegion:
)
assert result == "global"
def test_global_model_with_unsupported_user_region_overrides(self):
"""Test that unsupported user region is overridden for global-only models."""
def test_global_model_preserves_explicit_user_region(self):
"""Test that an explicit user region is not silently broadened."""
vertex_base = VertexBase()
with patch.dict(
@ -81,7 +81,7 @@ class TestVertexBaseGetVertexRegion:
vertex_region="us-central1",
model="qwen/qwen3-next-80b-a3b-instruct-maas",
)
assert result == "global"
assert result == "us-central1"
def test_non_global_model_uses_provided_region(self):
"""Test that non-global models use the provided region."""