forked from phoenix/litellm-mirror
feat(router.py): enable filtering model group by 'allowed_model_region'
This commit is contained in:
parent
db666b01e5
commit
3d18897d69
11 changed files with 417 additions and 35 deletions
|
@ -5844,6 +5844,40 @@ def calculate_max_parallel_requests(
|
|||
return None
|
||||
|
||||
|
||||
def _is_region_eu(model_region: str) -> bool:
|
||||
EU_Regions = ["europe", "sweden", "switzerland", "france", "uk"]
|
||||
for region in EU_Regions:
|
||||
if "europe" in model_region.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_model_region(
|
||||
litellm_params: LiteLLM_Params, mode: Optional[str]
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Pass the litellm params for an azure model, and get back the region
|
||||
"""
|
||||
if (
|
||||
"azure" in litellm_params.model
|
||||
and isinstance(litellm_params.api_key, str)
|
||||
and isinstance(litellm_params.api_base, str)
|
||||
):
|
||||
_model = litellm_params.model.replace("azure/", "")
|
||||
response: dict = litellm.AzureChatCompletion().get_headers(
|
||||
model=_model,
|
||||
api_key=litellm_params.api_key,
|
||||
api_base=litellm_params.api_base,
|
||||
api_version=litellm_params.api_version or "2023-07-01-preview",
|
||||
timeout=10,
|
||||
mode=mode or "chat",
|
||||
)
|
||||
|
||||
region: Optional[str] = response.get("x-ms-region", None)
|
||||
return region
|
||||
return None
|
||||
|
||||
|
||||
def get_api_base(model: str, optional_params: dict) -> Optional[str]:
|
||||
"""
|
||||
Returns the api base used for calling the model.
|
||||
|
@ -9423,7 +9457,9 @@ def get_secret(
|
|||
else:
|
||||
secret = os.environ.get(secret_name)
|
||||
try:
|
||||
secret_value_as_bool = ast.literal_eval(secret) if secret is not None else None
|
||||
secret_value_as_bool = (
|
||||
ast.literal_eval(secret) if secret is not None else None
|
||||
)
|
||||
if isinstance(secret_value_as_bool, bool):
|
||||
return secret_value_as_bool
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue