From 3054329115adc9d5146054ecf6e4ef7e0de248a9 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Wed, 22 Oct 2025 01:08:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(emoji):=20=E4=B8=BA=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E5=8C=85=E6=8F=8F=E8=BF=B0=E7=94=9F=E6=88=90=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20VLM=20=E8=B0=83=E7=94=A8=E9=87=8D=E8=AF=95=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VLM 在生成表情包描述时,其 API 调用可能因网络波动或服务暂时不可用而失败。此前的实现会在首次调用失败后直接中断流程。 为了提高该功能的健壮性,本次提交引入了重试逻辑: - 在调用 VLM 生成描述时,最多尝试 3 次。 - 如果调用失败或返回空结果,将记录错误并等待 1 秒后重试。 - 这能有效应对暂时性网络或服务问题,显著提高表情包描述生成的成功率。 --- src/chat/emoji_system/emoji_manager.py | 34 +++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/chat/emoji_system/emoji_manager.py b/src/chat/emoji_system/emoji_manager.py index f0dafe346..ef841b7b5 100644 --- a/src/chat/emoji_system/emoji_manager.py +++ b/src/chat/emoji_system/emoji_manager.py @@ -970,14 +970,36 @@ class EmojiManager: if not image_base64_frames: raise RuntimeError("GIF表情包转换失败") prompt = "这是一个GIF动图表情包的关键帧。请用不超过250字,详细描述它的核心内容:1. 动态画面展现了什么变化?2. 它传达了什么核心情绪或玩的是什么梗?3. 通常在什么场景下使用?请确保描述既包含关键信息,又能充分展现其内涵。" - description, _ = await self.vlm.generate_response_for_image( - prompt, image_base64_frames, "jpeg", temperature=0.3, max_tokens=600 - ) + description = None + for i in range(3): + try: + logger.info(f"[VLM调用] 正在为GIF表情包生成描述 (第 {i+1}/3 次)...") + description, _ = await self.vlm.generate_response_for_image( + prompt, image_base64_frames, "jpeg", temperature=0.3, max_tokens=600 + ) + if description and description.strip(): + break + except Exception as e: + logger.error(f"VLM调用失败 (第 {i+1}/3 次): {e}", exc_info=True) + if i < 2: + logger.warning("表情包识别失败,将在1秒后重试...") + await asyncio.sleep(1) else: prompt = "这是一个表情包。请用不超过250字,详细描述它的核心内容:1. 画面描绘了什么?2. 它传达了什么核心情绪或玩的是什么梗?3. 通常在什么场景下使用?请确保描述既包含关键信息,又能充分展现其内涵。" - description, _ = await self.vlm.generate_response_for_image( - prompt, image_base64, image_format, temperature=0.3, max_tokens=600 - ) + description = None + for i in range(3): + try: + logger.info(f"[VLM调用] 正在为静态表情包生成描述 (第 {i+1}/3 次)...") + description, _ = await self.vlm.generate_response_for_image( + prompt, image_base64, image_format, temperature=0.3, max_tokens=600 + ) + if description and description.strip(): + break + except Exception as e: + logger.error(f"VLM调用失败 (第 {i+1}/3 次): {e}", exc_info=True) + if i < 2: + logger.warning("表情包识别失败,将在1秒后重试...") + await asyncio.sleep(1) # 4. 检查VLM描述是否有效 if not description or not description.strip():