
Implement a new endpoint that converts natural language input into structured tasks using an LLM. Features include: - LLM service abstraction with support for OpenAI and Google Gemini - Dependency injection pattern for easy provider switching - Robust error handling and response formatting - Integration with existing user authentication and task creation - Fallback to mock LLM service for testing or development
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from app.models.task import TaskPriority, TaskStatus
|
|
|
|
|
|
class TaskBase(BaseModel):
|
|
title: str = Field(..., min_length=1, max_length=100)
|
|
description: Optional[str] = None
|
|
priority: TaskPriority = TaskPriority.MEDIUM
|
|
status: TaskStatus = TaskStatus.TODO
|
|
due_date: Optional[datetime] = None
|
|
completed: bool = False
|
|
|
|
model_config = {
|
|
"json_encoders": {
|
|
datetime: lambda dt: dt.isoformat(),
|
|
}
|
|
}
|
|
|
|
|
|
class TaskCreate(TaskBase):
|
|
pass
|
|
|
|
|
|
class TaskUpdate(BaseModel):
|
|
title: Optional[str] = Field(None, min_length=1, max_length=100)
|
|
description: Optional[str] = None
|
|
priority: Optional[TaskPriority] = None
|
|
status: Optional[TaskStatus] = None
|
|
due_date: Optional[datetime] = None
|
|
completed: Optional[bool] = None
|
|
|
|
model_config = {
|
|
"json_encoders": {
|
|
datetime: lambda dt: dt.isoformat(),
|
|
},
|
|
"populate_by_name": True,
|
|
"json_schema_extra": {
|
|
"examples": [
|
|
{
|
|
"title": "Updated Task Title",
|
|
"description": "Updated task description",
|
|
"priority": "high",
|
|
"status": "in_progress",
|
|
"completed": False,
|
|
}
|
|
]
|
|
},
|
|
}
|
|
|
|
|
|
class TaskInDBBase(TaskBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class Task(TaskInDBBase):
|
|
"""Schema for tasks returned from database operations."""
|
|
pass
|
|
|
|
|
|
class TaskRead(TaskInDBBase):
|
|
"""Schema for task data returned to clients."""
|
|
user_id: Optional[int] = None
|