diff --git a/src/pipecat/services/anthropic/llm.py b/src/pipecat/services/anthropic/llm.py index 755ca6400..5981d3e50 100644 --- a/src/pipecat/services/anthropic/llm.py +++ b/src/pipecat/services/anthropic/llm.py @@ -403,6 +403,11 @@ class AnthropicLLMService(LLMService): context, enable_prompt_caching=self._settings.enable_prompt_caching ) if self._system_instruction: + if params["system"] is not NOT_GIVEN: + logger.warning( + f"{self}: Both system_instruction and a system message in context are" + " set. Using system_instruction." + ) params["system"] = self._system_instruction return params diff --git a/src/pipecat/services/aws/llm.py b/src/pipecat/services/aws/llm.py index 31f8085bc..e465ae460 100644 --- a/src/pipecat/services/aws/llm.py +++ b/src/pipecat/services/aws/llm.py @@ -1025,6 +1025,11 @@ class AWSBedrockLLMService(LLMService): adapter: AWSBedrockLLMAdapter = self.get_llm_adapter() params: AWSBedrockLLMInvocationParams = adapter.get_llm_invocation_params(context) if self._system_instruction: + if params["system"]: + logger.warning( + f"{self}: Both system_instruction and a system message in context are" + " set. Using system_instruction." + ) params["system"] = [{"text": self._system_instruction}] return params diff --git a/src/pipecat/services/openai/base_llm.py b/src/pipecat/services/openai/base_llm.py index ed012d0df..dfef1ae90 100644 --- a/src/pipecat/services/openai/base_llm.py +++ b/src/pipecat/services/openai/base_llm.py @@ -292,9 +292,14 @@ class BaseOpenAILLMService(LLMService): params.update(self._settings.extra) - # Prepend system instruction if set + # Prepend system instruction from constructor, replacing any context system message if self._system_instruction: messages = params.get("messages", []) + if messages and messages[0].get("role") == "system": + logger.warning( + f"{self}: Both system_instruction and a system message in context are set." + " Using system_instruction." + ) params["messages"] = [ {"role": "system", "content": self._system_instruction} ] + messages