feat(llm): 新增 LLM 智能增强服务(Agnes client + 4 项 enrichment 任务 + admin API + migration)

This commit is contained in:
Mavis
2026-06-08 14:24:00 +08:00
parent 40be1e6861
commit ffd667f0dc
7 changed files with 698 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
"""LLM 设置(单行,owner 可编辑)。
字段对应:
- 排版/分类/点评提示词(用户可改)
- 插图尺寸 + prompt 模板(用户可改)
- 总开关 enabled
- 模型名(默认指向 Agnes,但可改成任意 OpenAI 兼容端点)
"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class LlmSetting(Base):
__tablename__ = "llm_settings"
# 永远只有一行:id=1
id: Mapped[int] = mapped_column(Integer, primary_key=True, default=1)
# === 提示词 ===
format_prompt: Mapped[str | None] = mapped_column(Text)
classify_prompt: Mapped[str | None] = mapped_column(Text)
commentary_prompt: Mapped[str | None] = mapped_column(Text)
image_prompt_template: Mapped[str | None] = mapped_column(Text)
# === 插图参数 ===
image_size: Mapped[str] = mapped_column(String(16), default="1024x768", nullable=False)
# === 模型 ===
chat_model: Mapped[str] = mapped_column(String(64), default="agnes-2.0-flash", nullable=False)
image_model: Mapped[str] = mapped_column(String(64), default="agnes-image-2.1-flash", nullable=False)
# === 限速 ===
interval_sec: Mapped[float] = mapped_column(default=2.0, nullable=False)
# === 总开关 ===
enabled: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
# === 时间 ===
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False
)
def __repr__(self) -> str:
return f"<LlmSetting id={self.id} enabled={self.enabled}>"