Fix IVRNavigator to push AggregatedTextFrame when switching to conversation mode
This commit is contained in:
1
changelog/3604.fixed.md
Normal file
1
changelog/3604.fixed.md
Normal file
@@ -0,0 +1 @@
|
||||
- Fixed an issue in the `IVRNavigator` where the `TextFrame`s pushed had incorrect spacing. Now, the internal `IVRProcessor` pushes `AggregatedTextFrame`s when in conversation mode. This allows for controlling spacing of the outputted, aggregated text.
|
||||
@@ -18,6 +18,7 @@ from loguru import logger
|
||||
from pipecat.audio.dtmf.types import KeypadEntry
|
||||
from pipecat.audio.vad.vad_analyzer import VADParams
|
||||
from pipecat.frames.frames import (
|
||||
AggregatedTextFrame,
|
||||
EndFrame,
|
||||
Frame,
|
||||
LLMContextFrame,
|
||||
@@ -153,13 +154,19 @@ class IVRProcessor(FrameProcessor):
|
||||
# Process text through the pattern aggregator
|
||||
async for result in self._aggregator.aggregate(frame.text):
|
||||
# Push aggregated text that doesn't contain XML patterns
|
||||
await self.push_frame(LLMTextFrame(result.text), direction)
|
||||
await self.push_frame(
|
||||
AggregatedTextFrame(text=result.text, aggregated_by=result.type),
|
||||
direction,
|
||||
)
|
||||
|
||||
elif isinstance(frame, (LLMFullResponseEndFrame, EndFrame)):
|
||||
# Flush any remaining text from the aggregator
|
||||
remaining = await self._aggregator.flush()
|
||||
if remaining:
|
||||
await self.push_frame(LLMTextFrame(remaining.text), direction)
|
||||
await self.push_frame(
|
||||
AggregatedTextFrame(text=remaining.text, aggregated_by=remaining.type),
|
||||
direction,
|
||||
)
|
||||
# Push the end frame
|
||||
await self.push_frame(frame, direction)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from unittest.mock import AsyncMock
|
||||
from pipecat.audio.vad.vad_analyzer import VADParams
|
||||
from pipecat.extensions.ivr.ivr_navigator import IVRProcessor
|
||||
from pipecat.frames.frames import (
|
||||
AggregatedTextFrame,
|
||||
LLMFullResponseEndFrame,
|
||||
LLMMessagesUpdateFrame,
|
||||
LLMTextFrame,
|
||||
@@ -339,7 +340,7 @@ class TestIVRNavigation(unittest.IsolatedAsyncioTestCase):
|
||||
]
|
||||
|
||||
expected_down_frames = [
|
||||
LLMTextFrame, # Should pass through unchanged
|
||||
AggregatedTextFrame, # LLMTextFrames aggregrated and converted to AggregatedTextFrame
|
||||
LLMFullResponseEndFrame,
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user