mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-24 09:25:21 +08:00
fix(wecombot): stop empty bubbles and premature stream close on blank final chunks (#2561)
* fix(pipeline): stop emitting empty final assistant messages An empty final streaming chunk was appended as an empty message chain when no sandbox outbox attachment was present, so platforms received an empty reply. Only append the chain when attachments were actually collected, and gate the "Call ..." tool notice behind output.misc.track-function-calls so it no longer becomes the final chunk of a stream. * fix(wecombot): do not close stream on a blank final snapshot A blank final snapshot closed the WeCom stream with an empty bubble and pushed the real answer into a separate reply_text message. Skip blank final snapshots and keep the session open so the following non-blank chunk can finalize it. Covered by new regression tests.
This commit is contained in:
@@ -687,6 +687,18 @@ class WecomBotWsClient:
|
||||
if not _re.sub(r'[\s]', '', next_content):
|
||||
return True
|
||||
|
||||
# A blank *final* snapshot would close the stream with an empty
|
||||
# bubble and strand the real answer in a separate reply_text
|
||||
# message. Keep the session open so a following non-blank chunk can
|
||||
# finalize it. The non-final branch above already skips blank
|
||||
# snapshots; final snapshots with earlier content are non-blank
|
||||
# here because ``next_content`` falls back to the previous content.
|
||||
if is_final:
|
||||
import re as _re
|
||||
|
||||
if not _re.sub(r'[\s\u200b\u200c\u200d\ufeff]', '', next_content):
|
||||
return True
|
||||
|
||||
# Generate feedback_id for final chunk
|
||||
feedback_id = ''
|
||||
if is_final:
|
||||
|
||||
@@ -161,26 +161,35 @@ class ResponseWrapper(stage.PipelineStage):
|
||||
elif (
|
||||
isinstance(result, provider_message.MessageChunk) and result.is_final and not result.tool_calls
|
||||
):
|
||||
# Final streaming chunk with no text content but
|
||||
# possibly carrying sandbox outbox attachments.
|
||||
# Final streaming chunk with no text content. It may still
|
||||
# carry sandbox outbox attachments; deliver them when present.
|
||||
# Otherwise emit nothing: appending an empty message chain
|
||||
# would be sent to the platform as an empty bubble and, on
|
||||
# streaming adapters (e.g. WeCom), would also close the
|
||||
# stream so the real answer arrives as a separate message.
|
||||
reply_chain = platform_message.MessageChain([])
|
||||
await self._append_outbound_attachments(query, reply_chain)
|
||||
query.resp_message_chain.append(reply_chain)
|
||||
yield entities.StageProcessResult(
|
||||
result_type=entities.ResultType.CONTINUE,
|
||||
new_query=query,
|
||||
)
|
||||
if len(reply_chain) > 0:
|
||||
query.resp_message_chain.append(reply_chain)
|
||||
yield entities.StageProcessResult(
|
||||
result_type=entities.ResultType.CONTINUE,
|
||||
new_query=query,
|
||||
)
|
||||
|
||||
if result.tool_calls is not None and len(result.tool_calls) > 0: # 有函数调用
|
||||
function_names = [tc.function.name for tc in result.tool_calls]
|
||||
|
||||
reply_text = f'Call {".".join(function_names)}...'
|
||||
|
||||
query.resp_message_chain.append(
|
||||
platform_message.MessageChain([platform_message.Plain(text=reply_text)])
|
||||
)
|
||||
|
||||
# Only surface the tool-call notice when the pipeline option
|
||||
# is enabled. Emitting it unconditionally would become the
|
||||
# final streaming chunk, closing the stream early and pushing
|
||||
# the real answer into a separate message.
|
||||
if query.pipeline_config['output']['misc']['track-function-calls']:
|
||||
query.resp_message_chain.append(
|
||||
platform_message.MessageChain([platform_message.Plain(text=reply_text)])
|
||||
)
|
||||
|
||||
event = events.NormalMessageResponded(
|
||||
launcher_type=query.launcher_type.value,
|
||||
launcher_id=query.launcher_id,
|
||||
|
||||
Reference in New Issue
Block a user