forked from phoenix/litellm-mirror
refactor: add black formatting
This commit is contained in:
parent
b87d630b0a
commit
4905929de3
156 changed files with 19723 additions and 10869 deletions
|
@ -5,6 +5,7 @@
|
|||
import sys, os
|
||||
import traceback
|
||||
import pytest
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../..")
|
||||
) # Adds the parent directory to the system path
|
||||
|
@ -18,6 +19,7 @@ user_message = "Hello, how are you?"
|
|||
messages = [{"content": user_message, "role": "user"}]
|
||||
model_val = None
|
||||
|
||||
|
||||
def test_completion_with_no_model():
|
||||
# test on empty
|
||||
with pytest.raises(ValueError):
|
||||
|
@ -32,9 +34,10 @@ def test_completion_with_empty_model():
|
|||
print(f"error occurred: {e}")
|
||||
pass
|
||||
|
||||
|
||||
# def test_completion_catch_nlp_exception():
|
||||
# TEMP commented out NLP cloud API is unstable
|
||||
# try:
|
||||
# try:
|
||||
# response = completion(model="dolphin", messages=messages, functions=[
|
||||
# {
|
||||
# "name": "get_current_weather",
|
||||
|
@ -56,65 +59,77 @@ def test_completion_with_empty_model():
|
|||
# }
|
||||
# ])
|
||||
|
||||
# except Exception as e:
|
||||
# if "Function calling is not supported by nlp_cloud" in str(e):
|
||||
# except Exception as e:
|
||||
# if "Function calling is not supported by nlp_cloud" in str(e):
|
||||
# pass
|
||||
# else:
|
||||
# pytest.fail(f'An error occurred {e}')
|
||||
|
||||
# test_completion_catch_nlp_exception()
|
||||
# test_completion_catch_nlp_exception()
|
||||
|
||||
|
||||
def test_completion_invalid_param_cohere():
|
||||
try:
|
||||
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):
|
||||
except Exception as e:
|
||||
if "Unsupported parameters passed: top_p" in str(e):
|
||||
pass
|
||||
else:
|
||||
pytest.fail(f'An error occurred {e}')
|
||||
else:
|
||||
pytest.fail(f"An error occurred {e}")
|
||||
|
||||
|
||||
# test_completion_invalid_param_cohere()
|
||||
|
||||
|
||||
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:
|
||||
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
|
||||
|
||||
|
||||
|
||||
# test_completion_function_call_cohere()
|
||||
|
||||
def test_completion_function_call_openai():
|
||||
try:
|
||||
|
||||
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"]
|
||||
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"],
|
||||
},
|
||||
}
|
||||
},
|
||||
"required": ["location"]
|
||||
}
|
||||
}
|
||||
])
|
||||
],
|
||||
)
|
||||
print(f"response: {response}")
|
||||
except:
|
||||
except:
|
||||
pass
|
||||
|
||||
# test_completion_function_call_openai()
|
||||
|
||||
# test_completion_function_call_openai()
|
||||
|
||||
|
||||
def test_completion_with_no_provider():
|
||||
# test on empty
|
||||
|
@ -125,6 +140,7 @@ def test_completion_with_no_provider():
|
|||
print(f"error occurred: {e}")
|
||||
pass
|
||||
|
||||
|
||||
# test_completion_with_no_provider()
|
||||
# # bad key
|
||||
# temp_key = os.environ.get("OPENAI_API_KEY")
|
||||
|
@ -136,4 +152,4 @@ def test_completion_with_no_provider():
|
|||
# except:
|
||||
# print(f"error occurred: {traceback.format_exc()}")
|
||||
# pass
|
||||
# os.environ["OPENAI_API_KEY"] = str(temp_key) # this passes linting#5
|
||||
# os.environ["OPENAI_API_KEY"] = str(temp_key) # this passes linting#5
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue