mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix(caching.py): return updated kwargs from get_cache helper function
This commit is contained in:
parent
ebf1bc842c
commit
7f83cca62c
3 changed files with 9 additions and 8 deletions
|
@ -678,7 +678,7 @@ class Cache:
|
||||||
if k == "ttl":
|
if k == "ttl":
|
||||||
kwargs["ttl"] = v
|
kwargs["ttl"] = v
|
||||||
cached_data = {"timestamp": time.time(), "response": result}
|
cached_data = {"timestamp": time.time(), "response": result}
|
||||||
return cache_key, cached_data
|
return cache_key, cached_data, kwargs
|
||||||
else:
|
else:
|
||||||
raise Exception("cache key is None")
|
raise Exception("cache key is None")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -696,7 +696,7 @@ class Cache:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cache_key, cached_data = self._add_cache_logic(
|
cache_key, cached_data, kwargs = self._add_cache_logic(
|
||||||
result=result, *args, **kwargs
|
result=result, *args, **kwargs
|
||||||
)
|
)
|
||||||
self.cache.set_cache(cache_key, cached_data, **kwargs)
|
self.cache.set_cache(cache_key, cached_data, **kwargs)
|
||||||
|
@ -710,7 +710,7 @@ class Cache:
|
||||||
Async implementation of add_cache
|
Async implementation of add_cache
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cache_key, cached_data = self._add_cache_logic(
|
cache_key, cached_data, kwargs = self._add_cache_logic(
|
||||||
result=result, *args, **kwargs
|
result=result, *args, **kwargs
|
||||||
)
|
)
|
||||||
await self.cache.async_set_cache(cache_key, cached_data, **kwargs)
|
await self.cache.async_set_cache(cache_key, cached_data, **kwargs)
|
||||||
|
|
|
@ -109,10 +109,7 @@ def test_caching_with_cache_controls():
|
||||||
)
|
)
|
||||||
print(f"response1: {response1}")
|
print(f"response1: {response1}")
|
||||||
print(f"response2: {response2}")
|
print(f"response2: {response2}")
|
||||||
assert (
|
assert response2["id"] == response1["id"]
|
||||||
response2["choices"][0]["message"]["content"]
|
|
||||||
== response1["choices"][0]["message"]["content"]
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"error occurred: {traceback.format_exc()}")
|
print(f"error occurred: {traceback.format_exc()}")
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
|
@ -2029,7 +2029,11 @@ def client(original_function):
|
||||||
# if caching is false or cache["no-cache"]==True, don't run this
|
# if caching is false or cache["no-cache"]==True, don't run this
|
||||||
if (
|
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("caching", False) == True
|
||||||
or (
|
or (
|
||||||
kwargs.get("cache", None) is not None
|
kwargs.get("cache", None) is not None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue