refactor(responses bridge): build system text extraction without a mutable list

_extract_system_text accumulated text parts with append; build the joined
text from an immutable tuple comprehension instead, keeping the same
semantics (a non-text or cache-bearing block still falls back to an input
item).

Signed-off-by: rain <1504569896@qq.com>
This commit is contained in:
rain 2026-09-21 00:10:24 +00:00 • committed by Rainmemery
parent 73b5ecf61f
commit 8330be3221

View file

@ -515,15 +515,16 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
if isinstance(content, str):
return content
if isinstance(content, list):
text_parts: list[str] = []
for block in content:
if not isinstance(block, dict) or block.get("type") != "text":
return None
if "cache_control" in block:
return None
text = block.get("text")
if isinstance(text, str):
text_parts.append(text)
if any(
not isinstance(block, dict)
or block.get("type") != "text"
or "cache_control" in block
for block in content
):
return None
text_parts: Final = tuple(
block["text"] for block in content if isinstance(block.get("text"), str)
)
return "".join(text_parts) if text_parts else None
return None