Switch questions
This commit is contained in:
@@ -10,11 +10,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
||||||
from pipecat.frames.frames import LLMMessagesFrame
|
from pipecat.frames.frames import BotSpeakingFrame, Frame, InputAudioRawFrame, LLMMessagesFrame, TTSAudioRawFrame, TextFrame, UserStoppedSpeakingFrame
|
||||||
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.openai_llm_context import OpenAILLMContext
|
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
|
||||||
|
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||||
from pipecat.services.cartesia import CartesiaTTSService
|
from pipecat.services.cartesia import CartesiaTTSService
|
||||||
from pipecat.services.openai import OpenAILLMService
|
from pipecat.services.openai import OpenAILLMService
|
||||||
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
||||||
@@ -30,6 +31,22 @@ load_dotenv(override=True)
|
|||||||
logger.remove(0)
|
logger.remove(0)
|
||||||
logger.add(sys.stderr, level="DEBUG")
|
logger.add(sys.stderr, level="DEBUG")
|
||||||
|
|
||||||
|
class DebugProcessor(FrameProcessor):
|
||||||
|
def __init__(self, name, **kwargs):
|
||||||
|
self._name = name
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||||
|
await super().process_frame(frame, direction)
|
||||||
|
if not (
|
||||||
|
isinstance(frame, InputAudioRawFrame)
|
||||||
|
or isinstance(frame, BotSpeakingFrame)
|
||||||
|
or isinstance(frame, TTSAudioRawFrame)
|
||||||
|
or isinstance(frame, TextFrame)
|
||||||
|
):
|
||||||
|
logger.debug(f"--- {self._name}: {frame} {direction}")
|
||||||
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@@ -64,10 +81,13 @@ async def main():
|
|||||||
context = OpenAILLMContext(messages)
|
context = OpenAILLMContext(messages)
|
||||||
context_aggregator = llm.create_context_aggregator(context)
|
context_aggregator = llm.create_context_aggregator(context)
|
||||||
|
|
||||||
|
dp = DebugProcessor("dp")
|
||||||
|
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(
|
||||||
[
|
[
|
||||||
transport.input(), # Transport user input
|
transport.input(), # Transport user input
|
||||||
context_aggregator.user(), # User responses
|
context_aggregator.user(), # User responses
|
||||||
|
dp,
|
||||||
llm, # LLM
|
llm, # LLM
|
||||||
tts, # TTS
|
tts, # TTS
|
||||||
transport.output(), # Transport bot output
|
transport.output(), # Transport bot output
|
||||||
|
|||||||
@@ -14,12 +14,19 @@ from loguru import logger
|
|||||||
from runner import configure
|
from runner import configure
|
||||||
|
|
||||||
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
||||||
from pipecat.frames.frames import (BotSpeakingFrame, EndFrame, Frame,
|
from pipecat.frames.frames import (
|
||||||
InputAudioRawFrame, StartInterruptionFrame,
|
BotSpeakingFrame,
|
||||||
StopInterruptionFrame, TextFrame,
|
EndFrame,
|
||||||
TranscriptionFrame, TTSAudioRawFrame,
|
Frame,
|
||||||
UserStartedSpeakingFrame,
|
InputAudioRawFrame,
|
||||||
UserStoppedSpeakingFrame)
|
StartInterruptionFrame,
|
||||||
|
StopInterruptionFrame,
|
||||||
|
TextFrame,
|
||||||
|
TranscriptionFrame,
|
||||||
|
TTSAudioRawFrame,
|
||||||
|
UserStartedSpeakingFrame,
|
||||||
|
UserStoppedSpeakingFrame,
|
||||||
|
)
|
||||||
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
|
||||||
@@ -56,11 +63,15 @@ async def main():
|
|||||||
(room_url, _) = await configure(session)
|
(room_url, _) = await configure(session)
|
||||||
|
|
||||||
transport = DailyTransport(
|
transport = DailyTransport(
|
||||||
room_url, None, "AI Bot", DailyParams(
|
room_url,
|
||||||
|
None,
|
||||||
|
"AI Bot",
|
||||||
|
DailyParams(
|
||||||
audio_out_enabled=True,
|
audio_out_enabled=True,
|
||||||
transcription_enabled=True,
|
transcription_enabled=True,
|
||||||
vad_enabled=True,
|
vad_enabled=True,
|
||||||
vad_analyzer=SileroVADAnalyzer(),)
|
vad_analyzer=SileroVADAnalyzer(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
tts = CartesiaTTSService(
|
tts = CartesiaTTSService(
|
||||||
api_key=os.getenv("CARTESIA_API_KEY"),
|
api_key=os.getenv("CARTESIA_API_KEY"),
|
||||||
@@ -88,8 +99,8 @@ async def main():
|
|||||||
[
|
[
|
||||||
# transport.input(),
|
# transport.input(),
|
||||||
context_aggregator.user(),
|
context_aggregator.user(),
|
||||||
dp,
|
|
||||||
llm,
|
llm,
|
||||||
|
dp,
|
||||||
tts,
|
tts,
|
||||||
transport.output(),
|
transport.output(),
|
||||||
context_aggregator.assistant(),
|
context_aggregator.assistant(),
|
||||||
@@ -106,7 +117,7 @@ async def main():
|
|||||||
async def on_first_participant_joined(transport, participant):
|
async def on_first_participant_joined(transport, participant):
|
||||||
participant_id = participant.get("info", {}).get("participantId", "")
|
participant_id = participant.get("info", {}).get("participantId", "")
|
||||||
|
|
||||||
# Create frames for 60 seconds
|
# Create frames for 600 seconds
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
while time.time() - start_time < 300:
|
while time.time() - start_time < 300:
|
||||||
elapsed_time = round(time.time() - start_time)
|
elapsed_time = round(time.time() - start_time)
|
||||||
@@ -123,7 +134,7 @@ async def main():
|
|||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
await task.queue_frame(
|
await task.queue_frame(
|
||||||
TranscriptionFrame("Tell a joke about dogs.", participant_id, time.time()),
|
TranscriptionFrame("Tell me more about your company.", participant_id, time.time()),
|
||||||
)
|
)
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
@@ -134,16 +145,13 @@ async def main():
|
|||||||
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
await task.queue_frame(
|
await task.queue_frame(
|
||||||
UserStoppedSpeakingFrame(),
|
UserStoppedSpeakingFrame(),
|
||||||
)
|
)
|
||||||
|
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
await task.queue_frame(
|
await task.queue_frame(StartInterruptionFrame())
|
||||||
StartInterruptionFrame()
|
|
||||||
)
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
await task.queue_frame(
|
await task.queue_frame(
|
||||||
@@ -153,7 +161,7 @@ async def main():
|
|||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
await task.queue_frame(
|
await task.queue_frame(
|
||||||
TranscriptionFrame("Tell a joke about cats.", participant_id, time.time()),
|
TranscriptionFrame("Give me a list of appointment dates.", participant_id, time.time()),
|
||||||
)
|
)
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
@@ -169,7 +177,6 @@ async def main():
|
|||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
await task.queue_frame(EndFrame())
|
await task.queue_frame(EndFrame())
|
||||||
|
|
||||||
|
|
||||||
# @transport.event_handler("on_first_participant_joined")
|
# @transport.event_handler("on_first_participant_joined")
|
||||||
# async def on_first_participant_joined(transport, participant):
|
# async def on_first_participant_joined(transport, participant):
|
||||||
# await transport.capture_participant_transcription(participant["id"])
|
# await transport.capture_participant_transcription(participant["id"])
|
||||||
|
|||||||
Reference in New Issue
Block a user