diff --git a/src/pipecat/pipeline/llm_switcher.py b/src/pipecat/pipeline/llm_switcher.py index d1906119a..a15e0a3c2 100644 --- a/src/pipecat/pipeline/llm_switcher.py +++ b/src/pipecat/pipeline/llm_switcher.py @@ -30,25 +30,17 @@ class LLMSwitcher(ServiceSwitcher[StrategyType]): """Get the currently active LLM, if any.""" return self.strategy.active_service - async def run_inference( - self, context: LLMContext, system_instruction: Optional[str] = None - ) -> Optional[str]: + async def run_inference(self, context: LLMContext) -> Optional[str]: """Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context, using the currently active LLM. Args: context: The LLM context containing conversation history. - system_instruction: Optional system instruction to guide the LLM's - behavior. You could also (again, optionally) provide a system - instruction directly in the context. If both are provided, the - one in the context takes precedence. Returns: The LLM's response as a string, or None if no response is generated. """ if self.active_llm: - return await self.active_llm.run_inference( - context=context, system_instruction=system_instruction - ) + return await self.active_llm.run_inference(context=context) return None def register_function( diff --git a/src/pipecat/services/anthropic/llm.py b/src/pipecat/services/anthropic/llm.py index ad858e596..013c3f155 100644 --- a/src/pipecat/services/anthropic/llm.py +++ b/src/pipecat/services/anthropic/llm.py @@ -228,17 +228,11 @@ class AnthropicLLMService(LLMService): response = await api_call(**params) return response - async def run_inference( - self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None - ) -> Optional[str]: + async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]: """Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context. Args: context: The LLM context containing conversation history. - system_instruction: Optional system instruction to guide the LLM's - behavior. You could also (again, optionally) provide a system - instruction directly in the context. If both are provided, the - one in the context takes precedence. Returns: The LLM's response as a string, or None if no response is generated. @@ -255,7 +249,7 @@ class AnthropicLLMService(LLMService): else: context = AnthropicLLMContext.upgrade_to_anthropic(context) messages = context.messages - system = getattr(context, "system", None) or system_instruction or NOT_GIVEN + system = getattr(context, "system", NOT_GIVEN) # LLM completion response = await self._client.messages.create( diff --git a/src/pipecat/services/aws/llm.py b/src/pipecat/services/aws/llm.py index 45cf063d8..5eefaa35f 100644 --- a/src/pipecat/services/aws/llm.py +++ b/src/pipecat/services/aws/llm.py @@ -792,17 +792,11 @@ class AWSBedrockLLMService(LLMService): """ return True - async def run_inference( - self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None - ) -> Optional[str]: + async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]: """Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context. Args: context: The LLM context containing conversation history. - system_instruction: Optional system instruction to guide the LLM's - behavior. You could also (again, optionally) provide a system - instruction directly in the context. If both are provided, the - one in the context takes precedence. Returns: The LLM's response as a string, or None if no response is generated. @@ -822,7 +816,7 @@ class AWSBedrockLLMService(LLMService): else: context = AWSBedrockLLMContext.upgrade_to_bedrock(context) messages = context.messages - system = getattr(context, "system", None) or system_instruction + system = getattr(context, "system", None) # Determine if we're using Claude or Nova based on model ID model_id = self.model_name diff --git a/src/pipecat/services/google/llm.py b/src/pipecat/services/google/llm.py index 2dfdf0fbf..63066c45a 100644 --- a/src/pipecat/services/google/llm.py +++ b/src/pipecat/services/google/llm.py @@ -733,17 +733,11 @@ class GoogleLLMService(LLMService): def _create_client(self, api_key: str, http_options: Optional[HttpOptions] = None): self._client = genai.Client(api_key=api_key, http_options=http_options) - async def run_inference( - self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None - ) -> Optional[str]: + async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]: """Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context. Args: context: The LLM context containing conversation history. - system_instruction: Optional system instruction to guide the LLM's - behavior. You could also (again, optionally) provide a system - instruction directly in the context. If both are provided, the - one in the context takes precedence. Returns: The LLM's response as a string, or None if no response is generated. @@ -758,7 +752,7 @@ class GoogleLLMService(LLMService): else: context = GoogleLLMContext.upgrade_to_google(context) messages = context.messages - system = getattr(context, "system_message", None) or system_instruction + system = getattr(context, "system_message", None) generation_config = GenerateContentConfig(system_instruction=system) diff --git a/src/pipecat/services/llm_service.py b/src/pipecat/services/llm_service.py index a44f7ab26..502570a83 100644 --- a/src/pipecat/services/llm_service.py +++ b/src/pipecat/services/llm_service.py @@ -195,18 +195,13 @@ class LLMService(AIService): """ return self._adapter - async def run_inference( - self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None - ) -> Optional[str]: + async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]: """Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context. Must be implemented by subclasses. Args: context: The LLM context containing conversation history. - system_instruction: Optional system instruction to guide the LLM's - behavior. You could also (again, optionally) provide a system - instruction directly in the context. Returns: The LLM's response as a string, or None if no response is generated. diff --git a/src/pipecat/services/openai/base_llm.py b/src/pipecat/services/openai/base_llm.py index fa90b7cf4..b9b216441 100644 --- a/src/pipecat/services/openai/base_llm.py +++ b/src/pipecat/services/openai/base_llm.py @@ -245,16 +245,11 @@ class BaseOpenAILLMService(LLMService): params.update(self._settings["extra"]) return params - async def run_inference( - self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None - ) -> Optional[str]: + async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]: """Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context. Args: context: The LLM context containing conversation history. - system_instruction: Optional system instruction to guide the LLM's - behavior. You could also (again, optionally) provide a system - instruction directly in the context. Returns: The LLM's response as a string, or None if no response is generated.