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"