Update OpenAIRealtimeLLMService to work with LLMContext and LLMContextAggregatorPair (cont'd).

Update 20b example to use new `LLMContext` pattern.
This commit is contained in:
Paul Kompfner
2025-10-21 11:14:40 -04:00
parent 19770b76b4
commit 46e97c57c2
2 changed files with 35 additions and 45 deletions

View File

@@ -13,11 +13,15 @@ from datetime import datetime
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.frames.frames import LLMRunFrame from pipecat.frames.frames import LLMRunFrame
from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.pipeline.task import PipelineParams, PipelineTask
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
from pipecat.processors.aggregators.openai_llm_context import ( from pipecat.processors.aggregators.openai_llm_context import (
OpenAILLMContext, OpenAILLMContext,
) )
@@ -97,14 +101,12 @@ async def load_conversation(params: FunctionCallParams):
asyncio.create_task(_reset()) asyncio.create_task(_reset())
tools = [ tools = ToolsSchema(
{ standard_tools=[
"type": "function", FunctionSchema(
"name": "get_current_weather", name="get_current_weather",
"description": "Get the current weather", description="Get the current weather",
"parameters": { properties={
"type": "object",
"properties": {
"location": { "location": {
"type": "string", "type": "string",
"description": "The city and state, e.g. San Francisco, CA", "description": "The city and state, e.g. San Francisco, CA",
@@ -115,45 +117,33 @@ tools = [
"description": "The temperature unit to use. Infer this from the users location.", "description": "The temperature unit to use. Infer this from the users location.",
}, },
}, },
"required": ["location", "format"], required=["location", "format"],
}, ),
}, FunctionSchema(
{ name="save_conversation",
"type": "function", description="Save the current conversatione. Use this function to persist the current conversation to external storage.",
"name": "save_conversation", properties={},
"description": "Save the current conversatione. Use this function to persist the current conversation to external storage.", required=[],
"parameters": { ),
"type": "object", FunctionSchema(
"properties": {}, name="get_saved_conversation_filenames",
"required": [], description="Get a list of saved conversation histories. Returns a list of filenames. Each filename includes a date and timestamp. Each file is conversation history that can be loaded into this session.",
}, properties={},
}, required=[],
{ ),
"type": "function", FunctionSchema(
"name": "get_saved_conversation_filenames", name="load_conversation",
"description": "Get a list of saved conversation histories. Returns a list of filenames. Each filename includes a date and timestamp. Each file is conversation history that can be loaded into this session.", description="Load a conversation history. Use this function to load a conversation history into the current session.",
"parameters": { properties={
"type": "object",
"properties": {},
"required": [],
},
},
{
"type": "function",
"name": "load_conversation",
"description": "Load a conversation history. Use this function to load a conversation history into the current session.",
"parameters": {
"type": "object",
"properties": {
"filename": { "filename": {
"type": "string", "type": "string",
"description": "The filename of the conversation history to load.", "description": "The filename of the conversation history to load.",
} }
}, },
"required": ["filename"], required=["filename"],
}, ),
}, ]
] )
# We store functions so objects (e.g. SileroVADAnalyzer) don't get # We store functions so objects (e.g. SileroVADAnalyzer) don't get
@@ -224,8 +214,8 @@ Remember, your responses should be short. Just one or two sentences, usually."""
llm.register_function("get_saved_conversation_filenames", get_saved_conversation_filenames) llm.register_function("get_saved_conversation_filenames", get_saved_conversation_filenames)
llm.register_function("load_conversation", load_conversation) llm.register_function("load_conversation", load_conversation)
context = OpenAILLMContext([], tools) context = LLMContext([], tools)
context_aggregator = llm.create_context_aggregator(context) context_aggregator = LLMContextAggregatorPair(context)
pipeline = Pipeline( pipeline = Pipeline(
[ [

View File

@@ -93,7 +93,7 @@ class OpenAIRealtimeLLMAdapter(BaseLLMAdapter):
# message as a single input. # message as a single input.
if not universal_context_messages: if not universal_context_messages:
return self.ConvertedMessages() return self.ConvertedMessages(messages=[])
messages = copy.deepcopy(universal_context_messages) messages = copy.deepcopy(universal_context_messages)
system_instruction = None system_instruction = None