Add basis workspace filters, stale-on-reimport, and variant usage metrics
This commit is contained in:
72
app/models/ai_generation_run.py
Normal file
72
app/models/ai_generation_run.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
AI generation run model.
|
||||
|
||||
Represents one admin generation request that can produce one or many variants.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class AIGenerationRun(Base):
|
||||
__tablename__ = "ai_generation_runs"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
basis_item_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("items.id", ondelete="CASCADE", onupdate="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
comment="Basis item ID",
|
||||
)
|
||||
source_snapshot_question_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey("tryout_snapshot_questions.id", ondelete="SET NULL", onupdate="CASCADE"),
|
||||
nullable=True,
|
||||
index=True,
|
||||
comment="Source snapshot question ID",
|
||||
)
|
||||
target_level: Mapped[str] = mapped_column(
|
||||
String(50),
|
||||
nullable=False,
|
||||
comment="Target level (mudah/sulit)",
|
||||
)
|
||||
requested_count: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
nullable=False,
|
||||
default=1,
|
||||
comment="Requested output count",
|
||||
)
|
||||
model: Mapped[str] = mapped_column(
|
||||
String(255),
|
||||
nullable=False,
|
||||
comment="Model identifier",
|
||||
)
|
||||
prompt_version: Mapped[str] = mapped_column(
|
||||
String(50),
|
||||
nullable=False,
|
||||
default="v1",
|
||||
comment="Prompt template version",
|
||||
)
|
||||
operator_notes: Mapped[Optional[str]] = mapped_column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="Optional admin notes",
|
||||
)
|
||||
created_by: Mapped[str] = mapped_column(
|
||||
String(255),
|
||||
nullable=False,
|
||||
comment="Admin username",
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
|
||||
generated_items: Mapped[list["Item"]] = relationship(
|
||||
"Item",
|
||||
back_populates="generation_run",
|
||||
lazy="selectin",
|
||||
)
|
||||
Reference in New Issue
Block a user