3232from pipecat .pipeline .runner import PipelineRunner
3333from pipecat .pipeline .task import PipelineParams , PipelineTask
3434from pipecat .processors .aggregators .llm_context import LLMContext
35+ from pipecat .processors .aggregators .llm_response import LLMAssistantAggregatorParams
3536from pipecat .processors .aggregators .llm_response_universal import LLMContextAggregatorPair
3637from pipecat .processors .frameworks .rtvi import RTVIObserver , RTVIProcessor
3738from pipecat .processors .transcript_processor import TranscriptProcessor
@@ -57,8 +58,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
5758
5859 # Text-to-Speech service
5960 # Text aggregator to handle code snippets
60- aggregator = PatternPairAggregator ()
61- aggregator .add_pattern_pair (
61+ tts_aggregator = PatternPairAggregator ()
62+ tts_aggregator .add_pattern_pair (
6263 pattern_id = "code" ,
6364 start_pattern = "<code>" ,
6465 end_pattern = "</code>" ,
@@ -68,7 +69,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
6869 tts = ElevenLabsTTSService (
6970 api_key = os .getenv ("ELEVENLABS_API_KEY" ),
7071 voice_id = os .getenv ("ELEVENLABS_VOICE_ID" ),
71- text_aggregator = aggregator ,
72+ text_aggregator = tts_aggregator ,
7273 skip_aggregator_types = ["code" ],
7374 )
7475
@@ -82,8 +83,21 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
8283 },
8384 ]
8485
86+ # LLM aggregator context
87+ # Text aggregator to handle code snippets when the tts is skipped
88+ llm_aggregator = PatternPairAggregator ()
89+ llm_aggregator .add_pattern_pair (
90+ pattern_id = "code" ,
91+ start_pattern = "<code>" ,
92+ end_pattern = "</code>" ,
93+ type = "code" ,
94+ action = MatchAction .AGGREGATE ,
95+ )
8596 context = LLMContext (messages )
86- context_aggregator = LLMContextAggregatorPair (context )
97+ context_aggregator = LLMContextAggregatorPair (
98+ context = context ,
99+ assistant_params = LLMAssistantAggregatorParams (llm_text_aggregator = llm_aggregator ),
100+ )
87101
88102 # Transcription processor
89103 transcript_processor = TranscriptProcessor ()
@@ -142,6 +156,9 @@ async def on_transcript_update(processor: TranscriptProcessor, frame: Transcript
142156 @rtvi .event_handler ("on_client_message" )
143157 async def on_message (rtvi , msg ):
144158 print ("RTVI junk message:" , msg .type , msg .data )
159+ if msg .type == "get_context" :
160+ context = context_aggregator .assistant ().messages
161+ print (f"context: { context } " )
145162
146163 runner = PipelineRunner (handle_sigint = runner_args .handle_sigint )
147164
0 commit comments