Merge pull request #2695 from BerriAI/litellm_fix_cache_controls

(test) Using Cache controls with litellm - `no-cache=True`
This commit is contained in:
Ishaan Jaff 2024-03-25 18:58:05 -07:00 committed by GitHub
commit ab8e264691
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -926,6 +926,53 @@ def test_cache_override():
# test_cache_override() # test_cache_override()
@pytest.mark.asyncio
async def test_cache_control_overrides():
# we use the cache controls to ensure there is no cache hit on this test
litellm.cache = Cache(
type="redis",
host=os.environ["REDIS_HOST"],
port=os.environ["REDIS_PORT"],
password=os.environ["REDIS_PASSWORD"],
)
print("Testing cache override")
litellm.set_verbose = True
import uuid
unique_num = str(uuid.uuid4())
start_time = time.time()
response1 = await litellm.acompletion(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": "hello who are you" + unique_num,
}
],
)
print(response1)
await asyncio.sleep(2)
response2 = await litellm.acompletion(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": "hello who are you" + unique_num,
}
],
cache={"no-cache": True},
)
print(response2)
assert response1.id != response2.id
def test_custom_redis_cache_params(): def test_custom_redis_cache_params():
# test if we can init redis with **kwargs # test if we can init redis with **kwargs
try: try: