Add brain memory services and APIs
Introduce the backend pieces for brain memory ingestion, routing, and system telemetry so the new knowledge workflows can project data into a brain view. The supporting tests lock in the new behavior and keep the expanded backend surface stable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import copy
|
||||
import logging
|
||||
from typing import Optional
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from app.models.user import User
|
||||
from app.services.auth_service import verify_password, get_password_hash
|
||||
from app.logging_utils import summarize_llm_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -49,9 +51,7 @@ async def update_user_profile(
|
||||
|
||||
async def update_llm_config(user_id: str, config: dict, db: AsyncSession) -> dict:
|
||||
"""更新 LLM 配置"""
|
||||
import copy
|
||||
logger.info(f"update_llm_config called with config keys: {list(config.keys())}")
|
||||
logger.info(f"chat config: {config.get('chat')}")
|
||||
logger.info("update_llm_config called", extra={"details": {"keys": list(config.keys())}})
|
||||
result = await db.execute(select(User).where(User.id == user_id))
|
||||
user = result.scalar_one_or_none()
|
||||
if not user:
|
||||
@@ -59,7 +59,7 @@ async def update_llm_config(user_id: str, config: dict, db: AsyncSession) -> dic
|
||||
|
||||
# 创建深拷贝,避免 SQLAlchemy 变更检测问题
|
||||
current = copy.deepcopy(user.llm_config) or {}
|
||||
logger.info(f"current llm_config before update: {current}")
|
||||
logger.info("llm_config before update", extra={"details": summarize_llm_config(current)})
|
||||
# 合并配置 - 直接替换整个类型配置列表
|
||||
for key, value in config.items():
|
||||
if value is not None:
|
||||
@@ -74,11 +74,11 @@ async def update_llm_config(user_id: str, config: dict, db: AsyncSession) -> dic
|
||||
current[key] = value
|
||||
else:
|
||||
current[key] = value
|
||||
logger.info(f"current llm_config after update: {current}")
|
||||
logger.info("llm_config after update", extra={"details": summarize_llm_config(current)})
|
||||
user.llm_config = current
|
||||
await db.commit()
|
||||
await db.refresh(user)
|
||||
logger.info(f"user.llm_config after refresh: {user.llm_config}")
|
||||
logger.info("user.llm_config after refresh", extra={"details": summarize_llm_config(user.llm_config)})
|
||||
return current
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user