From f18a64f6a47886da95faf4f4e496c8bd9c24ca1d Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Tue, 21 Nov 2023 13:39:59 -0800 Subject: [PATCH] (docs) catching timeout exceptions --- docs/my-website/docs/exception_mapping.md | 27 +++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/my-website/docs/exception_mapping.md b/docs/my-website/docs/exception_mapping.md index b29f2d4b9..7af668678 100644 --- a/docs/my-website/docs/exception_mapping.md +++ b/docs/my-website/docs/exception_mapping.md @@ -18,18 +18,27 @@ For all cases, the exception returned inherits from the original OpenAI Exceptio * message - the error message * llm_provider - the provider raising the exception -## usage +## Usage ```python -from openai.error import OpenAIError -from litellm import completion +import litellm +import openai -os.environ["ANTHROPIC_API_KEY"] = "bad-key" -try: - # some code - completion(model="claude-instant-1", messages=[{"role": "user", "content": "Hey, how's it going?"}]) -except OpenAIError as e: - print(e) +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: + print("Passed: Raised correct exception. Got openai.APITimeoutError\nGood Job", e) + print(type(e)) + pass ``` ## details