LLMUserContextAggregator: interrupt the bot if VAD happened a while back
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import unittest
|
||||
|
||||
from pipecat.frames.frames import (
|
||||
BotInterruptionFrame,
|
||||
InterimTranscriptionFrame,
|
||||
LLMFullResponseEndFrame,
|
||||
LLMFullResponseStartFrame,
|
||||
@@ -27,6 +28,8 @@ from pipecat.tests.utils import SleepFrame, run_test
|
||||
|
||||
AGGREGATION_TIMEOUT = 0.1
|
||||
AGGREGATION_SLEEP = 0.15
|
||||
BOT_INTERRUPTION_TIMEOUT = 0.2
|
||||
BOT_INTERRUPTION_SLEEP = 0.25
|
||||
|
||||
|
||||
class TestLLMUserContextAggreagator(unittest.IsolatedAsyncioTestCase):
|
||||
@@ -274,6 +277,72 @@ class TestLLMUserContextAggreagator(unittest.IsolatedAsyncioTestCase):
|
||||
)
|
||||
assert received_down[-1].context.messages[0]["content"] == "Hello Pipecat! How are you?"
|
||||
|
||||
async def test_t(self):
|
||||
context = OpenAILLMContext()
|
||||
aggregator = LLMUserContextAggregator(context, aggregation_timeout=AGGREGATION_TIMEOUT)
|
||||
frames_to_send = [
|
||||
TranscriptionFrame(text="Hello!", user_id="cat", timestamp=""),
|
||||
SleepFrame(sleep=AGGREGATION_SLEEP),
|
||||
]
|
||||
expected_down_frames = [OpenAILLMContextFrame]
|
||||
expected_up_frames = [BotInterruptionFrame]
|
||||
(received_down, _) = await run_test(
|
||||
aggregator,
|
||||
frames_to_send=frames_to_send,
|
||||
expected_down_frames=expected_down_frames,
|
||||
expected_up_frames=expected_up_frames,
|
||||
)
|
||||
assert received_down[-1].context.messages[0]["content"] == "Hello!"
|
||||
|
||||
async def test_it(self):
|
||||
context = OpenAILLMContext()
|
||||
aggregator = LLMUserContextAggregator(context, aggregation_timeout=AGGREGATION_TIMEOUT)
|
||||
frames_to_send = [
|
||||
InterimTranscriptionFrame(text="Hello ", user_id="cat", timestamp=""),
|
||||
TranscriptionFrame(text="Hello Pipecat!", user_id="cat", timestamp=""),
|
||||
SleepFrame(sleep=AGGREGATION_SLEEP),
|
||||
]
|
||||
expected_down_frames = [OpenAILLMContextFrame]
|
||||
expected_up_frames = [BotInterruptionFrame]
|
||||
(received_down, _) = await run_test(
|
||||
aggregator,
|
||||
frames_to_send=frames_to_send,
|
||||
expected_down_frames=expected_down_frames,
|
||||
expected_up_frames=expected_up_frames,
|
||||
)
|
||||
assert received_down[-1].context.messages[0]["content"] == "Hello Pipecat!"
|
||||
|
||||
async def test_sie_delay_it(self):
|
||||
context = OpenAILLMContext()
|
||||
aggregator = LLMUserContextAggregator(
|
||||
context,
|
||||
aggregation_timeout=AGGREGATION_TIMEOUT,
|
||||
bot_interruption_timeout=BOT_INTERRUPTION_TIMEOUT,
|
||||
)
|
||||
frames_to_send = [
|
||||
UserStartedSpeakingFrame(),
|
||||
InterimTranscriptionFrame(text="How ", user_id="cat", timestamp=""),
|
||||
SleepFrame(),
|
||||
UserStoppedSpeakingFrame(),
|
||||
SleepFrame(BOT_INTERRUPTION_SLEEP),
|
||||
InterimTranscriptionFrame(text="are you?", user_id="cat", timestamp=""),
|
||||
TranscriptionFrame(text="How are you?", user_id="cat", timestamp=""),
|
||||
SleepFrame(sleep=AGGREGATION_SLEEP),
|
||||
]
|
||||
expected_down_frames = [
|
||||
UserStartedSpeakingFrame,
|
||||
UserStoppedSpeakingFrame,
|
||||
OpenAILLMContextFrame,
|
||||
]
|
||||
expected_up_frames = [BotInterruptionFrame]
|
||||
(received_down, _) = await run_test(
|
||||
aggregator,
|
||||
frames_to_send=frames_to_send,
|
||||
expected_down_frames=expected_down_frames,
|
||||
expected_up_frames=expected_up_frames,
|
||||
)
|
||||
assert received_down[-1].context.messages[0]["content"] == "How are you?"
|
||||
|
||||
|
||||
class TestLLMAssistantContextAggreagator(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_empty(self):
|
||||
|
||||
Reference in New Issue
Block a user