Update Google adapter to handle possibility of system message in standard format being provided as a list of text parts rather than just a string.

This commit is contained in:
Paul Kompfner
2025-08-15 16:56:44 -04:00
parent 47f5ca6265
commit d50922cdcd
2 changed files with 13 additions and 3 deletions

View File

@@ -238,8 +238,11 @@ class GeminiLLMAdapter(BaseLLMAdapter[GeminiLLMInvocationParams]):
content = message.get("content", [])
if role == "system":
# System instructions are returned as plain text
# TODO: here we've always assumed that system instructions are plain text...is that a safe assumption?
return content
if isinstance(content, str):
return content
elif isinstance(content, list):
# If content is a list, we assume it's a list of text parts, per the standard
return " ".join(part["text"] for part in content if part.get("type") == "text")
elif role == "assistant":
role = "model"

View File

@@ -421,7 +421,14 @@ class GoogleLLMContext(OpenAILLMContext):
role = message["role"]
content = message.get("content", [])
if role == "system":
self.system_message = content
# System instructions are returned as plain text
if isinstance(content, str):
self.system_message = content
elif isinstance(content, list):
# If content is a list, we assume it's a list of text parts, per the standard
self.system_message = " ".join(
part["text"] for part in content if part.get("type") == "text"
)
return None
elif role == "assistant":
role = "model"