fix(caching.py): return updated kwargs from get_cache helper function

This commit is contained in:
Krrish Dholakia 2024-01-13 15:04:34 +05:30
parent ebf1bc842c
commit 7f83cca62c
3 changed files with 9 additions and 8 deletions

View file

@ -678,7 +678,7 @@ class Cache:
if k == "ttl":
kwargs["ttl"] = v
cached_data = {"timestamp": time.time(), "response": result}
return cache_key, cached_data
return cache_key, cached_data, kwargs
else:
raise Exception("cache key is None")
except Exception as e:
@ -696,7 +696,7 @@ class Cache:
None
"""
try:
cache_key, cached_data = self._add_cache_logic(
cache_key, cached_data, kwargs = self._add_cache_logic(
result=result, *args, **kwargs
)
self.cache.set_cache(cache_key, cached_data, **kwargs)
@ -710,7 +710,7 @@ class Cache:
Async implementation of add_cache
"""
try:
cache_key, cached_data = self._add_cache_logic(
cache_key, cached_data, kwargs = self._add_cache_logic(
result=result, *args, **kwargs
)
await self.cache.async_set_cache(cache_key, cached_data, **kwargs)

View file

@ -109,10 +109,7 @@ def test_caching_with_cache_controls():
)
print(f"response1: {response1}")
print(f"response2: {response2}")
assert (
response2["choices"][0]["message"]["content"]
== response1["choices"][0]["message"]["content"]
)
assert response2["id"] == response1["id"]
except Exception as e:
print(f"error occurred: {traceback.format_exc()}")
pytest.fail(f"Error occurred: {e}")

View file

@ -2029,7 +2029,11 @@ def client(original_function):
# if caching is false or cache["no-cache"]==True, don't run this
if (
(
(kwargs.get("caching", None) is None and litellm.cache is not None)
(
kwargs.get("caching", None) is None
and kwargs.get("cache", None) is None
and litellm.cache is not None
)
or kwargs.get("caching", False) == True
or (
kwargs.get("cache", None) is not None