From c488eb0cd00e3fccc6f0ce090b6fc909597fd441 Mon Sep 17 00:00:00 2001 From: lanceyq <1982376970@qq.com> Date: Wed, 4 Mar 2026 12:17:34 +0800 Subject: [PATCH] [changes] 1.Use structured logs; 2.Align the type and default value of "end_user_id" with the semantic meaning of "required". --- api/app/controllers/memory_agent_controller.py | 2 +- api/app/core/memory/analytics/hot_memory_tags.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/app/controllers/memory_agent_controller.py b/api/app/controllers/memory_agent_controller.py index 1f070eb6..ccf93d68 100644 --- a/api/app/controllers/memory_agent_controller.py +++ b/api/app/controllers/memory_agent_controller.py @@ -664,7 +664,7 @@ async def get_knowledge_type_stats_api( @router.get("/analytics/interest_distribution/by_user", response_model=ApiResponse) async def get_interest_distribution_by_user_api( - end_user_id: Optional[str] = Query(None, description="用户ID(必填)"), + end_user_id: str = Query(..., description="用户ID(必填)"), limit: int = Query(5, le=5, description="返回兴趣标签数量限制,最多5个"), language_type: str = Header(default=None, alias="X-Language-Type"), current_user: User = Depends(get_current_user), diff --git a/api/app/core/memory/analytics/hot_memory_tags.py b/api/app/core/memory/analytics/hot_memory_tags.py index 1d2d5259..6afcec6d 100644 --- a/api/app/core/memory/analytics/hot_memory_tags.py +++ b/api/app/core/memory/analytics/hot_memory_tags.py @@ -1,9 +1,12 @@ import asyncio import json +import logging import os from typing import List, Tuple from app.core.config import settings + +logger = logging.getLogger(__name__) from app.core.memory.utils.llm.llm_utils import MemoryClientFactory from app.db import get_db_context from app.repositories.neo4j.neo4j_connector import Neo4jConnector @@ -89,7 +92,7 @@ async def filter_tags_with_llm(tags: List[str], end_user_id: str) -> List[str]: return structured_response.meaningful_tags except Exception as e: - print(f"LLM筛选过程中发生错误: {e}") + logger.error(f"LLM筛选过程中发生错误: {e}", exc_info=True) # 在LLM失败时返回原始标签,确保流程继续 return tags @@ -153,7 +156,7 @@ async def filter_interests_with_llm(tags: List[str], end_user_id: str, language: return structured_response.interest_tags except Exception as e: - print(f"兴趣标签LLM筛选过程中发生错误: {e}") + logger.error(f"兴趣标签LLM筛选过程中发生错误: {e}", exc_info=True) return tags