File size: 3,121 Bytes
2380f6f |
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 |
"""Pydantic models for topic extraction endpoints"""
from pydantic import BaseModel, Field, ConfigDict
from typing import List, Optional
class TopicRequest(BaseModel):
"""Request model for topic extraction"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"text": "Social media companies must NOT be allowed to track people across websites."
}
}
)
text: str = Field(
..., min_length=5, max_length=5000,
description="The text/argument to extract topic from"
)
class TopicResponse(BaseModel):
"""Response model for topic extraction"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"text": "Social media companies must NOT be allowed to track people across websites.",
"topic": "social media tracking and cross-website user privacy",
"timestamp": "2024-01-01T12:00:00Z"
}
}
)
text: str = Field(..., description="The original input text")
topic: str = Field(..., description="The extracted topic")
timestamp: str = Field(..., description="Timestamp of the extraction")
class BatchTopicRequest(BaseModel):
"""Request model for batch topic extraction"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"texts": [
"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."
]
}
}
)
texts: List[str] = Field(
..., min_length=1, max_length=50,
description="List of texts to extract topics from (max 50)"
)
class BatchTopicResponse(BaseModel):
"""Response model for batch topic extraction"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"results": [
{
"text": "Social media companies must NOT be allowed to track people across websites.",
"topic": "social media tracking and cross-website user privacy",
"timestamp": "2024-01-01T12:00:00Z"
},
{
"text": "I don't think universal basic income is a good idea — it'll disincentivize work.",
"topic": "universal basic income and its impact on work incentives",
"timestamp": "2024-01-01T12:00:00Z"
}
],
"total_processed": 2,
"timestamp": "2024-01-01T12:00:00Z"
}
}
)
results: List[TopicResponse] = Field(..., description="List of topic extraction results")
total_processed: int = Field(..., description="Number of texts processed")
timestamp: str = Field(..., description="Timestamp of the batch extraction")
|