mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-08 14:22:08 +00:00
(test) perplexity exception raising
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user