From d50922cdcd4977ef2469e63ee04d51f46ff37715 Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Fri, 15 Aug 2025 16:56:44 -0400 Subject: [PATCH] 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. --- src/pipecat/adapters/services/gemini_adapter.py | 7 +++++-- src/pipecat/services/google/llm.py | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pipecat/adapters/services/gemini_adapter.py b/src/pipecat/adapters/services/gemini_adapter.py index d078705c1..6b52010b5 100644 --- a/src/pipecat/adapters/services/gemini_adapter.py +++ b/src/pipecat/adapters/services/gemini_adapter.py @@ -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" diff --git a/src/pipecat/services/google/llm.py b/src/pipecat/services/google/llm.py index 6790a9485..bcaa79483 100644 --- a/src/pipecat/services/google/llm.py +++ b/src/pipecat/services/google/llm.py @@ -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"