fix(chat): 防止在生成回复时触发消息打断
通过在聊天流上下文中引入 `is_replying` 状态标志,解决了在LLM生成回复期间可能被新消息错误打断的问题。 - 在调用LLM生成内容前将 `is_replying` 设置为 `True`。 - 在消息打断检查逻辑中,如果 `is_replying` 为 `True` 则跳过检查。 - 使用 `finally` 块确保无论生成成功或失败,`is_replying` 状态都会被重置为 `False`。 这确保了回复生成的原子性,防止了因用户快速连续发送消息而导致的自我打断。
This commit is contained in:
@@ -52,6 +52,7 @@ class StreamContext(BaseDataModel):
|
||||
priority_mode: str | None = None
|
||||
priority_info: dict | None = None
|
||||
triggering_user_id: str | None = None # 触发当前聊天流的用户ID
|
||||
is_replying: bool = False # 是否正在生成回复
|
||||
|
||||
def add_action_to_message(self, message_id: str, action: str):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user