From 3d97004b150daf5be248c53062871963e980d662 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 9 Feb 2024 17:42:17 -0800 Subject: [PATCH 1/3] (feat) support timeout on bedrock --- litellm/router.py | 15 ++++++++-- litellm/tests/test_router_timeout.py | 44 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index e9bf6dfed5c..21e967576ed 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -389,7 +389,7 @@ class Router: model_name = data["model"] for k, v in self.default_litellm_params.items(): if ( - k not in kwargs + k not in kwargs and v is not None ): # prioritize model-specific params > default router params kwargs[k] = v elif k == "metadata": @@ -409,13 +409,24 @@ class Router: else: model_client = potential_model_client self.total_calls[model_name] += 1 + + timeout = ( + data.get( + "timeout", None + ) # timeout set on litellm_params for this deployment + or self.timeout # timeout set on router + or kwargs.get( + "timeout", None + ) # this uses default_litellm_params when nothing is set + ) + response = await litellm.acompletion( **{ **data, "messages": messages, "caching": self.cache_responses, "client": model_client, - "timeout": self.timeout, + "timeout": timeout, **kwargs, } ) diff --git a/litellm/tests/test_router_timeout.py b/litellm/tests/test_router_timeout.py index 1f93a60a689..b22683c41e1 100644 --- a/litellm/tests/test_router_timeout.py +++ b/litellm/tests/test_router_timeout.py @@ -85,3 +85,47 @@ def test_router_timeouts(): print("Response:", response) print("********** TOKENS USED SO FAR = ", total_tokens_used) + + +@pytest.mark.asyncio +async def test_router_timeouts_bedrock(): + import openai + + # Model list for OpenAI and Anthropic models + model_list = [ + { + "model_name": "bedrock", + "litellm_params": { + "model": "bedrock/anthropic.claude-instant-v1", + "timeout": 0.001, + }, + "tpm": 80000, + }, + ] + + # Configure router + router = Router( + model_list=model_list, + routing_strategy="usage-based-routing", + debug_level="DEBUG", + set_verbose=True, + ) + + litellm.set_verbose = True + try: + response = await router.acompletion( + model="bedrock", + messages=[{"role": "user", "content": "hello, who are u"}], + ) + print(response) + pytest.fail("Did not raise error `openai.APITimeoutError`") + except openai.APITimeoutError as e: + print( + "Passed: Raised correct exception. Got openai.APITimeoutError\nGood Job", e + ) + print(type(e)) + pass + except Exception as e: + pytest.fail( + f"Did not raise error `openai.APITimeoutError`. Instead raised error type: {type(e)}, Error: {e}" + ) From 640011379c2498be477e7fa98ba69f17595ee170 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 9 Feb 2024 17:42:35 -0800 Subject: [PATCH 2/3] (feat) set timeout on proxy config --- litellm/proxy/proxy_config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 82f0fa877f6..a549771d5d5 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -29,6 +29,7 @@ model_list: - model_name: BEDROCK_GROUP litellm_params: model: bedrock/cohere.command-text-v14 + timeout: 0.0001 - model_name: tg-ai litellm_params: model: together_ai/mistralai/Mistral-7B-Instruct-v0.1 From 556c1605e6493555f63bffadfa7540c884b7a369 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 9 Feb 2024 18:50:07 -0800 Subject: [PATCH 3/3] =?UTF-8?q?bump:=20version=201.23.5=20=E2=86=92=201.23?= =?UTF-8?q?.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fde1a27708f..b0126654720 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "1.23.5" +version = "1.23.6" description = "Library to easily interface with LLM API providers" authors = ["BerriAI"] license = "MIT" @@ -69,7 +69,7 @@ requires = ["poetry-core", "wheel"] build-backend = "poetry.core.masonry.api" [tool.commitizen] -version = "1.23.5" +version = "1.23.6" version_files = [ "pyproject.toml:^version" ]