From b3b07850f266442724cbb65fae5d63e39c2f93cd Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Wed, 24 Dec 2025 19:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/semantic_cache_service.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ruoyi-fastapi-backend/utils/semantic_cache_service.py b/ruoyi-fastapi-backend/utils/semantic_cache_service.py index 12637ce..71a31c6 100644 --- a/ruoyi-fastapi-backend/utils/semantic_cache_service.py +++ b/ruoyi-fastapi-backend/utils/semantic_cache_service.py @@ -413,14 +413,18 @@ def get_semantic_cache_service() -> SemanticCacheService: # 便捷函数 async def lookup_question(chat_id: str, question: str, redis_client=None) -> Optional[Tuple[str, float]]: """查找缓存问题""" - logger.info(f"[SemanticCache.lookup_question] 🔍 函数被调用 | chat_id={chat_id} | question={question} | redis_client={redis_client is not None}") - service = get_semantic_cache_service() - logger.info(f"[SemanticCache.lookup_question] 获取服务实例完成 | service={service is not None}") - result = await service.lookup(chat_id, question, redis_client) - logger.info(f"[SemanticCache.lookup_question] 返回 | result={result is not None}") - if result: - logger.info(f"[SemanticCache.lookup_question] 命中结果 | answer_length={len(result[0])} | similarity={result[1]:.2f}") - return result + try: + logger.info(f"[SemanticCache.lookup_question] 🔍 函数被调用 | chat_id={chat_id} | question={question} | redis_client={redis_client is not None}") + service = get_semantic_cache_service() + logger.info(f"[SemanticCache.lookup_question] 获取服务实例完成 | service={service is not None}") + result = await service.lookup(chat_id, question, redis_client) + logger.info(f"[SemanticCache.lookup_question] 返回 | result={result is not None}") + if result: + logger.info(f"[SemanticCache.lookup_question] 命中结果 | answer_length={len(result[0])} | similarity={result[1]:.2f}") + return result + except Exception as e: + logger.error(f"[SemanticCache.lookup_question] 异常: {e}") + return None async def store_qa_pair(chat_id: str, question: str, answer: str, redis_client=None) -> bool: