From 6166566054c0dc079afcd6b51c0b4d46c41dd2cc Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 2 Feb 2024 08:46:42 -0800 Subject: [PATCH] (test) perplexity exception raising --- litellm/tests/test_exceptions.py | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/litellm/tests/test_exceptions.py b/litellm/tests/test_exceptions.py index 70e45341ac..dfa571f00c 100644 --- a/litellm/tests/test_exceptions.py +++ b/litellm/tests/test_exceptions.py @@ -444,6 +444,52 @@ def test_content_policy_violation_error_streaming(): asyncio.run(test_get_error()) +def test_completion_perplexity_exception(): + try: + import openai + + print("perplexity test\n\n") + litellm.set_verbose = True + ## Test azure call + old_azure_key = os.environ["PERPLEXITYAI_API_KEY"] + os.environ["PERPLEXITYAI_API_KEY"] = "good morning" + response = completion( + model="perplexity/mistral-7b-instruct", + messages=[{"role": "user", "content": "hello"}], + ) + os.environ["PERPLEXITYAI_API_KEY"] = old_azure_key + pytest.fail("Request should have failed - bad api key") + except openai.AuthenticationError as e: + os.environ["PERPLEXITYAI_API_KEY"] = old_azure_key + print("exception: ", e) + assert "PerplexityException" in str(e) + except Exception as e: + pytest.fail(f"Error occurred: {e}") + + +def test_completion_openai_api_key_exception(): + try: + import openai + + print("gpt-3.5 test\n\n") + litellm.set_verbose = True + ## Test azure call + old_azure_key = os.environ["OPENAI_API_KEY"] + os.environ["OPENAI_API_KEY"] = "good morning" + response = completion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "hello"}], + ) + os.environ["OPENAI_API_KEY"] = old_azure_key + pytest.fail("Request should have failed - bad api key") + except openai.AuthenticationError as e: + os.environ["OPENAI_API_KEY"] = old_azure_key + print("exception: ", e) + assert "OpenAIException" in str(e) + except Exception as e: + pytest.fail(f"Error occurred: {e}") + + # tesy_async_acompletion() # # test_invalid_request_error(model="command-nightly")