From 11512c057d4c1e5c88b92e28d09484de9fbb0c74 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 24 Jul 2024 12:19:10 -0700 Subject: [PATCH 1/3] feat use UnsupportedParamsError as litellm error type --- litellm/__init__.py | 1 + litellm/exceptions.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/litellm/__init__.py b/litellm/__init__.py index 5a10ae77c11..956834afc3c 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -888,6 +888,7 @@ from .exceptions import ( APIError, Timeout, APIConnectionError, + UnsupportedParamsError, APIResponseValidationError, UnprocessableEntityError, InternalServerError, diff --git a/litellm/exceptions.py b/litellm/exceptions.py index 414b3e002ac..d2337b7f494 100644 --- a/litellm/exceptions.py +++ b/litellm/exceptions.py @@ -682,11 +682,39 @@ class JSONSchemaValidationError(APIError): ) +class UnsupportedParamsError(BadRequestError): + def __init__( + self, + message, + llm_provider: Optional[str] = None, + model: Optional[str] = None, + status_code: int = 400, + response: Optional[httpx.Response] = None, + litellm_debug_info: Optional[str] = None, + max_retries: Optional[int] = None, + num_retries: Optional[int] = None, + ): + self.status_code = 400 + self.message = "litellm.UnsupportedParamsError: {}".format(message) + self.model = model + self.llm_provider = llm_provider + self.litellm_debug_info = litellm_debug_info + response = response or httpx.Response( + status_code=self.status_code, + request=httpx.Request( + method="GET", url="https://litellm.ai" + ), # mock request object + ) + self.max_retries = max_retries + self.num_retries = num_retries + + LITELLM_EXCEPTION_TYPES = [ AuthenticationError, NotFoundError, BadRequestError, UnprocessableEntityError, + UnsupportedParamsError, Timeout, PermissionDeniedError, RateLimitError, From 8ea4b73c27101974ef5789ad2fceda361fbde623 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 24 Jul 2024 12:20:14 -0700 Subject: [PATCH 2/3] add UnsupportedParamsError to litellm exceptions --- litellm/utils.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index 035c1c72f7a..a6d3d860301 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -129,6 +129,7 @@ from .exceptions import ( ServiceUnavailableError, Timeout, UnprocessableEntityError, + UnsupportedParamsError, ) from .proxy._types import KeyManagementSystem from .types.llms.openai import ( @@ -225,17 +226,6 @@ last_fetched_at_keys = None # } -class UnsupportedParamsError(Exception): - def __init__(self, status_code, message): - self.status_code = status_code - self.message = message - self.request = httpx.Request(method="POST", url=" https://openai.api.com/v1/") - self.response = httpx.Response(status_code=status_code, request=self.request) - super().__init__( - self.message - ) # Call the base class constructor with the parameters it needs - - ############################################################ def print_verbose( print_statement, From 30c27b3f92a772d48e7a59bc74f6edc7b944a9af Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 24 Jul 2024 12:21:22 -0700 Subject: [PATCH 3/3] test UnsupportedParamsError --- litellm/tests/test_bad_params.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/tests/test_bad_params.py b/litellm/tests/test_bad_params.py index 9f126a1b8c0..1b20096e5d0 100644 --- a/litellm/tests/test_bad_params.py +++ b/litellm/tests/test_bad_params.py @@ -2,18 +2,19 @@ # This tests chaos monkeys - if random parts of the system are broken / things aren't sent correctly - what happens. # Expect to add more edge cases to this over time. -import sys, os +import os +import sys import traceback + import pytest sys.path.insert( 0, os.path.abspath("../..") ) # Adds the parent directory to the system path import litellm -from litellm import embedding, completion +from litellm import completion, embedding from litellm.utils import Message - # litellm.set_verbose = True user_message = "Hello, how are you?" messages = [{"content": user_message, "role": "user"}] @@ -74,6 +75,8 @@ def test_completion_invalid_param_cohere(): response = completion(model="command-nightly", messages=messages, seed=12) pytest.fail(f"This should have failed cohere does not support `seed` parameter") except Exception as e: + assert isinstance(e, litellm.UnsupportedParamsError) + print("got an exception=", str(e)) if " cohere does not support parameters: {'seed': 12}" in str(e): pass else: