mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
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:
parent
73b5ecf61f
commit
8330be3221
1 changed files with 10 additions and 9 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue