toxic-api / app /schemas /requests.py
handrix
Initial deployment - Toxic Detection API
ae4e2a6
"""
Request Schemas
===============
DTOs for API requests
"""
from pydantic import BaseModel, Field, field_validator
class AnalysisRequest(BaseModel):
"""Request for text analysis"""
text: str = Field(
...,
description="Text to analyze for toxicity",
min_length=1,
max_length=5000,
examples=["Đồ ngu ngốc, mất dạy!"]
)
include_html: bool = Field(
default=True,
description="Include HTML highlighting in response"
)
include_word_scores: bool = Field(
default=True,
description="Include detailed word-level scores"
)
include_summary_table: bool = Field(
default=False,
description="Include summary table of all words"
)
@field_validator('text')
@classmethod
def validate_text(cls, v: str) -> str:
"""Validate text input"""
if not v or not v.strip():
raise ValueError("Text cannot be empty or only whitespace")
return v.strip()
class Config:
json_schema_extra = {
"example": {
"text": "Đồ ngu ngốc, mất dạy! Cảm ơn bạn đã chia sẻ.",
"include_html": True,
"include_word_scores": True,
"include_summary_table": False
}
}