mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
Merge pull request #40464 from BerriAI/litellm_internal_copy_35771
fix(azure): respect DEFAULT_MAX_RETRIES in initialize_azure_sdk_client (internal copy of #35771)
This commit is contained in:
commit
b22ca7ac6d
2 changed files with 56 additions and 3 deletions
|
|
@ -14,6 +14,7 @@ from typing_extensions import ReadOnly, TypedDict
|
|||
import litellm
|
||||
from litellm._logging import verbose_logger
|
||||
from litellm.caching.caching import DualCache
|
||||
from litellm.constants import DEFAULT_MAX_RETRIES
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.llms.openai.common_utils import BaseOpenAILLM
|
||||
from litellm.secret_managers.get_azure_ad_token_provider import (
|
||||
|
|
@ -582,7 +583,8 @@ class BaseAzureLLM(BaseOpenAILLM):
|
|||
if scope is None:
|
||||
scope = "https://cognitiveservices.azure.com/.default"
|
||||
|
||||
max_retries: Final = litellm_params.get("max_retries")
|
||||
configured_max_retries: Final = litellm_params.get("max_retries")
|
||||
max_retries: Final = DEFAULT_MAX_RETRIES if configured_max_retries is None else configured_max_retries
|
||||
timeout: Final = litellm_params.get("timeout")
|
||||
if not api_key and azure_ad_token_provider is None and tenant_id and client_id and client_secret:
|
||||
verbose_logger.debug("Using Azure AD Token Provider from Entra ID for Azure Auth")
|
||||
|
|
@ -642,8 +644,7 @@ class BaseAzureLLM(BaseOpenAILLM):
|
|||
else:
|
||||
azure_client_params["http_client"] = self._get_sync_http_client()
|
||||
|
||||
if max_retries is not None:
|
||||
azure_client_params["max_retries"] = max_retries
|
||||
azure_client_params["max_retries"] = max_retries
|
||||
if timeout is not None:
|
||||
azure_client_params["timeout"] = timeout
|
||||
|
||||
|
|
|
|||
|
|
@ -385,6 +385,58 @@ def test_select_azure_base_url_called(setup_mocks):
|
|||
setup_mocks["select_url"].assert_called_once()
|
||||
|
||||
|
||||
def test_initialize_defaults_max_retries_to_litellm_default(setup_mocks):
|
||||
result = BaseAzureLLM().initialize_azure_sdk_client(
|
||||
litellm_params={},
|
||||
api_key="test-api-key",
|
||||
api_base="https://test.openai.azure.com",
|
||||
model_name="gpt-4",
|
||||
api_version="2023-06-01",
|
||||
is_async=False,
|
||||
)
|
||||
|
||||
assert result["max_retries"] == litellm.constants.DEFAULT_MAX_RETRIES
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"configured, expected",
|
||||
[(0, 0), (5, 5), (None, litellm.constants.DEFAULT_MAX_RETRIES)],
|
||||
)
|
||||
def test_initialize_honors_explicit_max_retries(setup_mocks, configured, expected):
|
||||
result = BaseAzureLLM().initialize_azure_sdk_client(
|
||||
litellm_params={"max_retries": configured},
|
||||
api_key="test-api-key",
|
||||
api_base="https://test.openai.azure.com",
|
||||
model_name="gpt-4",
|
||||
api_version="2023-06-01",
|
||||
is_async=False,
|
||||
)
|
||||
|
||||
assert result["max_retries"] == expected
|
||||
|
||||
|
||||
def test_default_max_retries_env_var_reaches_azure_sdk_client():
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
code = (
|
||||
"from litellm.llms.azure.common_utils import BaseAzureLLM\n"
|
||||
"client = BaseAzureLLM().get_azure_openai_client("
|
||||
"api_key='test-api-key', api_base='https://test.openai.azure.com', api_version='2024-02-01',"
|
||||
" client=None, _is_async=True, litellm_params={}, model='gpt-4')\n"
|
||||
"print(client.max_retries)"
|
||||
)
|
||||
completed = subprocess.run(
|
||||
[sys.executable, "-c", code],
|
||||
env={**os.environ, "DEFAULT_MAX_RETRIES": "0"},
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
|
||||
assert completed.stdout.strip() == "0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"call_type",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue