|
|
|
|
|
|
|
|
|
import sys, os |
|
import traceback |
|
import pytest |
|
sys.path.insert( |
|
0, os.path.abspath("../..") |
|
) |
|
import litellm |
|
from litellm import embedding, completion |
|
from litellm.utils import Message |
|
|
|
|
|
|
|
user_message = "Hello, how are you?" |
|
messages = [{"content": user_message, "role": "user"}] |
|
model_val = None |
|
|
|
def test_completion_with_no_model(): |
|
|
|
with pytest.raises(ValueError): |
|
response = completion(messages=messages) |
|
|
|
|
|
def test_completion_with_empty_model(): |
|
|
|
try: |
|
response = completion(model=model_val, messages=messages) |
|
except Exception as e: |
|
print(f"error occurred: {e}") |
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_completion_invalid_param_cohere(): |
|
try: |
|
response = completion(model="command-nightly", messages=messages, top_p=1) |
|
print(f"response: {response}") |
|
except Exception as e: |
|
if "Unsupported parameters passed: top_p" in str(e): |
|
pass |
|
else: |
|
pytest.fail(f'An error occurred {e}') |
|
|
|
|
|
|
|
def test_completion_function_call_cohere(): |
|
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 |
|
|
|
|
|
|
|
|
|
def test_completion_function_call_openai(): |
|
try: |
|
messages = [{"role": "user", "content": "What is the weather like in Boston?"}] |
|
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"] |
|
} |
|
} |
|
]) |
|
print(f"response: {response}") |
|
except: |
|
pass |
|
|
|
|
|
|
|
def test_completion_with_no_provider(): |
|
|
|
try: |
|
model = "cerebras/btlm-3b-8k-base" |
|
response = completion(model=model, messages=messages) |
|
except Exception as e: |
|
print(f"error occurred: {e}") |
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|