(docs) catching timeout exceptions

This commit is contained in:
ishaan-jaff 2023-11-21 13:39:59 -08:00
parent 9d6569791f
commit f18a64f6a4

View file

@ -18,18 +18,27 @@ For all cases, the exception returned inherits from the original OpenAI Exceptio
* message - the error message * message - the error message
* llm_provider - the provider raising the exception * llm_provider - the provider raising the exception
## usage ## Usage
```python ```python
from openai.error import OpenAIError import litellm
from litellm import completion import openai
os.environ["ANTHROPIC_API_KEY"] = "bad-key" try:
try: response = litellm.completion(
# some code model="gpt-4",
completion(model="claude-instant-1", messages=[{"role": "user", "content": "Hey, how's it going?"}]) messages=[
except OpenAIError as e: {
print(e) "role": "user",
"content": "hello, write a 20 pageg essay"
}
],
timeout=0.01, # this will raise a timeout exception
)
except openai.APITimeoutError as e:
print("Passed: Raised correct exception. Got openai.APITimeoutError\nGood Job", e)
print(type(e))
pass
``` ```
## details ## details