litellm/tests/local_testing/test_bad_params.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
3.1 KiB
Python
Raw Normal View History

2023-08-01 09:26:16 +08:00
#### What this tests ####
# This tests chaos monkeys - if random parts of the system are broken / things aren't sent correctly - what happens.
2023-08-19 02:05:05 +08:00
# Expect to add more edge cases to this over time.
2023-08-01 09:26:16 +08:00
2024-07-25 03:21:22 +08:00
import os
import sys
2023-07-31 23:46:23 +08:00
import traceback
2024-07-25 03:21:22 +08:00
import pytest
2023-12-25 16:40:38 +08:00
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
2023-08-01 09:47:50 +08:00
import litellm
2024-07-25 03:21:22 +08:00
from litellm import completion, embedding
from litellm.utils import Message
2023-08-01 09:47:50 +08:00
# litellm.set_verbose = True
2023-07-31 23:46:23 +08:00
user_message = "Hello, how are you?"
2023-08-19 02:05:05 +08:00
messages = [{"content": user_message, "role": "user"}]
2023-08-02 02:29:24 +08:00
model_val = None
2023-08-01 09:36:38 +08:00
2023-12-25 16:40:38 +08:00
def test_completion_with_no_model():
# test on empty
with pytest.raises(TypeError):
response = completion(messages=messages)
2023-08-01 09:36:38 +08:00
def test_completion_with_empty_model():
# test on empty
try:
response = completion(model=model_val, messages=messages)
except Exception as e:
2023-08-19 02:05:05 +08:00
print(f"error occurred: {e}")
2023-08-04 01:06:31 +08:00
pass
2023-12-25 16:40:38 +08:00
def test_completion_invalid_param_cohere():
2023-12-25 16:40:38 +08:00
try:
litellm.set_verbose = True
response = completion(model="command-nightly", messages=messages, seed=12)
pytest.fail(f"This should have failed cohere does not support `seed` parameter")
2023-12-25 16:40:38 +08:00
except Exception as e:
2024-07-25 03:21:22 +08:00
assert isinstance(e, litellm.UnsupportedParamsError)
print("got an exception=", str(e))
2025-04-02 21:49:11 +08:00
if "cohere does not support parameters: ['seed']" in str(e):
pass
2023-12-25 16:40:38 +08:00
else:
pytest.fail(f"An error occurred {e}")
2023-10-02 22:38:52 +08:00
def test_completion_function_call_cohere():
2023-12-25 16:40:38 +08:00
try:
response = completion(
model="command-nightly", messages=messages, functions=["TEST-FUNCTION"]
)
pytest.fail(f"An error occurred {e}")
except Exception as e:
print(e)
pass
2023-12-25 16:40:38 +08:00
2023-10-02 22:38:52 +08:00
2023-12-25 16:40:38 +08:00
def test_completion_function_call_openai():
try:
2023-10-02 22:38:52 +08:00
messages = [{"role": "user", "content": "What is the weather like in Boston?"}]
2023-12-25 16:40:38 +08:00
response = completion(
model="gpt-3.5-turbo",
messages=messages,
functions=[
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
},
},
"required": ["location"],
},
2023-10-02 22:38:52 +08:00
}
2023-12-25 16:40:38 +08:00
],
)
2023-10-02 22:38:52 +08:00
print(f"response: {response}")
except Exception:
2023-10-02 22:38:52 +08:00
pass
2023-12-25 16:40:38 +08:00
# test_completion_function_call_openai()
2023-10-02 22:38:52 +08:00
def test_completion_with_no_provider():
# test on empty
try:
model = "cerebras/btlm-3b-8k-base"
response = completion(model=model, messages=messages)
except Exception as e:
print(f"error occurred: {e}")
pass