forked from phoenix/litellm-mirror
(test) timeout error
This commit is contained in:
parent
589cdce8d3
commit
9d6569791f
2 changed files with 32 additions and 22 deletions
|
@ -78,7 +78,7 @@ def test_completion_claude2_1():
|
||||||
# print("new cost tracking")
|
# print("new cost tracking")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
test_completion_claude2_1()
|
# test_completion_claude2_1()
|
||||||
|
|
||||||
# def test_completion_oobabooga():
|
# def test_completion_oobabooga():
|
||||||
# try:
|
# try:
|
||||||
|
@ -421,7 +421,12 @@ def test_completion_openai():
|
||||||
litellm.set_verbose=True
|
litellm.set_verbose=True
|
||||||
print(f"api key: {os.environ['OPENAI_API_KEY']}")
|
print(f"api key: {os.environ['OPENAI_API_KEY']}")
|
||||||
litellm.api_key = os.environ['OPENAI_API_KEY']
|
litellm.api_key = os.environ['OPENAI_API_KEY']
|
||||||
response = completion(model="gpt-3.5-turbo", messages=messages, max_tokens=10, request_timeout=10)
|
response = completion(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
messages=messages,
|
||||||
|
max_tokens=10,
|
||||||
|
request_timeout=0.1
|
||||||
|
)
|
||||||
print("This is the response object\n", response)
|
print("This is the response object\n", response)
|
||||||
|
|
||||||
|
|
||||||
|
@ -439,7 +444,7 @@ def test_completion_openai():
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
# test_completion_openai()
|
test_completion_openai()
|
||||||
|
|
||||||
def test_completion_text_openai():
|
def test_completion_text_openai():
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -8,24 +8,29 @@ sys.path.insert(
|
||||||
0, os.path.abspath("../..")
|
0, os.path.abspath("../..")
|
||||||
) # Adds the parent directory to the system path
|
) # Adds the parent directory to the system path
|
||||||
import time
|
import time
|
||||||
from litellm import timeout
|
import litellm
|
||||||
|
import openai
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@timeout(10)
|
def test_timeout():
|
||||||
def stop_after_10_s(force_timeout=60):
|
# this Will Raise a timeout
|
||||||
print("Stopping after 10 seconds")
|
litellm.set_verbose=False
|
||||||
time.sleep(10)
|
try:
|
||||||
return
|
response = litellm.completion(
|
||||||
|
model="gpt-4",
|
||||||
|
timeout=0.01,
|
||||||
start_time = time.time()
|
messages=[
|
||||||
|
{
|
||||||
try:
|
"role": "user",
|
||||||
stop_after_10_s(force_timeout=1)
|
"content": "hello, write a 20 pg essay"
|
||||||
except Exception as e:
|
}
|
||||||
print(e)
|
]
|
||||||
pass
|
)
|
||||||
|
except openai.APITimeoutError as e:
|
||||||
end_time = time.time()
|
print("Passed: Raised correct exception. Got openai.APITimeoutError\nGood Job", e)
|
||||||
|
print(type(e))
|
||||||
print(f"total time: {end_time-start_time}")
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
pytest.fail(f"Did not raise error `openai.APITimeoutError`. Instead raised error type: {type(e)}, Error: {e}")
|
||||||
|
test_timeout()
|
Loading…
Add table
Add a link
Reference in a new issue