55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
"""PMFlow OS AI answer feedback models."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
from sqlalchemy import BigInteger, ForeignKey, Integer, Text, UniqueConstraint, VARCHAR
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
from .types import JSONB
|
|
|
|
|
|
class PMFlowAIFeedbackEvent(Base):
|
|
__tablename__ = "pmflow_ai_feedback_events"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
project_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("projects.id"), nullable=False, index=True)
|
|
thread_id: Mapped[Optional[int]] = mapped_column(BigInteger, ForeignKey("pmflow_threads.id"), nullable=True, index=True)
|
|
message_id: Mapped[Optional[int]] = mapped_column(
|
|
BigInteger, ForeignKey("pmflow_thread_messages.id"), nullable=True, index=True
|
|
)
|
|
change_set_id: Mapped[Optional[int]] = mapped_column(
|
|
BigInteger, ForeignKey("pmflow_change_sets.id"), nullable=True, index=True
|
|
)
|
|
ai_call_log_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
|
actor_user_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id"), nullable=False, index=True)
|
|
target_type: Mapped[str] = mapped_column(VARCHAR(64), nullable=False, index=True)
|
|
target_id: Mapped[str] = mapped_column(VARCHAR(128), nullable=False, index=True)
|
|
answer_kind: Mapped[str] = mapped_column(VARCHAR(64), nullable=False, default="chat_answer", index=True)
|
|
rating: Mapped[str] = mapped_column(VARCHAR(16), nullable=False, index=True)
|
|
reason_tags: Mapped[Any] = mapped_column(JSONB, nullable=False, default=list)
|
|
comment: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
scene_key: Mapped[Optional[str]] = mapped_column(VARCHAR(128), nullable=True, index=True)
|
|
prompt_key: Mapped[Optional[str]] = mapped_column(VARCHAR(128), nullable=True, index=True)
|
|
prompt_release_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, index=True)
|
|
runtime_profile_id: Mapped[Optional[str]] = mapped_column(VARCHAR(128), nullable=True, index=True)
|
|
model_provider: Mapped[Optional[str]] = mapped_column(VARCHAR(64), nullable=True)
|
|
model_name: Mapped[Optional[str]] = mapped_column(VARCHAR(120), nullable=True)
|
|
feedback_metadata: Mapped[Any] = mapped_column(JSONB, nullable=False, default=dict)
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"tenant_id",
|
|
"project_id",
|
|
"actor_user_id",
|
|
"target_type",
|
|
"target_id",
|
|
name="uq_pmflow_ai_feedback_target_user",
|
|
),
|
|
)
|
|
|
|
|
|
__all__ = ["PMFlowAIFeedbackEvent"]
|