mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
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>
This commit is contained in:
parent
8bf443997b
commit
516586008c
1 changed files with 12 additions and 10 deletions
|
|
@ -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":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue