Fix an issue where the UserIdleProcessor was blocking the EndFrame
This commit is contained in:
@@ -14,7 +14,7 @@ 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 EndFrame
|
from pipecat.frames.frames import EndFrame, TTSSpeakFrame
|
||||||
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
|
||||||
@@ -37,7 +37,7 @@ async def handle_user_idle(processor: UserIdleProcessor, retry_count: int) -> bo
|
|||||||
messages.append(
|
messages.append(
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
"content": "The user has been quiet for a while. Politely ask if they're still there.",
|
"content": "The user has been quiet for a while. Politely and concisely ask if they're still there.",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
await task.queue_frames([context_aggregator.user().get_context_frame()])
|
await task.queue_frames([context_aggregator.user().get_context_frame()])
|
||||||
@@ -47,20 +47,17 @@ async def handle_user_idle(processor: UserIdleProcessor, retry_count: int) -> bo
|
|||||||
messages.append(
|
messages.append(
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
"content": "The user is still inactive. Ask if they would like to continue the conversation.",
|
"content": "The user is still inactive. Concisely ask if they would like to continue the conversation.",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
await task.queue_frames([context_aggregator.user().get_context_frame()])
|
await task.queue_frames([context_aggregator.user().get_context_frame()])
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
# Third attempt: End the conversation
|
# Third attempt: End the conversation
|
||||||
messages.append(
|
await task.queue_frames(
|
||||||
{
|
[TTSSpeakFrame("It seems like you're busy right now. Have a nice day!")]
|
||||||
"role": "system",
|
|
||||||
"content": "The user has been inactive for too long. Politely end the conversation.",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
await task.queue_frames([context_aggregator.user().get_context_frame()])
|
await asyncio.sleep(3)
|
||||||
await task.queue_frame(EndFrame())
|
await task.queue_frame(EndFrame())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,10 @@ class UserIdleProcessor(FrameProcessor):
|
|||||||
await super().process_frame(frame, direction)
|
await super().process_frame(frame, direction)
|
||||||
|
|
||||||
# Check for end frames before processing
|
# Check for end frames before processing
|
||||||
if isinstance(frame, StartFrame):
|
if isinstance(frame, (EndFrame, CancelFrame)):
|
||||||
self._create_idle_task()
|
await self.push_frame(frame, direction) # Push the frame down the pipeline
|
||||||
elif isinstance(frame, (EndFrame, CancelFrame)):
|
await self._stop() # Then stop the idle task
|
||||||
await self._stop()
|
return # Return early since we're ending
|
||||||
|
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user