diff --git a/litellm/caching/redis_semantic_cache.py b/litellm/caching/redis_semantic_cache.py index b067e0087f0..cce4b75795f 100644 --- a/litellm/caching/redis_semantic_cache.py +++ b/litellm/caching/redis_semantic_cache.py @@ -259,7 +259,7 @@ class RedisSemanticCache(BaseCache): stripped_text = text_value.strip() if stripped_text: prompt_parts.append(stripped_text) - return + return return content = getattr(value, "content", None) @@ -273,7 +273,7 @@ class RedisSemanticCache(BaseCache): stripped_text = text_value.strip() if stripped_text: prompt_parts.append(stripped_text) - return + return @staticmethod def _coerce_response_input_value(value: Any) -> Any: diff --git a/tests/test_litellm/caching/test_redis_semantic_cache.py b/tests/test_litellm/caching/test_redis_semantic_cache.py index dda25b0d3fd..c8be40b52ae 100644 --- a/tests/test_litellm/caching/test_redis_semantic_cache.py +++ b/tests/test_litellm/caching/test_redis_semantic_cache.py @@ -667,6 +667,28 @@ def test_redis_semantic_cache_prompt_extraction_returns_none_without_text(): ) +def test_redis_semantic_cache_prompt_extraction_skips_blank_dict_text_keys(): + from litellm.caching.redis_semantic_cache import RedisSemanticCache + + prompt = RedisSemanticCache._get_prompt_from_kwargs( + input={"text": " ", "input_text": "fallback prompt"} + ) + + assert prompt == "fallback prompt" + + +def test_redis_semantic_cache_prompt_extraction_skips_blank_object_text_keys(): + from litellm.caching.redis_semantic_cache import RedisSemanticCache + + class ResponseInput: + text = " " + input_text = "fallback prompt" + + prompt = RedisSemanticCache._get_prompt_from_kwargs(input=ResponseInput()) + + assert prompt == "fallback prompt" + + @pytest.mark.asyncio async def test_redis_semantic_cache_async_paths_use_responses_string_input(): from litellm.caching.redis_semantic_cache import RedisSemanticCache