File size: 1,356 Bytes
ae4e2a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
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
            }
        }