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")
|
||||
except Exception as e:
|
||||
pytest.fail(f"Error occurred: {e}")
|
||||
test_completion_claude2_1()
|
||||
# test_completion_claude2_1()
|
||||
|
||||
# def test_completion_oobabooga():
|
||||
# try:
|
||||
|
@ -421,7 +421,12 @@ def test_completion_openai():
|
|||
litellm.set_verbose=True
|
||||
print(f"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)
|
||||
|
||||
|
||||
|
@ -439,7 +444,7 @@ def test_completion_openai():
|
|||
pass
|
||||
except Exception as e:
|
||||
pytest.fail(f"Error occurred: {e}")
|
||||
# test_completion_openai()
|
||||
test_completion_openai()
|
||||
|
||||
def test_completion_text_openai():
|
||||
try:
|
||||
|
|
|
@ -8,24 +8,29 @@ sys.path.insert(
|
|||
0, os.path.abspath("../..")
|
||||
) # Adds the parent directory to the system path
|
||||
import time
|
||||
from litellm import timeout
|
||||
import litellm
|
||||
import openai
|
||||
import pytest
|
||||
|
||||
|
||||
@timeout(10)
|
||||
def stop_after_10_s(force_timeout=60):
|
||||
print("Stopping after 10 seconds")
|
||||
time.sleep(10)
|
||||
return
|
||||
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
try:
|
||||
stop_after_10_s(force_timeout=1)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
|
||||
end_time = time.time()
|
||||
|
||||
print(f"total time: {end_time-start_time}")
|
||||
def test_timeout():
|
||||
# this Will Raise a timeout
|
||||
litellm.set_verbose=False
|
||||
try:
|
||||
response = litellm.completion(
|
||||
model="gpt-4",
|
||||
timeout=0.01,
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hello, write a 20 pg essay"
|
||||
}
|
||||
]
|
||||
)
|
||||
except openai.APITimeoutError as e:
|
||||
print("Passed: Raised correct exception. Got openai.APITimeoutError\nGood Job", e)
|
||||
print(type(e))
|
||||
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