diff --git a/app/api/api_recommendation.py b/app/api/api_recommendation.py index 40f7fa0..477ab08 100644 --- a/app/api/api_recommendation.py +++ b/app/api/api_recommendation.py @@ -34,12 +34,14 @@ async def startup_event(): scheduler.start() logger.info("定时任务已启动") + def softmax(scores): max_score = max(scores) exp_scores = [math.exp(s - max_score) for s in scores] sum_exp = sum(exp_scores) return [s / sum_exp for s in exp_scores] + # def get_random_recommendations(category: str, num: int) -> List[str]: # """根据预加载热度向量推荐(冷启动)""" # try: @@ -92,7 +94,7 @@ async def get_recommendations(user_id: int, category: str, brand_id: int, brand_ ] """ 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() 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: logger.error(f"推荐失败: {str(e)}", exc_info=True) - raise HTTPException(status_code=500, detail=str(e)) \ No newline at end of file + raise HTTPException(status_code=500, detail=str(e))