forked from phoenix/litellm-mirror
docs(exception_mapping.md): update exception mapping docs with 'should_retry'
This commit is contained in:
parent
2084cfd959
commit
f7eee60943
2 changed files with 60 additions and 22 deletions
|
@ -13,7 +13,7 @@ LiteLLM maps exceptions across all providers to their OpenAI counterparts.
|
||||||
| >=500 | InternalServerError |
|
| >=500 | InternalServerError |
|
||||||
| N/A | ContextWindowExceededError|
|
| N/A | ContextWindowExceededError|
|
||||||
| 400 | ContentPolicyViolationError|
|
| 400 | ContentPolicyViolationError|
|
||||||
| N/A | APIConnectionError |
|
| 500 | APIConnectionError |
|
||||||
|
|
||||||
|
|
||||||
Base case we return APIConnectionError
|
Base case we return APIConnectionError
|
||||||
|
@ -74,6 +74,28 @@ except Exception as e:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage - Should you retry exception?
|
||||||
|
|
||||||
|
```
|
||||||
|
import litellm
|
||||||
|
import openai
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = litellm.completion(
|
||||||
|
model="gpt-4",
|
||||||
|
messages=[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "hello, write a 20 pageg essay"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
timeout=0.01, # this will raise a timeout exception
|
||||||
|
)
|
||||||
|
except openai.APITimeoutError as e:
|
||||||
|
should_retry = litellm._should_retry(e.status_code)
|
||||||
|
print(f"should_retry: {should_retry}")
|
||||||
|
```
|
||||||
|
|
||||||
## Details
|
## Details
|
||||||
|
|
||||||
To see how it's implemented - [check out the code](https://github.com/BerriAI/litellm/blob/a42c197e5a6de56ea576c73715e6c7c6b19fa249/litellm/utils.py#L1217)
|
To see how it's implemented - [check out the code](https://github.com/BerriAI/litellm/blob/a42c197e5a6de56ea576c73715e6c7c6b19fa249/litellm/utils.py#L1217)
|
||||||
|
@ -86,21 +108,34 @@ To see how it's implemented - [check out the code](https://github.com/BerriAI/li
|
||||||
|
|
||||||
Base case - we return the original exception.
|
Base case - we return the original exception.
|
||||||
|
|
||||||
| | ContextWindowExceededError | AuthenticationError | InvalidRequestError | RateLimitError | ServiceUnavailableError |
|
| custom_llm_provider | Timeout | ContextWindowExceededError | BadRequestError | NotFoundError | ContentPolicyViolationError | AuthenticationError | APIError | RateLimitError | ServiceUnavailableError | PermissionDeniedError | UnprocessableEntityError |
|
||||||
|---------------|----------------------------|---------------------|---------------------|---------------|-------------------------|
|
|----------------------------|---------|----------------------------|------------------|---------------|-----------------------------|---------------------|----------|----------------|-------------------------|-----------------------|-------------------------|
|
||||||
| Anthropic | ✅ | ✅ | ✅ | ✅ | |
|
| openai | ✓ | ✓ | ✓ | | ✓ | ✓ | | | | | |
|
||||||
| OpenAI | ✅ | ✅ |✅ |✅ |✅|
|
| text-completion-openai | ✓ | ✓ | ✓ | | ✓ | ✓ | | | | | |
|
||||||
| Azure OpenAI | ✅ | ✅ |✅ |✅ |✅|
|
| custom_openai | ✓ | ✓ | ✓ | | ✓ | ✓ | | | | | |
|
||||||
| Replicate | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| openai_compatible_providers| ✓ | ✓ | ✓ | | ✓ | ✓ | | | | | |
|
||||||
| Cohere | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| anthropic | ✓ | ✓ | ✓ | ✓ | | ✓ | | | ✓ | ✓ | |
|
||||||
| Huggingface | ✅ | ✅ | ✅ | ✅ | |
|
| replicate | ✓ | ✓ | ✓ | ✓ | | ✓ | | ✓ | ✓ | | |
|
||||||
| Openrouter | ✅ | ✅ | ✅ | ✅ | |
|
| bedrock | ✓ | ✓ | ✓ | ✓ | | ✓ | | ✓ | ✓ | ✓ | |
|
||||||
| AI21 | ✅ | ✅ | ✅ | ✅ | |
|
| sagemaker | | ✓ | ✓ | | | | | | | | |
|
||||||
| VertexAI | | |✅ | | |
|
| vertex_ai | ✓ | | ✓ | | | | ✓ | | | | ✓ |
|
||||||
| Bedrock | | |✅ | | |
|
| palm | ✓ | ✓ | | | | | ✓ | | | | |
|
||||||
| Sagemaker | | |✅ | | |
|
| gemini | ✓ | ✓ | | | | | ✓ | | | | |
|
||||||
| TogetherAI | ✅ | ✅ | ✅ | ✅ | |
|
| cloudflare | | | ✓ | | | ✓ | | | | | |
|
||||||
| AlephAlpha | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| cohere | | ✓ | ✓ | | | ✓ | | | ✓ | | |
|
||||||
|
| cohere_chat | | ✓ | ✓ | | | ✓ | | | ✓ | | |
|
||||||
|
| huggingface | ✓ | ✓ | ✓ | | | ✓ | | ✓ | ✓ | | |
|
||||||
|
| ai21 | ✓ | ✓ | ✓ | ✓ | | ✓ | | ✓ | | | |
|
||||||
|
| nlp_cloud | ✓ | ✓ | ✓ | | | ✓ | ✓ | ✓ | ✓ | | |
|
||||||
|
| together_ai | ✓ | ✓ | ✓ | | | ✓ | | | | | |
|
||||||
|
| aleph_alpha | | | ✓ | | | ✓ | | | | | |
|
||||||
|
| ollama | ✓ | | ✓ | | | | | | ✓ | | |
|
||||||
|
| ollama_chat | ✓ | | ✓ | | | | | | ✓ | | |
|
||||||
|
| vllm | | | | | | ✓ | ✓ | | | | |
|
||||||
|
| azure | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | | ✓ | | |
|
||||||
|
|
||||||
|
- "✓" indicates that the specified `custom_llm_provider` can raise the corresponding exception.
|
||||||
|
- Empty cells indicate the lack of association or that the provider does not raise that particular exception type as indicated by the function.
|
||||||
|
|
||||||
|
|
||||||
> For a deeper understanding of these exceptions, you can check out [this](https://github.com/BerriAI/litellm/blob/d7e58d13bf9ba9edbab2ab2f096f3de7547f35fa/litellm/utils.py#L1544) implementation for additional insights.
|
> For a deeper understanding of these exceptions, you can check out [this](https://github.com/BerriAI/litellm/blob/d7e58d13bf9ba9edbab2ab2f096f3de7547f35fa/litellm/utils.py#L1544) implementation for additional insights.
|
||||||
|
|
|
@ -8480,7 +8480,7 @@ def exception_type(
|
||||||
# 503 Getting metadata from plugin failed with error: Reauthentication is needed. Please run `gcloud auth application-default login` to reauthenticate.
|
# 503 Getting metadata from plugin failed with error: Reauthentication is needed. Please run `gcloud auth application-default login` to reauthenticate.
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
raise BadRequestError(
|
raise BadRequestError(
|
||||||
message=f"PalmException - Invalid api key",
|
message=f"GeminiException - Invalid api key",
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="palm",
|
llm_provider="palm",
|
||||||
response=original_exception.response,
|
response=original_exception.response,
|
||||||
|
@ -8491,23 +8491,26 @@ def exception_type(
|
||||||
):
|
):
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
raise Timeout(
|
raise Timeout(
|
||||||
message=f"PalmException - {original_exception.message}",
|
message=f"GeminiException - {original_exception.message}",
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="palm",
|
llm_provider="palm",
|
||||||
)
|
)
|
||||||
if "400 Request payload size exceeds" in error_str:
|
if "400 Request payload size exceeds" in error_str:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
raise ContextWindowExceededError(
|
raise ContextWindowExceededError(
|
||||||
message=f"PalmException - {error_str}",
|
message=f"GeminiException - {error_str}",
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="palm",
|
llm_provider="palm",
|
||||||
response=original_exception.response,
|
response=original_exception.response,
|
||||||
)
|
)
|
||||||
if "500 An internal error has occurred." in error_str:
|
if (
|
||||||
|
"500 An internal error has occurred." in error_str
|
||||||
|
or "list index out of range" in error_str
|
||||||
|
):
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
raise APIError(
|
raise APIError(
|
||||||
status_code=getattr(original_exception, "status_code", 500),
|
status_code=getattr(original_exception, "status_code", 500),
|
||||||
message=f"PalmException - {original_exception.message}",
|
message=f"GeminiException - {original_exception.message}",
|
||||||
llm_provider="palm",
|
llm_provider="palm",
|
||||||
model=model,
|
model=model,
|
||||||
request=original_exception.request,
|
request=original_exception.request,
|
||||||
|
@ -8516,7 +8519,7 @@ def exception_type(
|
||||||
if original_exception.status_code == 400:
|
if original_exception.status_code == 400:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
raise BadRequestError(
|
raise BadRequestError(
|
||||||
message=f"PalmException - {error_str}",
|
message=f"GeminiException - {error_str}",
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="palm",
|
llm_provider="palm",
|
||||||
response=original_exception.response,
|
response=original_exception.response,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue