Update OpenAIRealtimeLLMService to work with LLMContext and LLMContextAggregatorPair

This commit is contained in:
Paul Kompfner
2025-10-01 10:18:07 -04:00
parent a2c69fbd8b
commit 0dac7f7e48
2 changed files with 16 additions and 13 deletions

View File

@@ -6,8 +6,8 @@
"""OpenAI Realtime LLM adapter for Pipecat.""" """OpenAI Realtime LLM adapter for Pipecat."""
import copy
import json import json
from copy import copy
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Dict, List, Optional, TypedDict from typing import Any, Dict, List, Optional, TypedDict
@@ -75,7 +75,7 @@ class OpenAIRealtimeLLMAdapter(BaseLLMAdapter):
Returns: Returns:
List of messages in a format ready for logging about OpenAI Realtime. List of messages in a format ready for logging about OpenAI Realtime.
""" """
raise NotImplementedError("Universal LLMContext is not yet supported for OpenAI Realtime.") return self._from_universal_context_messages(self.get_messages(context)).messages
@dataclass @dataclass
class ConvertedMessages: class ConvertedMessages:

View File

@@ -9,6 +9,7 @@
import base64 import base64
import json import json
import time import time
import traceback
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
@@ -475,17 +476,18 @@ class OpenAIRealtimeLLMService(LLMService):
async def _update_settings(self): async def _update_settings(self):
settings = self._session_properties settings = self._session_properties
adapter: OpenAIRealtimeLLMAdapter = self.get_llm_adapter() if self._context:
llm_invocation_params = adapter.get_llm_invocation_params(self._context) adapter: OpenAIRealtimeLLMAdapter = self.get_llm_adapter()
llm_invocation_params = adapter.get_llm_invocation_params(self._context)
# tools given in the context override the tools in the session properties # tools given in the context override the tools in the session properties
if llm_invocation_params["tools"]: if llm_invocation_params["tools"]:
settings.tools = llm_invocation_params["tools"] settings.tools = llm_invocation_params["tools"]
# instructions in the context come from an initial "system" message in the # instructions in the context come from an initial "system" message in the
# messages list, and override instructions in the session properties # messages list, and override instructions in the session properties
if llm_invocation_params["system_instruction"]: if llm_invocation_params["system_instruction"]:
settings.instructions = llm_invocation_params["system_instruction"] settings.instructions = llm_invocation_params["system_instruction"]
await self.send_client_event(events.SessionUpdateEvent(session=settings)) await self.send_client_event(events.SessionUpdateEvent(session=settings))
@@ -790,10 +792,11 @@ class OpenAIRealtimeLLMService(LLMService):
self._run_llm_when_api_session_ready = True self._run_llm_when_api_session_ready = True
return return
adapter: OpenAIRealtimeLLMAdapter = self.get_llm_adapter()
# Configure the LLM for this session if needed # Configure the LLM for this session if needed
if self._llm_needs_conversation_setup: if self._llm_needs_conversation_setup:
# Send initial messages # Send initial messages
adapter: OpenAIRealtimeLLMAdapter = self.get_llm_adapter()
llm_invocation_params = adapter.get_llm_invocation_params(self._context) llm_invocation_params = adapter.get_llm_invocation_params(self._context)
messages = llm_invocation_params["messages"] messages = llm_invocation_params["messages"]
for item in messages: for item in messages:
@@ -807,7 +810,7 @@ class OpenAIRealtimeLLMService(LLMService):
# We're done configuring the LLM for this session # We're done configuring the LLM for this session
self._llm_needs_conversation_setup = False self._llm_needs_conversation_setup = False
logger.debug(f"Creating response: {self._context.get_messages_for_logging()}") logger.debug(f"Creating response: {adapter.get_messages_for_logging(self._context)}")
await self.push_frame(LLMFullResponseStartFrame()) await self.push_frame(LLMFullResponseStartFrame())
await self.start_processing_metrics() await self.start_processing_metrics()