mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-08 08:08:37 +00:00
fix(utils): allow httpx.Timeout for mistral, openai-compatible and httpx-based providers (#47822)
This commit is contained in:
parent
f2118fc767
commit
c73639b5c7
2 changed files with 70 additions and 5 deletions
|
|
@ -2846,15 +2846,61 @@ def token_counter(
|
|||
)
|
||||
|
||||
|
||||
HTTPX_TIMEOUT_SUPPORTED_PROVIDERS: Final[frozenset[str]] = frozenset(
|
||||
{
|
||||
"openai",
|
||||
"azure",
|
||||
"bedrock",
|
||||
"bedrock_mantle",
|
||||
"custom_openai",
|
||||
"text-completion-openai",
|
||||
"openai_like",
|
||||
"chatgpt",
|
||||
"anthropic",
|
||||
"anthropic_text",
|
||||
"mistral",
|
||||
"codestral",
|
||||
"cohere",
|
||||
"cohere_chat",
|
||||
"ollama",
|
||||
"ollama_chat",
|
||||
"openrouter",
|
||||
"vertex_ai",
|
||||
"gemini",
|
||||
"deepseek",
|
||||
"groq",
|
||||
"together_ai",
|
||||
"fireworks_ai",
|
||||
"perplexity",
|
||||
"xai",
|
||||
"zai",
|
||||
"cerebras",
|
||||
"sambanova",
|
||||
"baseten",
|
||||
"cloudflare",
|
||||
"databricks",
|
||||
"hosted_vllm",
|
||||
"minimax",
|
||||
"huggingface",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def supports_httpx_timeout(custom_llm_provider: str) -> bool:
|
||||
"""
|
||||
Helper function to know if a provider implementation supports httpx timeout
|
||||
"""
|
||||
supported_providers: Final = ["openai", "azure", "bedrock"]
|
||||
|
||||
if custom_llm_provider in supported_providers:
|
||||
if custom_llm_provider in HTTPX_TIMEOUT_SUPPORTED_PROVIDERS:
|
||||
return True
|
||||
|
||||
try:
|
||||
from litellm.constants import openai_compatible_providers
|
||||
|
||||
if custom_llm_provider in openai_compatible_providers:
|
||||
return True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ def test_httpx_timeout_coerced_for_provider_without_httpx_timeout_support():
|
|||
out = CompletionTimeout.resolve(
|
||||
t,
|
||||
{},
|
||||
"azure_ai",
|
||||
"replicate",
|
||||
global_timeout=None,
|
||||
supports_httpx_timeout=supports_httpx_timeout,
|
||||
stream_kind=StreamKind.NOT_STREAMED,
|
||||
|
|
@ -182,7 +182,7 @@ def test_sdk_timeout_coerces_read_timeout_for_providers_without_httpx_support(
|
|||
CompletionTimeout.resolve(
|
||||
SDKTimeout(connect=2.0, read=read_timeout, write=5.0, pool=7.0),
|
||||
{},
|
||||
"azure_ai",
|
||||
"replicate",
|
||||
global_timeout=None,
|
||||
supports_httpx_timeout=supports_httpx_timeout,
|
||||
stream_kind=StreamKind.NOT_STREAMED,
|
||||
|
|
@ -231,3 +231,22 @@ def test_fake_stream_with_only_a_stream_timeout_keeps_the_global_request_timeout
|
|||
)
|
||||
== 600.0
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"provider",
|
||||
("mistral", "custom_openai", "anthropic", "cohere", "ollama", "groq", "deepseek"),
|
||||
)
|
||||
def test_httpx_timeout_preserved_for_extended_providers(provider: str) -> None:
|
||||
t = httpx.Timeout(10.0, connect=1.0)
|
||||
out = CompletionTimeout.resolve(
|
||||
t,
|
||||
{},
|
||||
provider,
|
||||
global_timeout=None,
|
||||
supports_httpx_timeout=supports_httpx_timeout,
|
||||
stream_kind=StreamKind.NOT_STREAMED,
|
||||
)
|
||||
assert out is t
|
||||
assert isinstance(out, httpx.Timeout)
|
||||
assert out.connect == 1.0
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue