Skip to content

修复:清空聊天记录前的发送按钮状态检查#127

Merged
CJackHwang merged 16 commits intoCJackHwang:devfrom
NyxJae:dev
Jun 4, 2025
Merged

修复:清空聊天记录前的发送按钮状态检查#127
CJackHwang merged 16 commits intoCJackHwang:devfrom
NyxJae:dev

Conversation

@NyxJae
Copy link
Contributor

@NyxJae NyxJae commented Jun 3, 2025

如注释所述,会有这种情况导致卡住,针对这种情况先停止ai回复再清空.
api_utils\request_processor.py:284-304

async def _clear_chat_history(req_id: str, page: AsyncPage, check_client_disconnected: Callable) -> None:
    """清空聊天记录"""
    from server import logger
    
    logger.info(f"[{req_id}] 开始清空聊天记录...")
    try:
        # 一般是使用流式代理时遇到,流式输出已结束,但页面上AI仍回复个不停,此时会锁住清空按钮,但页面仍是/new_chat,而跳过后续清空操作
        # 导致后续请求无法发出而卡住,故先检查并点击发送按钮(此时是停止功能)
        submit_button_locator = page.locator(SUBMIT_BUTTON_SELECTOR)
        try:
            logger.info(f"[{req_id}] 尝试检查发送按钮状态...")
            # 使用较短的超时时间(1秒),避免长时间阻塞,因为这不是清空流程的常见步骤
            await expect_async(submit_button_locator).to_be_enabled(timeout=1000)
            logger.info(f"[{req_id}] 发送按钮可用,尝试点击并等待1秒...")
            await submit_button_locator.click(timeout=CLICK_TIMEOUT_MS) # 使用已定义的 CLICK_TIMEOUT_MS
            await asyncio.sleep(1.0)
            logger.info(f"[{req_id}] 发送按钮点击并等待完成。")
        except Exception as e_submit:
            # 如果发送按钮不可用、超时或发生Playwright相关错误,记录日志并继续
            logger.info(f"[{req_id}] 发送按钮不可用或检查/点击时发生Playwright错误。符合预期,继续检查清空按钮。")

@NyxJae
Copy link
Contributor Author

NyxJae commented Jun 3, 2025

对于 #123 这个pr 应该也能起效

Copy link
Owner

@CJackHwang CJackHwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,既然你已经做了我今晚就不用再处理这个问题了哈哈哈

@CJackHwang CJackHwang self-assigned this Jun 4, 2025
@CJackHwang CJackHwang merged commit d66aa90 into CJackHwang:dev Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants