prompt.py
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""提示词模板 SQLAlchemy 模型"""
import uuid
from datetime import datetime
from sqlalchemy import Integer, DateTime
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.dialects.mysql import VARCHAR, TEXT
from app.core.database import Base
from app.models._types import JsonAsText
class PromptTemplate(Base):
"""提示词模板表"""
__tablename__ = "ai_llmbase_prompt_templates"
id: Mapped[str] = mapped_column(
VARCHAR(36), primary_key=True,
default=lambda: str(uuid.uuid4())
)
template_type: Mapped[str] = mapped_column(
VARCHAR(50), nullable=False,
comment="模板类型:general/quality_inspection/image/param_text/audio_summary/employee_review"
)
title: Mapped[str] = mapped_column(
VARCHAR(200), nullable=False,
comment="模板标题"
)
code: Mapped[str] = mapped_column(
VARCHAR(100), nullable=False, unique=True,
comment="业务编码,手动配置的唯一标识"
)
system_prompt: Mapped[str] = mapped_column(
TEXT, nullable=False,
comment="System Prompt 内容"
)
user_prompt: Mapped[str | None] = mapped_column(
TEXT, nullable=True,
comment="User Prompt 内容"
)
variables: Mapped[list | None] = mapped_column(
JsonAsText, default=list,
comment="变量占位符定义,如 [{\"name\":\"content\", \"type\":\"string\"}]"
)
version: Mapped[int] = mapped_column(
Integer, nullable=False, default=1,
comment="当前版本号"
)
status: Mapped[str] = mapped_column(
VARCHAR(20), nullable=False, default="published",
comment="状态:draft/published/archived"
)
created_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.now,
comment="创建时间"
)
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.now, onupdate=datetime.now,
comment="更新时间"
)
def __repr__(self) -> str:
return f"<PromptTemplate {self.title} v{self.version}>"