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:
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user