From 516586008c82357c7a5f02dea8f5bdfdc7b5a4aa Mon Sep 17 00:00:00 2001 From: kerry Date: Wed, 30 Sep 2026 17:21:59 +0000 Subject: [PATCH] refactor(caching): split Responses text-field collection to stay within complexity budget Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/caching/redis_semantic_cache.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/litellm/caching/redis_semantic_cache.py b/litellm/caching/redis_semantic_cache.py index cd0f0770eec..9968297f01d 100644 --- a/litellm/caching/redis_semantic_cache.py +++ b/litellm/caching/redis_semantic_cache.py @@ -297,16 +297,7 @@ class RedisSemanticCache(BaseCache): cls._collect_responses_input_text(content, prompt_parts) return - for text_key in ("text", "output", "input_text", "output_text"): - text_value = value.get(text_key) - if isinstance(text_value, (list, tuple)): - cls._collect_responses_input_text(text_value, prompt_parts) - return - if isinstance(text_value, str): - stripped_text = text_value.strip() - if stripped_text: - prompt_parts.append(stripped_text) - return + cls._collect_responses_text_fields(value, prompt_parts) return content = getattr(value, "content", None) @@ -322,6 +313,17 @@ class RedisSemanticCache(BaseCache): prompt_parts.append(stripped_text) return + @classmethod + def _collect_responses_text_fields(cls, value: dict, prompt_parts: list[str]) -> None: + for text_key in ("text", "output", "input_text", "output_text"): + text_value = value.get(text_key) + if isinstance(text_value, (list, tuple)): + cls._collect_responses_input_text(text_value, prompt_parts) + return + if isinstance(text_value, str) and (stripped_text := text_value.strip()): + prompt_parts.append(stripped_text) + return + @staticmethod def _function_call_as_prompt(value: object) -> object: if isinstance(value, dict) and value.get("type") == "function_call":