From d02ab9bfcd065ed8f4cef62bdb6c9bb9c20b13a1 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 8 Sep 2023 18:55:11 -0700 Subject: [PATCH] update exception logic --- litellm/__pycache__/utils.cpython-311.pyc | Bin 91041 -> 90966 bytes litellm/tests/test_exceptions.py | 16 +++++++++++++++- litellm/utils.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/litellm/__pycache__/utils.cpython-311.pyc b/litellm/__pycache__/utils.cpython-311.pyc index bbb8e3fd35c9194d49e44534bf3f968b1b593287..71efd9879a2252c911a9d1c7feb57fe5581c367d 100644 GIT binary patch delta 327 zcmZ2@ob}ogC0!aIGV7^BqYvgf&Mj59Vr zd8@<7RKvJg=RGqEuRcf%1Y}7}{;*79bI9jbCPw4Qx4zn`)i5?ODl?Rrz*I0Ws4x_@ z*Rq$GBScCpCP#dWovgi@)2x^;#j?Z(A(bT$W0x@$8J9T1cnl0#iZFJG%j7TLG#Qnr zAJk=3+U)Q>f|*fe^2}eWCVTu|$tXMd({B|<)yd+2jxefjzVoMvjpG9kgS74i5uNS% z%#80?IX(z52&-P;QJJ2{$+*ur-i+ZSmyaTlx~l8K38ZdXxS9c}`zA~v(u^yKo%sQS a6H^is^CKo!ASao5^2Q{Q?ZsS-dXWJBs9G`r delta 347 zcmcb1jCJ90R^H{jyj%=Gz;o_*%E^tqtj`!dHVZ#Gf z-s&(imFPpngx)i=@EU^jK|q$||i_whAagbyNsd8xWpO81Ij4D*d=b04}8;PRGHo= z$f&ZJ?|T?Cqw3_;U#pl>7$)=lUc;zAdFO8xM#IVXeji~p+`RZt6Pw^y9tLUE3##T9 zr7W&USzHjY*sjaW_>NWZs{n(r>;+l83lHztjE=Jc#0H|GDr2qf` diff --git a/litellm/tests/test_exceptions.py b/litellm/tests/test_exceptions.py index f8cb8a1b89..95e7f7774d 100644 --- a/litellm/tests/test_exceptions.py +++ b/litellm/tests/test_exceptions.py @@ -2,6 +2,7 @@ from openai.error import AuthenticationError, InvalidRequestError, RateLimitErro import os import sys import traceback +import subprocess sys.path.insert( 0, os.path.abspath("../..") @@ -36,6 +37,7 @@ litellm.vertex_location = "us-central1" models = ["gpt-3.5-turbo"] test_model = "claude-instant-1" +# Test 1: Context Window Errors @pytest.mark.parametrize("model", models) def test_context_window(model): sample_text = "how does a court case get to the Supreme Court?" * 1000 @@ -43,7 +45,19 @@ def test_context_window(model): with pytest.raises(ContextWindowExceededError): completion(model=model, messages=messages) -test_context_window(models[0]) + +def test_uninstall_cohere_and_completion_call(): + # Uninstall cohere package + subprocess.call(["pip", "uninstall", "cohere"]) + + model = "command-nightly" + sample_text = "how does a court case get to the Supreme Court?" * 1000 + messages = [{"content": sample_text, "role": "user"}] + + # with pytest.raises(Exception): + completion(model=model, messages=messages) + +test_uninstall_cohere_and_completion_call() # Test 2: InvalidAuth Errors @pytest.mark.parametrize("model", models) diff --git a/litellm/utils.py b/litellm/utils.py index 90f0b7c4c4..416cfc2051 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1762,7 +1762,7 @@ def exception_type(model, original_exception, custom_llm_provider): llm_provider="cohere", model=model ) - raise ValueError(original_exception) + raise original_exception elif custom_llm_provider == "huggingface": if "length limit exceeded" in error_str: exception_mapping_worked = True @@ -1915,7 +1915,7 @@ def exception_type(model, original_exception, custom_llm_provider): model=model ) else: - raise ValueError(original_exception) + raise original_exception except Exception as e: # LOGGING exception_logging(