mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-30 01:52:18 +00:00
fix cache key raw payload logging
This commit is contained in:
parent
28c0d8579b
commit
1aae75ef3e
2 changed files with 56 additions and 1 deletions
|
|
@ -309,7 +309,9 @@ class Cache:
|
|||
param_value = kwargs[param]
|
||||
cache_key += f"{str(param)}: {str(param_value)}"
|
||||
|
||||
verbose_logger.debug("\nCreated cache key: %s", cache_key)
|
||||
verbose_logger.debug(
|
||||
"\nCreated cache key payload length before hashing: %s", len(cache_key)
|
||||
)
|
||||
hashed_cache_key = Cache._get_hashed_cache_key(cache_key)
|
||||
hashed_cache_key = self._add_namespace_to_cache_key(hashed_cache_key, **kwargs)
|
||||
# Remove preset_cache_key from kwargs to avoid "got multiple values" TypeError
|
||||
|
|
|
|||
53
tests/test_litellm/caching/test_cache_key_logging.py
Normal file
53
tests/test_litellm/caching/test_cache_key_logging.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import logging
|
||||
|
||||
from litellm.caching.caching import Cache
|
||||
|
||||
|
||||
def test_cache_key_logging_does_not_emit_raw_request_payload(caplog):
|
||||
cache = Cache()
|
||||
payload_marker = "RAW_PAYLOAD_MARKER_29414"
|
||||
tool_marker = "RAW_TOOL_MARKER_29414"
|
||||
schema_marker = "RAW_SCHEMA_MARKER_29414"
|
||||
|
||||
with caplog.at_level(logging.DEBUG, logger="LiteLLM"):
|
||||
cache_key = cache.get_cache_key(
|
||||
model="gpt-4.1",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"Please summarize {payload_marker}.",
|
||||
}
|
||||
],
|
||||
tools=[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "lookup_customer",
|
||||
"description": tool_marker,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {"customer_id": {"type": "string"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
response_format={
|
||||
"type": "json_schema",
|
||||
"json_schema": {
|
||||
"name": "summary",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"description": schema_marker,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
log_output = "\n".join(
|
||||
record.getMessage() for record in caplog.records if record.name == "LiteLLM"
|
||||
)
|
||||
|
||||
assert payload_marker not in log_output
|
||||
assert tool_marker not in log_output
|
||||
assert schema_marker not in log_output
|
||||
assert cache_key in log_output
|
||||
Loading…
Add table
Reference in a new issue