Yassine Mhirsi
feat: Add topic-related schemas and API routes for topic management, along with LangChain dependencies in requirements.
2380f6f
| """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") | |