huoyan-enterprise/backend/models/moderation.py

36 lines
1.1 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.

"""
内容审核模型
定义阿里云内容审核相关的数据模型。
"""
from enum import Enum
from typing import List, Optional
from pydantic import BaseModel, Field
class ModerationDecision(str, Enum):
"""审核决策类型"""
PASS = "pass" # 通过审核
REVIEW = "review" # 需要人工复审
BLOCK = "block" # 阻止内容
class ModerationLabel(BaseModel):
"""违规标签信息"""
label: str = Field(..., description="违规标签,如 politics、abuse、spam")
score: float = Field(..., ge=0, le=100, description="置信度分数 (0-100)")
class Config:
from_attributes = True
class ModerationResult(BaseModel):
"""内容审核结果"""
decision: ModerationDecision = Field(..., description="审核决策")
labels: List[ModerationLabel] = Field(default_factory=list, description="违规标签列表")
request_id: Optional[str] = Field(None, description="请求 ID用于追踪")
message: Optional[str] = Field(None, description="用户友好的提示消息(用于被阻止的内容)")
class Config:
from_attributes = True