From 3d5f640bab02771fca3d1d2eff978a5f402ca947 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Wed, 8 Jan 2025 18:14:29 -0500 Subject: [PATCH] Include deprecation warnings for LLMUserResponseAggregator and LLMAssistantResponseAggregator --- CHANGELOG.md | 2 +- .../foundational/07p-interruptible-krisp.py | 16 ++++++---------- examples/foundational/21-tavus-layer.py | 16 ++++++---------- .../processors/aggregators/llm_response.py | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3545b0744..a7f83b67e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -458,7 +458,7 @@ async def on_audio_data(processor, audio, sample_rate, num_channels): ### Deprecated - `LLMUserResponseAggregator` and `LLMAssistantResponseAggregator` are - mostly deprecated, use `OpenAILLMContext` instead. + deprecated. Use `OpenAILLMContext` instead. - The `vad` package is now deprecated and `audio.vad` should be used instead. The `avd` package will get removed in a future release. diff --git a/examples/foundational/07p-interruptible-krisp.py b/examples/foundational/07p-interruptible-krisp.py index dfc085f8f..959eeb636 100644 --- a/examples/foundational/07p-interruptible-krisp.py +++ b/examples/foundational/07p-interruptible-krisp.py @@ -14,14 +14,10 @@ from loguru import logger from runner import configure from pipecat.audio.filters.krisp_filter import KrispFilter -from pipecat.frames.frames import LLMMessagesFrame from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask -from pipecat.processors.aggregators.llm_response import ( - LLMAssistantResponseAggregator, - LLMUserResponseAggregator, -) +from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext from pipecat.services.deepgram import DeepgramSTTService, DeepgramTTSService from pipecat.services.openai import OpenAILLMService from pipecat.transports.services.daily import DailyParams, DailyTransport @@ -63,18 +59,18 @@ async def main(): }, ] - tma_in = LLMUserResponseAggregator(messages) - tma_out = LLMAssistantResponseAggregator(messages) + context = OpenAILLMContext(messages) + context_aggregator = llm.create_context_aggregator(context) pipeline = Pipeline( [ transport.input(), # Transport user input stt, # STT - tma_in, # User responses + context_aggregator.user(), # User responses llm, # LLM tts, # TTS transport.output(), # Transport bot output - tma_out, # Assistant spoken responses + context_aggregator.assistant(), # Assistant spoken responses ] ) @@ -84,7 +80,7 @@ async def main(): async def on_first_participant_joined(transport, participant): # Kick off the conversation. messages.append({"role": "system", "content": "Please introduce yourself to the user."}) - await task.queue_frames([LLMMessagesFrame(messages)]) + await task.queue_frames([context_aggregator.user().get_context_frame()]) runner = PipelineRunner() diff --git a/examples/foundational/21-tavus-layer.py b/examples/foundational/21-tavus-layer.py index f985bfba1..47c4dac96 100644 --- a/examples/foundational/21-tavus-layer.py +++ b/examples/foundational/21-tavus-layer.py @@ -14,14 +14,10 @@ from dotenv import load_dotenv from loguru import logger from pipecat.audio.vad.silero import SileroVADAnalyzer -from pipecat.frames.frames import LLMMessagesFrame from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask -from pipecat.processors.aggregators.llm_response import ( - LLMAssistantResponseAggregator, - LLMUserResponseAggregator, -) +from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext from pipecat.services.cartesia import CartesiaTTSService from pipecat.services.deepgram import DeepgramSTTService from pipecat.services.openai import OpenAILLMService @@ -74,19 +70,19 @@ async def main(): }, ] - tma_in = LLMUserResponseAggregator(messages) - tma_out = LLMAssistantResponseAggregator(messages) + context = OpenAILLMContext(messages) + context_aggregator = llm.create_context_aggregator(context) pipeline = Pipeline( [ transport.input(), # Transport user input stt, # STT - tma_in, # User responses + context_aggregator.user(), # User responses llm, # LLM tts, # TTS tavus, # Tavus output layer transport.output(), # Transport bot output - tma_out, # Assistant spoken responses + context_aggregator.assistant(), # Assistant spoken responses ] ) @@ -120,7 +116,7 @@ async def main(): messages.append( {"role": "system", "content": "Please introduce yourself to the user."} ) - await task.queue_frames([LLMMessagesFrame(messages)]) + await task.queue_frames([context_aggregator.user().get_context_frame()]) runner = PipelineRunner() diff --git a/src/pipecat/processors/aggregators/llm_response.py b/src/pipecat/processors/aggregators/llm_response.py index 349f7290c..067c39e9d 100644 --- a/src/pipecat/processors/aggregators/llm_response.py +++ b/src/pipecat/processors/aggregators/llm_response.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: BSD 2-Clause License # +import warnings from typing import List, Type from pipecat.frames.frames import ( @@ -28,6 +29,16 @@ from pipecat.processors.aggregators.openai_llm_context import ( from pipecat.processors.frame_processor import FrameDirection, FrameProcessor +def _deprecation_warning(old_class: str): + warnings.warn( + f"{old_class} is deprecated and will be removed in a future version. " + f"Instead, create an OpenAILLMContext and use llm.create_context_aggregator(context) " + f"to get context-aware aggregators via .user() and .assistant() methods.", + DeprecationWarning, + stacklevel=2, + ) + + class LLMResponseAggregator(FrameProcessor): def __init__( self, @@ -175,7 +186,10 @@ class LLMResponseAggregator(FrameProcessor): class LLMAssistantResponseAggregator(LLMResponseAggregator): + """DEPRECATED: Create an OpenAILLMContext and use llm.create_context_aggregator(context).assistant() instead.""" + def __init__(self, messages: List[dict] = []): + _deprecation_warning("LLMAssistantResponseAggregator") super().__init__( messages=messages, role="assistant", @@ -187,7 +201,10 @@ class LLMAssistantResponseAggregator(LLMResponseAggregator): class LLMUserResponseAggregator(LLMResponseAggregator): + """DEPRECATED: Create an OpenAILLMContext and use llm.create_context_aggregator(context).user() instead.""" + def __init__(self, messages: List[dict] = []): + _deprecation_warning("LLMUserResponseAggregator") super().__init__( messages=messages, role="user",