From 2708dcf7b50c058e50ebf9c28f2814df3b27db37 Mon Sep 17 00:00:00 2001 From: Moishe Lettvin Date: Mon, 4 Mar 2024 14:07:49 -0500 Subject: [PATCH] Remove conversation wrapper --- src/dailyai/conversation_wrappers.py | 77 ------------------- src/examples/foundational/07-interruptible.py | 3 - 2 files changed, 80 deletions(-) delete mode 100644 src/dailyai/conversation_wrappers.py diff --git a/src/dailyai/conversation_wrappers.py b/src/dailyai/conversation_wrappers.py deleted file mode 100644 index c5caf7fa0..000000000 --- a/src/dailyai/conversation_wrappers.py +++ /dev/null @@ -1,77 +0,0 @@ -import asyncio -import copy -import functools -from typing import AsyncGenerator, Awaitable, Callable -from dailyai.pipeline.aggregators import LLMAssistantContextAggregator, LLMContextAggregator, LLMUserContextAggregator -from dailyai.pipeline.frames import EndStreamQueueFrame, QueueFrame, TranscriptionQueueFrame - - -class InterruptibleConversationWrapper: - - def __init__( - self, - frame_generator: Callable[[], AsyncGenerator[QueueFrame, None]], - runner: Callable[ - [str, LLMContextAggregator, LLMContextAggregator], Awaitable[None] - ], - interrupt: Callable[[], None], - my_participant_id: str | None, - llm_messages: list[dict[str, str]], - llm_context_aggregator_in=LLMUserContextAggregator, - llm_context_aggregator_out=LLMAssistantContextAggregator, - delay_before_speech_seconds: float = 1.0, - ): - self._frame_generator: Callable[[], AsyncGenerator[QueueFrame, None]] = frame_generator - self._runner: Callable[ - [str, LLMContextAggregator, LLMContextAggregator], Awaitable[None] - ] = runner - self._interrupt: Callable[[], None] = interrupt - self._my_participant_id = my_participant_id - self._messages: list[dict[str, str]] = llm_messages - self._delay_before_speech_seconds = delay_before_speech_seconds - self._llm_context_aggregator_in = llm_context_aggregator_in - self._llm_context_aggregator_out = llm_context_aggregator_out - - self._current_phrase = "" - - def update_messages(self, new_messages: list[dict[str, str]], task: asyncio.Task | None): - if task: - if not task.cancelled(): - self._current_phrase = "" - self._messages = new_messages - - async def speak_after_delay(self, user_speech, messages): - await asyncio.sleep(self._delay_before_speech_seconds) - tma_in = self._llm_context_aggregator_in( - messages, self._my_participant_id, complete_sentences=False - ) - tma_out = self._llm_context_aggregator_out( - messages, self._my_participant_id - ) - - await self._runner(user_speech, tma_in, tma_out) - - async def run_conversation(self): - current_response_task = None - - async for frame in self._frame_generator(): - if isinstance(frame, EndStreamQueueFrame): - break - elif not isinstance(frame, TranscriptionQueueFrame): - continue - - if frame.participantId == self._my_participant_id: - continue - - if current_response_task: - current_response_task.cancel() - self._interrupt() - - self._current_phrase += " " + frame.text - current_llm_messages = copy.deepcopy(self._messages) - current_response_task = asyncio.create_task( - self.speak_after_delay(self._current_phrase, current_llm_messages) - ) - current_response_task.add_done_callback( - functools.partial(self.update_messages, current_llm_messages) - ) diff --git a/src/examples/foundational/07-interruptible.py b/src/examples/foundational/07-interruptible.py index 59c5c752c..6698230fa 100644 --- a/src/examples/foundational/07-interruptible.py +++ b/src/examples/foundational/07-interruptible.py @@ -1,15 +1,12 @@ import asyncio import aiohttp import os -from dailyai.conversation_wrappers import InterruptibleConversationWrapper from dailyai.pipeline.aggregators import LLMAssistantContextAggregator, LLMUserContextAggregator -from dailyai.pipeline.frames import StartStreamQueueFrame, TextQueueFrame from dailyai.pipeline.pipeline import Pipeline from dailyai.services.ai_services import FrameLogger from dailyai.services.daily_transport_service import DailyTransportService from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService -from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService from examples.foundational.support.runner import configure