From 896fd393dbb33936243edde504d0a63485df8ced Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 9 Feb 2024 14:36:43 -0800 Subject: [PATCH 1/3] (feat) support bedrock timeout --- litellm/llms/bedrock.py | 2 ++ litellm/main.py | 1 + 2 files changed, 3 insertions(+) diff --git a/litellm/llms/bedrock.py b/litellm/llms/bedrock.py index 4118e3183a0..ae076fdf029 100644 --- a/litellm/llms/bedrock.py +++ b/litellm/llms/bedrock.py @@ -526,6 +526,7 @@ def completion( optional_params=None, litellm_params=None, logger_fn=None, + timeout=None, ): exception_mapping_worked = False try: @@ -553,6 +554,7 @@ def completion( aws_role_name=aws_role_name, aws_session_name=aws_session_name, aws_profile_name=aws_profile_name, + timeout=timeout, ) model = model diff --git a/litellm/main.py b/litellm/main.py index d11e76048f6..bf1017a4830 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1590,6 +1590,7 @@ def completion( logger_fn=logger_fn, encoding=encoding, logging_obj=logging, + timeout=timeout, ) if "stream" in optional_params and optional_params["stream"] == True: From 6dc7ded1a6aec87d0b5572766501c9919c930c73 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 9 Feb 2024 14:37:34 -0800 Subject: [PATCH 2/3] (bedrock) raise timeout error --- litellm/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 0ab5d672524..bea16a22141 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -6643,6 +6643,13 @@ def exception_type( llm_provider="bedrock", response=original_exception.response, ) + if "Connect timeout on endpoint URL" in error_str: + exception_mapping_worked = True + raise Timeout( + message=f"BedrockException: Timeout Error - {error_str}", + model=model, + llm_provider="bedrock", + ) if hasattr(original_exception, "status_code"): if original_exception.status_code == 500: exception_mapping_worked = True From 2c116af59601c974763cf69fe7c174d43a9f6c67 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 9 Feb 2024 14:38:17 -0800 Subject: [PATCH 3/3] (test) bedrock timeout --- litellm/tests/test_timeout.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/litellm/tests/test_timeout.py b/litellm/tests/test_timeout.py index 1902e1a36ca..8c92607c02c 100644 --- a/litellm/tests/test_timeout.py +++ b/litellm/tests/test_timeout.py @@ -37,6 +37,28 @@ def test_timeout(): # test_timeout() +def test_bedrock_timeout(): + # this Will Raise a timeout + litellm.set_verbose = True + try: + response = litellm.completion( + model="bedrock/anthropic.claude-instant-v1", + timeout=0.01, + messages=[{"role": "user", "content": "hello, write a 20 pg essay"}], + ) + 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}" + ) + + def test_hanging_request_azure(): litellm.set_verbose = True import asyncio