Fix 'list' object has no attribute 'strip' error

Handle multimodal messages (images) where content is a list instead of string.
Skip non-string content in LLMLingua and code-aware compression transforms.
This commit is contained in:
chopratejas 2026-01-15 21:25:48 -08:00
parent e6370026bc
commit 07dfa9d25c
2 changed files with 9 additions and 2 deletions

View file

@ -1201,7 +1201,8 @@ class CodeAwareCompressor(Transform):
for message in messages:
content = message.get("content", "")
if not content:
# Skip empty or non-string content (multimodal messages with images)
if not content or not isinstance(content, str):
transformed_messages.append(message)
continue
@ -1266,7 +1267,8 @@ class CodeAwareCompressor(Transform):
for message in messages:
content = message.get("content", "")
if content:
# Only check string content (skip multimodal)
if content and isinstance(content, str):
detection = detect_content_type(content)
if detection.content_type == ContentType.SOURCE_CODE:
return True

View file

@ -430,6 +430,11 @@ class LLMLinguaCompressor(Transform):
role = message.get("role", "")
content = message.get("content", "")
# Skip non-string content (multimodal messages with images)
if not isinstance(content, str):
transformed_messages.append(message)
continue
# Compress tool results (highest value compression)
if role == "tool" and content:
result = self.compress(content, context=context, content_type="json")