analyse: thread user.lang into the system prompt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Giorgio Gilestro 2026-05-27 17:01:00 +02:00
parent e4982cdc04
commit d318039ad5
3 changed files with 89 additions and 4 deletions

View file

@ -36,7 +36,7 @@ from fastapi.responses import JSONResponse
from sqlalchemy import and_, func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.auth import require_auth
from app.auth import CurrentUser, require_auth
from app.config import get_settings
from app.db import get_session, utcnow
from app.logging import get_logger
@ -341,10 +341,11 @@ async def parse_portfolio(
# ---------------------------------------------------------------------------
@router.post("/analyze", dependencies=[Depends(require_paid)])
@router.post("/analyze")
async def analyze_portfolio(
request: Request,
session: AsyncSession = Depends(get_session),
principal: CurrentUser = Depends(require_paid),
) -> dict:
"""Generate AI commentary for the supplied pie. The pie is held in
memory only for the duration of the LLM call; nothing about holdings
@ -364,6 +365,11 @@ async def analyze_portfolio(
except Exception:
raise HTTPException(status_code=400, detail="malformed JSON body")
user_lang = (
principal.user.lang if (principal.user and principal.user.lang) else "en"
)
payload["lang"] = user_lang
try:
req = portfolio_analysis.parse_request(payload)
except ValueError as e: