添加异常处理

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

View File

@ -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: