(test) improve exceptions for pplx AI

This commit is contained in:
ishaan-jaff 2024-02-02 12:37:21 -08:00
parent 4473c48e2b
commit e37294c921

View file

@ -455,15 +455,21 @@ def test_completion_perplexity_exception_on_openai_client():
# delete perplexityai api key to simulate bad api key
del os.environ["PERPLEXITYAI_API_KEY"]
# temporaily delete openai api key
original_openai_key = os.environ["OPENAI_API_KEY"]
del os.environ["OPENAI_API_KEY"]
response = completion(
model="perplexity/mistral-7b-instruct",
messages=[{"role": "user", "content": "hello"}],
)
os.environ["PERPLEXITYAI_API_KEY"] = old_azure_key
os.environ["OPENAI_API_KEY"] = original_openai_key
pytest.fail("Request should have failed - bad api key")
except openai.AuthenticationError as e:
os.environ["PERPLEXITYAI_API_KEY"] = old_azure_key
os.environ["OPENAI_API_KEY"] = original_openai_key
print("exception: ", e)
assert (
"perplexity.perplexityError: The api_key client option must be set either by passing api_key to the client or by setting the PERPLEXITY_API_KEY environment variable"