mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix: Improve Azure auth parameter handling for None values (#14436)
* fix: Improve Azure auth parameter handling for None values Previously, litellm_params.get() with default fallbacks could ignore environment variables when the param existed but was None. Now explicitly checks for None values before falling back to environment variables. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix lint --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
This commit is contained in:
parent
48579f7539
commit
f4a5196728
1 changed files with 23 additions and 15 deletions
|
|
@ -500,23 +500,18 @@ class BaseAzureLLM(BaseOpenAILLM):
|
|||
azure_ad_token_provider = litellm_params.get("azure_ad_token_provider")
|
||||
# If we have api_key, then we have higher priority
|
||||
azure_ad_token = litellm_params.get("azure_ad_token")
|
||||
tenant_id = litellm_params.get("tenant_id", os.getenv("AZURE_TENANT_ID"))
|
||||
client_id = litellm_params.get("client_id", os.getenv("AZURE_CLIENT_ID"))
|
||||
client_secret = litellm_params.get(
|
||||
"client_secret", os.getenv("AZURE_CLIENT_SECRET")
|
||||
)
|
||||
azure_username = litellm_params.get(
|
||||
"azure_username", os.getenv("AZURE_USERNAME")
|
||||
)
|
||||
azure_password = litellm_params.get(
|
||||
"azure_password", os.getenv("AZURE_PASSWORD")
|
||||
)
|
||||
scope = litellm_params.get(
|
||||
"azure_scope",
|
||||
os.getenv("AZURE_SCOPE", "https://cognitiveservices.azure.com/.default"),
|
||||
)
|
||||
|
||||
# litellm_params sometimes contains the key, but the value is None
|
||||
# We should respect environment variables in this case
|
||||
tenant_id = self._resolve_env_var(litellm_params, "tenant_id", "AZURE_TENANT_ID")
|
||||
client_id = self._resolve_env_var(litellm_params, "client_id", "AZURE_CLIENT_ID")
|
||||
client_secret = self._resolve_env_var(litellm_params, "client_secret", "AZURE_CLIENT_SECRET")
|
||||
azure_username = self._resolve_env_var(litellm_params, "azure_username", "AZURE_USERNAME")
|
||||
azure_password = self._resolve_env_var(litellm_params, "azure_password", "AZURE_PASSWORD")
|
||||
scope = self._resolve_env_var(litellm_params, "azure_scope", "AZURE_SCOPE")
|
||||
if scope is None:
|
||||
scope = "https://cognitiveservices.azure.com/.default"
|
||||
|
||||
max_retries = litellm_params.get("max_retries")
|
||||
timeout = litellm_params.get("timeout")
|
||||
if (
|
||||
|
|
@ -760,3 +755,16 @@ class BaseAzureLLM(BaseOpenAILLM):
|
|||
if api_version is None:
|
||||
return False
|
||||
return api_version in {"preview", "latest", "v1"}
|
||||
|
||||
def _resolve_env_var(self, litellm_params: Dict[str, Any], param_key: str, env_var_key: str) -> Optional[str]:
|
||||
"""Resolve the environment variable for a given parameter key.
|
||||
|
||||
The logic here is different from `params.get(key, os.getenv(env_var))` because
|
||||
litellm_params may contain the key with a None value, in which case we want
|
||||
to fallback to the environment variable.
|
||||
"""
|
||||
param_value = litellm_params.get(param_key)
|
||||
if param_value is not None:
|
||||
return param_value
|
||||
return os.getenv(env_var_key)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue