fix(chat): 防止在生成回复时触发消息打断
通过在聊天流上下文中引入 `is_replying` 状态标志,解决了在LLM生成回复期间可能被新消息错误打断的问题。 - 在调用LLM生成内容前将 `is_replying` 设置为 `True`。 - 在消息打断检查逻辑中,如果 `is_replying` 为 `True` 则跳过检查。 - 使用 `finally` 块确保无论生成成功或失败,`is_replying` 状态都会被重置为 `False`。 这确保了回复生成的原子性,防止了因用户快速连续发送消息而导致的自我打断。
This commit is contained in:
@@ -365,6 +365,11 @@ class MessageManager:
|
||||
if not global_config.chat.interruption_enabled or not chat_stream or not message:
|
||||
return
|
||||
|
||||
# 检查是否正在回复
|
||||
if chat_stream.context_manager.context.is_replying:
|
||||
logger.info(f"聊天流 {chat_stream.stream_id} 正在回复中,跳过打断检查")
|
||||
return
|
||||
|
||||
# 检查是否为表情包消息
|
||||
if message.is_picid or message.is_emoji:
|
||||
logger.info(f"消息 {message.message_id} 是表情包或Emoji,跳过打断检查")
|
||||
|
||||
Reference in New Issue
Block a user