Make end call tool can be cancelled
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from pipecat.frames.frames import LLMMessagesAppendFrame, UserImageRawFrame
|
||||
from pipecat.frames.frames import (
|
||||
InputTransportMessageFrame,
|
||||
LLMMessagesAppendFrame,
|
||||
UserImageRawFrame,
|
||||
)
|
||||
from pipecat.processors.frame_processor import FrameDirection
|
||||
from services.pipecat.call_lifecycle import CallEndCoordinator
|
||||
from services.pipecat.pipeline import _multimodal_user_input_frame
|
||||
from services.pipecat.processors import UserInputError, parse_user_input
|
||||
from services.pipecat.processors import (
|
||||
UserInputError,
|
||||
UserInputProcessor,
|
||||
parse_user_input,
|
||||
)
|
||||
|
||||
|
||||
class UserInputParserTests(unittest.TestCase):
|
||||
@@ -127,5 +138,40 @@ class UserInputParserTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class UserInputProcessorTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_interrupting_text_cancels_pending_end_before_mute_check(self):
|
||||
async def queue_end(_reason: str) -> None:
|
||||
self.fail("撤销后不应挂断")
|
||||
|
||||
call_end = CallEndCoordinator(queue_end)
|
||||
call_end.begin("user_goodbye", interruptible=True)
|
||||
processor = UserInputProcessor(
|
||||
should_ignore_input=lambda: not call_end.accepts_input,
|
||||
cancel_pending_end=call_end.cancel_pending_end,
|
||||
)
|
||||
processor._call_event_handler = AsyncMock()
|
||||
processor.broadcast_interruption = AsyncMock()
|
||||
|
||||
await processor.process_frame(
|
||||
InputTransportMessageFrame(
|
||||
message={
|
||||
"type": "user-input",
|
||||
"schema_version": 1,
|
||||
"input_id": "input_interrupt_end",
|
||||
"parts": [{"type": "input_text", "text": "等等"}],
|
||||
"options": {
|
||||
"run_immediately": True,
|
||||
"interrupt": True,
|
||||
},
|
||||
}
|
||||
),
|
||||
FrameDirection.DOWNSTREAM,
|
||||
)
|
||||
|
||||
self.assertFalse(call_end.ending)
|
||||
processor._call_event_handler.assert_awaited_once()
|
||||
processor.broadcast_interruption.assert_awaited_once()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user