mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 19:54:13 +00:00
(test) perplexity exception raising
This commit is contained in:
parent
c73684a5b1
commit
6166566054
1 changed files with 46 additions and 0 deletions
|
@ -444,6 +444,52 @@ def test_content_policy_violation_error_streaming():
|
||||||
asyncio.run(test_get_error())
|
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()
|
# tesy_async_acompletion()
|
||||||
|
|
||||||
# # test_invalid_request_error(model="command-nightly")
|
# # test_invalid_request_error(model="command-nightly")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue