test: handle blank redis semantic text fallbacks

This commit is contained in:
Dávid Balatoni 2026-05-19 23:57:52 +02:00
parent af948a1393
commit dcad0e0190
No known key found for this signature in database
2 changed files with 24 additions and 2 deletions

View file

@ -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:

View file

@ -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