finalize medical consultation agent backend
This commit is contained in:
@@ -3,8 +3,8 @@ from __future__ import annotations
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, Integer, JSON, Numeric, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, JSON, Numeric, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db.base import Base
|
||||
from app.models.mixins import TimestampMixin
|
||||
@@ -42,8 +42,8 @@ class TrainingRecord(TimestampMixin, Base):
|
||||
rag_context_version: Mapped[str] = mapped_column(String(50), nullable=False, default="none", comment="RAG上下文版本")
|
||||
case_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True, comment="病例ID")
|
||||
teacher_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="教师ID")
|
||||
user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="数字用户ID")
|
||||
external_user_id: Mapped[str] = mapped_column(String(128), nullable=False, index=True, comment="宿主系统用户ID")
|
||||
user_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="Django用户中心数字ID")
|
||||
external_user_id: Mapped[str] = mapped_column(String(128), nullable=False, index=True, comment="Django用户中心ID")
|
||||
session_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="训练会话ID")
|
||||
evaluation_record_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="兼容旧评价记录ID")
|
||||
score_type: Mapped[str] = mapped_column(String(20), nullable=False, default="percentage", comment="分数类型")
|
||||
@@ -53,3 +53,25 @@ class TrainingRecord(TimestampMixin, Base):
|
||||
UniqueConstraint("session_id", name="uk_training_record_session"),
|
||||
{"comment": "训练记录表"},
|
||||
)
|
||||
|
||||
score_details = relationship("TrainingScoreDetail", back_populates="record", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class TrainingScoreDetail(TimestampMixin, Base):
|
||||
"""评分明细表:保存每条 scoring_rule 对应的 AI 评分、扣分原因、证据和置信度。"""
|
||||
|
||||
__tablename__ = "training_score_detail"
|
||||
|
||||
id: Mapped[int] = mapped_column(BIGINT_PK, primary_key=True, autoincrement=True, comment="评分明细ID")
|
||||
record_id: Mapped[int] = mapped_column(ForeignKey("training_record.id"), nullable=False, index=True, comment="训练记录ID")
|
||||
rule_id: Mapped[int | None] = mapped_column(ForeignKey("scoring_rule.id"), nullable=True, index=True, comment="评分规则ID")
|
||||
dimension: Mapped[str] = mapped_column(String(50), nullable=False, index=True, comment="评分维度")
|
||||
score: Mapped[Decimal] = mapped_column(Numeric(5, 2), nullable=False, default=0, comment="分数")
|
||||
deducted_reason: Mapped[str | None] = mapped_column(Text, comment="扣分原因")
|
||||
evidence_message_ids: Mapped[list] = mapped_column(JSON, nullable=False, default=list, comment="对应对话证据")
|
||||
ai_confidence: Mapped[Decimal | None] = mapped_column(Numeric(5, 2), comment="AI评分置信度")
|
||||
comment: Mapped[str | None] = mapped_column(Text, comment="评语")
|
||||
|
||||
record = relationship("TrainingRecord", back_populates="score_details")
|
||||
|
||||
__table_args__ = {"comment": "评分明细表"}
|
||||
|
||||
Reference in New Issue
Block a user