feat(新功能):
fix(修复bug): 推荐接口 请求参数打印 docs(文档变更): refactor(重构): test(增加测试):
This commit is contained in:
@@ -34,12 +34,14 @@ async def startup_event():
|
|||||||
scheduler.start()
|
scheduler.start()
|
||||||
logger.info("定时任务已启动")
|
logger.info("定时任务已启动")
|
||||||
|
|
||||||
|
|
||||||
def softmax(scores):
|
def softmax(scores):
|
||||||
max_score = max(scores)
|
max_score = max(scores)
|
||||||
exp_scores = [math.exp(s - max_score) for s in scores]
|
exp_scores = [math.exp(s - max_score) for s in scores]
|
||||||
sum_exp = sum(exp_scores)
|
sum_exp = sum(exp_scores)
|
||||||
return [s / sum_exp for s in exp_scores]
|
return [s / sum_exp for s in exp_scores]
|
||||||
|
|
||||||
|
|
||||||
# def get_random_recommendations(category: str, num: int) -> List[str]:
|
# def get_random_recommendations(category: str, num: int) -> List[str]:
|
||||||
# """根据预加载热度向量推荐(冷启动)"""
|
# """根据预加载热度向量推荐(冷启动)"""
|
||||||
# try:
|
# try:
|
||||||
@@ -92,7 +94,7 @@ async def get_recommendations(user_id: int, category: str, brand_id: int, brand_
|
|||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
logger.info(f"user_id:{user_id}, category:{category}, num_recommendations:{num_recommendations}")
|
logger.info(f"user_id:{user_id}-----category:{category}-----brand_id:{brand_id}-----brand_scale:{brand_scale}-----num_recommendations:{num_recommendations}")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
cache_key = (user_id, category)
|
cache_key = (user_id, category)
|
||||||
# === 新增:用户存在性检查 ===
|
# === 新增:用户存在性检查 ===
|
||||||
@@ -202,4 +204,4 @@ async def get_recommendations(user_id: int, category: str, brand_id: int, brand_
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"推荐失败: {str(e)}", exc_info=True)
|
logger.error(f"推荐失败: {str(e)}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|||||||
Reference in New Issue
Block a user