添加异常处理

This commit is contained in:
Tian jianyong 2025-12-24 19:57:25 +08:00
parent 4bf037ade5
commit b3b07850f2

View File

@ -413,6 +413,7 @@ def get_semantic_cache_service() -> SemanticCacheService:
# 便捷函数
async def lookup_question(chat_id: str, question: str, redis_client=None) -> Optional[Tuple[str, float]]:
"""查找缓存问题"""
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}")
@ -421,6 +422,9 @@ async def lookup_question(chat_id: str, question: str, redis_client=None) -> Opt
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: