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", [])
|
content = message.get("content", [])
|
||||||
if role == "system":
|
if role == "system":
|
||||||
# System instructions are returned as plain text
|
# System instructions are returned as plain text
|
||||||
# TODO: here we've always assumed that system instructions are plain text...is that a safe assumption?
|
if isinstance(content, str):
|
||||||
return content
|
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":
|
elif role == "assistant":
|
||||||
role = "model"
|
role = "model"
|
||||||
|
|
||||||
|
|||||||
@@ -421,7 +421,14 @@ class GoogleLLMContext(OpenAILLMContext):
|
|||||||
role = message["role"]
|
role = message["role"]
|
||||||
content = message.get("content", [])
|
content = message.get("content", [])
|
||||||
if role == "system":
|
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
|
return None
|
||||||
elif role == "assistant":
|
elif role == "assistant":
|
||||||
role = "model"
|
role = "model"
|
||||||
|
|||||||
Reference in New Issue
Block a user