Files
my_bookmate/backend/app/models/ai_model.py
T

28 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import uuid
from datetime import datetime
from sqlalchemy import String, Text, Integer, DateTime, func
from sqlalchemy.orm import Mapped, mapped_column
from app.core.database import Base
def gen_uuid():
return str(uuid.uuid4())
class AiModel(Base):
"""用户从页面配置的 AI 模型(OpenAI 兼容 / Anthropic)。
.env 内置模型不落这张表,由 hub.builtin_models() 动态读取。
"""
__tablename__ = "ai_models"
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=gen_uuid)
name: Mapped[str] = mapped_column(String(200), unique=True) # 解析标识(请求模型 id)
label: Mapped[str] = mapped_column(String(200)) # 前端显示名
kind: Mapped[str] = mapped_column(String(50), default="openai_compatible") # openai_compatible | anthropic
base_url: Mapped[str] = mapped_column(String(500), default="")
api_key: Mapped[str] = mapped_column(Text, default="") # 明文本地存储(与 .env 同级信任)
model_id: Mapped[str] = mapped_column(String(200)) # 实际请求模型 id
sort_order: Mapped[int] = mapped_column(Integer, default=0)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())