Files
diary-news/backend/app/models/llm_setting.py

51 lines
1.7 KiB
Python

"""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}>"