mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
refactor(caching): remove redundant comments, restore warning-set state in test
This commit is contained in:
parent
1652079e21
commit
c1f79fdf86
2 changed files with 13 additions and 24 deletions
|
|
@ -394,10 +394,6 @@ class Cache:
|
|||
param_value = kwargs[param]
|
||||
cache_key += f"{param}: {param_value}"
|
||||
elif kwargs[param] is not None and param not in _warned_dropped_cache_params:
|
||||
# Provider-specific param (e.g. ollama num_ctx) is being excluded
|
||||
# from the cache key. Two requests differing only in this param
|
||||
# will collide and the second gets the first's cached response.
|
||||
# Warn once per param; set enable_caching_on_provider_specific_optional_params=True to include it.
|
||||
_warned_dropped_cache_params.add(param)
|
||||
verbose_logger.warning(
|
||||
"litellm.cache: provider-specific param '%s' is excluded from the cache key by default, "
|
||||
|
|
|
|||
|
|
@ -78,32 +78,25 @@ async def test_dual_cache_async_batch_get_cache():
|
|||
|
||||
|
||||
def test_cache_key_warns_on_dropped_provider_specific_param(caplog):
|
||||
"""Provider-specific params dropped from the cache key (default flag) should
|
||||
emit a one-time warning. Regression for #42400."""
|
||||
import litellm
|
||||
from litellm.caching.caching import Cache, _warned_dropped_cache_params
|
||||
|
||||
litellm.enable_caching_on_provider_specific_optional_params = False
|
||||
_warned_dropped_cache_params.discard("num_ctx") # reset in case another test warned
|
||||
_warned_dropped_cache_params.discard("num_ctx")
|
||||
cache = Cache()
|
||||
try:
|
||||
with caplog.at_level(logging.WARNING):
|
||||
cache.get_cache_key(model="ollama/llama3.2",
|
||||
messages=[{"role": "user", "content": "hello"}], num_ctx=2048)
|
||||
assert any("num_ctx" in r.message for r in caplog.records)
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
cache.get_cache_key(
|
||||
model="ollama/llama3.2",
|
||||
messages=[{"role": "user", "content": "hello"}],
|
||||
num_ctx=2048,
|
||||
)
|
||||
assert any("num_ctx" in r.message for r in caplog.records)
|
||||
|
||||
# second call must NOT warn again (one-time behavior)
|
||||
caplog.clear()
|
||||
with caplog.at_level(logging.WARNING):
|
||||
cache.get_cache_key(
|
||||
model="ollama/llama3.2",
|
||||
messages=[{"role": "user", "content": "hello"}],
|
||||
num_ctx=4096,
|
||||
)
|
||||
assert not any("num_ctx" in r.message for r in caplog.records)
|
||||
caplog.clear()
|
||||
with caplog.at_level(logging.WARNING):
|
||||
cache.get_cache_key(model="ollama/llama3.2",
|
||||
messages=[{"role": "user", "content": "hello"}], num_ctx=4096)
|
||||
assert not any("num_ctx" in r.message for r in caplog.records)
|
||||
finally:
|
||||
_warned_dropped_cache_params.discard("num_ctx")
|
||||
|
||||
|
||||
def test_dual_cache_batch_get_cache():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue