Merge pull request #162 from pipecat-ai/reset-before-pushing

processors: reset aggergator before pushing
This commit is contained in:
Aleix Conchillo Flaqué
2024-05-23 02:51:55 +08:00
committed by GitHub
2 changed files with 14 additions and 4 deletions

View File

@@ -117,12 +117,15 @@ class LLMResponseAggregator(FrameProcessor):
async def _push_aggregation(self):
if len(self._aggregation) > 0:
self._messages.append({"role": self._role, "content": self._aggregation})
# Reset our accumulator state. Reset it before pushing it down,
# otherwise if the tasks gets cancelled we won't be able to clear
# things up.
self._reset()
frame = LLMMessagesFrame(self._messages)
await self.push_frame(frame)
# Reset our accumulator state.
self._reset()
def _reset(self):
self._aggregation = ""
self._aggregating = False

View File

@@ -118,7 +118,14 @@ class ResponseAggregator(FrameProcessor):
async def _push_aggregation(self):
if len(self._aggregation) > 0:
await self.push_frame(TextFrame(self._aggregation.strip()))
frame = TextFrame(self._aggregation.strip())
# Reset our accumulator state. Reset it before pushing it down,
# otherwise if the tasks gets cancelled we won't be able to clear
# things up.
self._reset()
await self.push_frame(frame)
# Reset our accumulator state.
self._reset()