caching test fix

This commit is contained in:
ishaan-jaff
2023-08-10 14:51:44 -07:00
parent f6279353ac
commit 35bb67c2de
+5 -6
View File
@@ -3,10 +3,10 @@ import traceback
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(0, os.path.abspath('../..')) # Adds the parent directory to the system path
import pytest
import litellm
from litellm import embedding, completion
# set cache to True
litellm.cache = True
@@ -15,19 +15,20 @@ litellm.cache_similarity_threshold = 0.5
user_message = "Hello, whats the weather in San Francisco??"
messages = [{ "content": user_message,"role": "user"}]
def test_completion_gpt():
def test_completion_with_cache_gpt4():
try:
# in this test make the same call twice, measure the response time
# the 2nd response time should be less than half of the first, ensuring that the cache is working
import time
start = time.time()
response = completion(model="gpt-4", messages=messages)
print(litellm.cache)
response = litellm.completion(model="gpt-4", messages=messages)
end = time.time()
first_call_time = end-start
print(f"first call: {first_call_time}")
start = time.time()
response = completion(model="gpt-4", messages=messages)
response = litellm.completion(model="gpt-4", messages=messages)
end = time.time()
second_call_time = end-start
print(f"second call: {second_call_time}")
@@ -40,5 +41,3 @@ def test_completion_gpt():
except Exception as e:
pytest.fail(f"Error occurred: {e}")
litellm.cache = False # rest to False for the next test