File size: 4,245 Bytes
430b54f |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
"""Pydantic models for analysis endpoints"""
from pydantic import BaseModel, Field, ConfigDict
from typing import List, Optional
class AnalysisRequest(BaseModel):
"""Request model for analysis with arguments"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"arguments": [
"Social media companies must NOT be allowed to track people across websites.",
"I don't think universal basic income is a good idea — it'll disincentivize work.",
"We must invest in renewable energy to combat climate change."
]
}
}
)
arguments: List[str] = Field(
..., min_length=1, max_length=100,
description="List of argument texts to analyze (max 100)"
)
class AnalysisResult(BaseModel):
"""Model for a single analysis result"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"user_id": "123e4567-e89b-12d3-a456-426614174000",
"argument": "Social media companies must NOT be allowed to track people across websites.",
"topic": "social media tracking and cross-website user privacy",
"predicted_stance": "CON",
"confidence": 0.9234,
"probability_con": 0.9234,
"probability_pro": 0.0766,
"created_at": "2024-01-01T12:00:00Z",
"updated_at": "2024-01-01T12:00:00Z"
}
}
)
id: str = Field(..., description="Analysis result UUID")
user_id: str = Field(..., description="User UUID")
argument: str = Field(..., description="The argument text")
topic: str = Field(..., description="Extracted topic")
predicted_stance: str = Field(..., description="PRO or CON")
confidence: float = Field(..., ge=0.0, le=1.0, description="Confidence score")
probability_con: float = Field(..., ge=0.0, le=1.0, description="Probability of CON")
probability_pro: float = Field(..., ge=0.0, le=1.0, description="Probability of PRO")
created_at: str = Field(..., description="Creation timestamp")
updated_at: str = Field(..., description="Last update timestamp")
class AnalysisResponse(BaseModel):
"""Response model for analysis endpoint"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"results": [
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"user_id": "123e4567-e89b-12d3-a456-426614174000",
"argument": "Social media companies must NOT be allowed to track people across websites.",
"topic": "social media tracking and cross-website user privacy",
"predicted_stance": "CON",
"confidence": 0.9234,
"probability_con": 0.9234,
"probability_pro": 0.0766,
"created_at": "2024-01-01T12:00:00Z",
"updated_at": "2024-01-01T12:00:00Z"
}
],
"total_processed": 1,
"timestamp": "2024-01-01T12:00:00Z"
}
}
)
results: List[AnalysisResult] = Field(..., description="List of analysis results")
total_processed: int = Field(..., description="Number of arguments processed")
timestamp: str = Field(..., description="Analysis timestamp")
class GetAnalysisRequest(BaseModel):
"""Request model for getting user's analysis results"""
limit: Optional[int] = Field(100, ge=1, le=1000, description="Maximum number of results")
offset: Optional[int] = Field(0, ge=0, description="Number of results to skip")
class GetAnalysisResponse(BaseModel):
"""Response model for getting analysis results"""
results: List[AnalysisResult] = Field(..., description="List of analysis results")
total: int = Field(..., description="Total number of results")
limit: int = Field(..., description="Limit used")
offset: int = Field(..., description="Offset used")
|