From a2b30961592f925577c9d3e76902d2c5a12e3e1a Mon Sep 17 00:00:00 2001 From: takatost Date: Sun, 17 Mar 2024 21:36:22 +0800 Subject: [PATCH] add text chunk subscribe for advanced chat blocking mode --- .../apps/advanced_chat/generate_task_pipeline.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/core/app/apps/advanced_chat/generate_task_pipeline.py b/api/core/app/apps/advanced_chat/generate_task_pipeline.py index 1d8558ee743ad7..9c78373d17a4a6 100644 --- a/api/core/app/apps/advanced_chat/generate_task_pipeline.py +++ b/api/core/app/apps/advanced_chat/generate_task_pipeline.py @@ -160,6 +160,22 @@ def _process_blocking_response(self) -> ChatbotAppBlockingResponse: self._save_message() return self._to_blocking_response() + elif isinstance(event, QueueTextChunkEvent): + delta_text = event.text + if delta_text is None: + continue + + if not self._is_stream_out_support( + event=event + ): + continue + + # handle output moderation chunk + should_direct_answer = self._handle_output_moderation_chunk(delta_text) + if should_direct_answer: + continue + + self._task_state.answer += delta_text else: continue