From 0c7780f8f89324d2d1266e7010a11c3d19b1991a Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Mon, 22 Sep 2025 15:44:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=E6=A8=A1=E5=9E=8B=E8=B0=83=E7=94=A8=E5=B9=B6?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A7=86=E9=A2=91=E5=88=86=E6=9E=90=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 表情动作: 将模型调用从 `planner` 切换到 `utils`,以使用更合适的模型进行表情推荐。 - 视频分析: 增加检查逻辑,仅当分析成功且结果不为错误提示时,才将结果存入数据库,防止存储无效记录。 --- src/chat/utils/utils_video.py | 48 ++++++++++------------ src/plugins/built_in/emoji_plugin/emoji.py | 12 +++--- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/chat/utils/utils_video.py b/src/chat/utils/utils_video.py index 2f72af32b..5846dee79 100644 --- a/src/chat/utils/utils_video.py +++ b/src/chat/utils/utils_video.py @@ -233,34 +233,28 @@ class VideoAnalyzer: return {"summary": summary} finally: if os.path.exists(temp_path): - try: - os.remove(temp_path) - except Exception: # pragma: no cover - pass - except Exception as e: # pragma: no cover - return {"summary": f"❌ 处理失败: {e}"} + os.unlink(temp_path) - # ---- 缓存辅助 ---- - async def _get_cached(self, video_hash: str) -> Optional[str]: - try: - async with get_db_session() as session: # type: ignore - result = await session.execute(select(Videos).where(Videos.video_hash == video_hash)) # type: ignore - obj: Optional[Videos] = result.scalar_one_or_none() # type: ignore - if obj and obj.vlm_processed and obj.description: - # 更新使用次数 - try: - await session.execute( - update(Videos) - .where(Videos.id == obj.id) # type: ignore - .values(count=obj.count + 1 if obj.count is not None else 1) - ) - await session.commit() - except Exception: # pragma: no cover - await session.rollback() - return obj.description - except Exception: # pragma: no cover - pass - return None + # 保存分析结果到数据库(仅保存成功的结果) + if success and not result.startswith("❌"): + metadata = {"filename": filename, "file_size": len(video_bytes), "analysis_timestamp": time.time()} + self._store_video_result(video_hash=video_hash, description=result, metadata=metadata) + logger.info("✅ 分析结果已保存到数据库") + else: + logger.warning("⚠️ 分析失败,不保存到数据库以便后续重试") + + # 处理完成,通知等待者并清理资源 + video_event.set() + async with video_lock_manager: + # 清理资源 + video_locks.pop(video_hash, None) + video_events.pop(video_hash, None) + + return {"summary": result} + + except Exception as e: + error_msg = f"❌ 从字节数据分析视频失败: {str(e)}" + logger.error(error_msg) async def _save_cache(self, video_hash: str, summary: str, file_size: int) -> None: try: diff --git a/src/plugins/built_in/emoji_plugin/emoji.py b/src/plugins/built_in/emoji_plugin/emoji.py index 007a99c3e..acacfee50 100644 --- a/src/plugins/built_in/emoji_plugin/emoji.py +++ b/src/plugins/built_in/emoji_plugin/emoji.py @@ -152,10 +152,10 @@ class EmojiAction(BaseAction): # 调用LLM models = llm_api.get_available_models() - chat_model_config = models.get("planner") + chat_model_config = models.get("utils") if not chat_model_config: - logger.error(f"{self.log_prefix} 未找到'planner'模型配置,无法调用LLM") - return False, "未找到'planner'模型配置" + logger.error(f"{self.log_prefix} 未找到'utils'模型配置,无法调用LLM") + return False, "未找到'utils'模型配置" success, chosen_emotion, _, _ = await llm_api.generate_with_model( prompt, model_config=chat_model_config, request_type="emoji" @@ -212,10 +212,10 @@ class EmojiAction(BaseAction): # 调用LLM models = llm_api.get_available_models() - chat_model_config = models.get("planner") + chat_model_config = models.get("utils") if not chat_model_config: - logger.error(f"{self.log_prefix} 未找到'planner'模型配置,无法调用LLM") - return False, "未找到'planner'模型配置" + logger.error(f"{self.log_prefix} 未找到'utils'模型配置,无法调用LLM") + return False, "未找到'utils'模型配置" success, chosen_description, _, _ = await llm_api.generate_with_model( prompt, model_config=chat_model_config, request_type="emoji"