From d7fe4f6c901facb9855aea8e6828dc764196ce0b Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 29 Aug 2023 15:40:16 -0700 Subject: [PATCH] adding new exception mapping details to documentation --- docs/my-website/docs/exception_mapping.md | 25 +++++++++++++++++++---- litellm/utils.py | 8 ++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/my-website/docs/exception_mapping.md b/docs/my-website/docs/exception_mapping.md index 7710c933a7..c7283f80f3 100644 --- a/docs/my-website/docs/exception_mapping.md +++ b/docs/my-website/docs/exception_mapping.md @@ -1,13 +1,14 @@ # Exception Mapping -LiteLLM maps the 3 most common exceptions across all providers. +LiteLLM maps the 4 most common exceptions across all providers. - Rate Limit Errors - Context Window Errors -- InvalidAuth errors (key rotation stuff) +- Invalid Request Errors +- InvalidAuth Errors (incorrect key, etc.) Base case - we return the original exception. -For all 3 cases, the exception returned inherits from the original OpenAI Exception but contains 3 additional attributes: +For all 4 cases, the exception returned inherits from the original OpenAI Exception but contains 3 additional attributes: * status_code - the http status code of the exception * message - the error message * llm_provider - the provider raising the exception @@ -44,9 +45,25 @@ To see how it's implemented - [check out the code](https://github.com/BerriAI/li | Replicate | Request was throttled | RateLimitError | 429 | | Replicate | ReplicateError | ServiceUnavailableError | 500 | | Cohere | invalid api token | AuthenticationError | 401 | -| Cohere | too many tokens | InvalidRequestError | 400 | +| Cohere | too many tokens | ContextWindowExceededError | 400 | | Cohere | CohereConnectionError | RateLimitError | 429 | | Huggingface | 401 | AuthenticationError | 401 | | Huggingface | 400 | InvalidRequestError | 400 | | Huggingface | 429 | RateLimitError | 429 | +| Openrouter | 413 | ContextWindowExceededError | 400 | +| Openrouter | 401 | AuthenticationError | 401 | +| Openrouter | 429 | RateLimitError | 429 | +| AI21 | Prompt has too many tokens | ContextWindowExceededError | 400 | +| AI21 | 422 | InvalidRequestError | 400 | +| AI21 | 401 | AuthenticationError | 401 | +| AI21 | 429 | RateLimitError | 429 | +| TogetherAI | inputs` tokens + `max_new_tokens` must be <= | ContextWindowExceededError | 400 | +| TogetherAI | INVALID_ARGUMENT | InvalidRequestError | 400 | +| TogetherAI | "error_type": "validation" | InvalidRequestError | 400 | +| TogetherAI | invalid private key | AuthenticationError | 401 | +| TogetherAI | 429 | RateLimitError | 429 | + + +The `ContextWindowExceededError` is a sub-class of `InvalidRequestError`. It was introduced to provide more granularity for exception-handling scenarios. Please refer to [this issue to learn more](https://github.com/BerriAI/litellm/issues/228). + diff --git a/litellm/utils.py b/litellm/utils.py index 7633950abe..ac0ca8d4a0 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1332,8 +1332,6 @@ def exception_type(model, original_exception, custom_llm_provider): # Handle the OpenAIError exception_mapping_worked = True if model in litellm.openrouter_models: - print(f"e: {original_exception}") - print(f"original_exception.http_status: {original_exception.http_status}") if original_exception.http_status == 413: raise ContextWindowExceededError( message=str(original_exception), @@ -1422,7 +1420,7 @@ def exception_type(model, original_exception, custom_llm_provider): ) elif "too many tokens" in error_str: exception_mapping_worked = True - raise InvalidRequestError( + raise ContextWindowExceededError( message=f"CohereException - {original_exception.message}", model=model, llm_provider="cohere", @@ -1474,7 +1472,7 @@ def exception_type(model, original_exception, custom_llm_provider): message=f"AI21Exception - {original_exception.message}", llm_provider="ai21", ) - if original_exception.status_code == 422 or "Prompt has too many tokens" in original_exception.message: + if original_exception.status_code == 422: exception_mapping_worked = True raise InvalidRequestError( message=f"AI21Exception - {original_exception.message}", @@ -1522,8 +1520,6 @@ def exception_type(model, original_exception, custom_llm_provider): message=f"TogetherAIException - {original_exception.message}", llm_provider="together_ai", ) - print(f"error: {error_response}") - print(f"e: {original_exception}") raise original_exception # base case - return the original exception else: raise original_exception