refactor(vertex_ai): reuse get_vertex_base_url for URL construction

Use existing get_vertex_base_url from common_utils instead of duplicating
the global vs regional URL logic in create_vertex_url and get_api_base.
This commit is contained in:
Chesars 2026-01-30 14:39:13 -03:00
parent 535fcdfad5
commit 6d28228245

View file

@ -20,6 +20,7 @@ from .common_utils import (
_get_vertex_url,
all_gemini_url_modes,
get_vertex_base_model_name,
get_vertex_base_url,
is_global_only_vertex_model,
)
@ -200,12 +201,7 @@ class VertexBase:
) -> str:
if api_base:
return api_base
elif vertex_location == "global":
return "https://aiplatform.googleapis.com"
elif vertex_location:
return f"https://{vertex_location}-aiplatform.googleapis.com"
else:
return f"https://{self.get_default_vertex_location()}-aiplatform.googleapis.com"
return get_vertex_base_url(vertex_location or self.get_default_vertex_location())
@staticmethod
def create_vertex_url(
@ -218,12 +214,8 @@ class VertexBase:
) -> str:
"""Return the base url for the vertex partner models"""
# For global location, use the non-regional URL
if api_base is None:
if vertex_location == "global":
api_base = "https://aiplatform.googleapis.com"
else:
api_base = f"https://{vertex_location}-aiplatform.googleapis.com"
api_base = get_vertex_base_url(vertex_location)
if partner == VertexPartnerProvider.llama:
return f"{api_base}/v1/projects/{vertex_project}/locations/{vertex_location}/endpoints/openapi/chat/completions"
elif partner == VertexPartnerProvider.mistralai: