feat: AI 周报摘要提示词自定义设置

- system_config 新增 ai_summary_prompt 配置键
- generate_summary 从数据库加载自定义提示词,为空则使用默认 SUMMARY_SYSTEM_PROMPT
- 系统设置新增「AI 周报提示词」卡片,支持编辑和清空恢复默认

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-12 14:20:20 +08:00
parent 7dcb22f573
commit e7c3081070
3 changed files with 54 additions and 2 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ async def update_config(
):
"""Update a single config key. Only directors can change settings."""
value = body.get("value", "")
valid_keys = {"notification_time", "holidays"}
valid_keys = {"notification_time", "holidays", "ai_summary_prompt"}
if key not in valid_keys:
raise HTTPException(status_code=400, detail=f"不支持的配置项: {key}")
+8 -1
View File
@@ -6,6 +6,7 @@ from app.config import settings
from app.services.dashboard import get_weekly_report, get_week_range
from app.services.light_board import get_light_board
from app.models.ai_summary import AISummary
from app.models.system_config import SystemConfig
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from uuid import UUID
@@ -240,6 +241,12 @@ async def generate_summary(
leaves=leave_overview.get("leave_list", []),
)
# Load custom system prompt (director/leader can override via system settings)
custom_row = await db.get(SystemConfig, "ai_summary_prompt")
system_prompt = SUMMARY_SYSTEM_PROMPT
if custom_row and custom_row.value and custom_row.value.strip():
system_prompt = custom_row.value.strip()
# Call LLM
headers = {"Content-Type": "application/json"}
if settings.AI_API_KEY:
@@ -248,7 +255,7 @@ async def generate_summary(
payload = {
"model": settings.AI_MODEL,
"messages": [
{"role": "system", "content": SUMMARY_SYSTEM_PROMPT},
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt},
],
"max_tokens": settings.AI_MAX_TOKENS,