mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix(vertex_ai): auto-resolve vertex_location from supported_regions
- Add call to get_vertex_region() in partner models to auto-detect region - Improve get_vertex_region() to read supported_regions from model_cost - User-specified vertex_location still takes priority
This commit is contained in:
parent
c63b7965bd
commit
c723d63e59
2 changed files with 19 additions and 2 deletions
|
|
@ -161,6 +161,11 @@ class VertexAIPartnerModels(VertexBase):
|
|||
else:
|
||||
raise ValueError(f"Unknown partner model: {model}")
|
||||
|
||||
# Resolve vertex_location based on model's supported_regions
|
||||
vertex_location = self.get_vertex_region(
|
||||
vertex_region=vertex_location, model=model
|
||||
)
|
||||
|
||||
api_base = self.get_complete_vertex_url(
|
||||
custom_api_base=api_base,
|
||||
vertex_location=vertex_location,
|
||||
|
|
|
|||
|
|
@ -49,8 +49,20 @@ class VertexBase:
|
|||
self.async_handler: Optional[AsyncHTTPHandler] = None
|
||||
|
||||
def get_vertex_region(self, vertex_region: Optional[str], model: str) -> str:
|
||||
if is_global_only_vertex_model(model):
|
||||
return "global"
|
||||
import litellm
|
||||
|
||||
# Try to get supported_regions directly from model_cost
|
||||
# Check both with and without vertex_ai/ prefix
|
||||
model_key = f"vertex_ai/{model}" if not model.startswith("vertex_ai/") else model
|
||||
model_info = litellm.model_cost.get(model_key, {})
|
||||
supported_regions = 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, trust them
|
||||
return vertex_region
|
||||
return vertex_region or "us-central1"
|
||||
|
||||
def load_auth(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue