Download src/schemas/chat.py from BilalCode/TaskFlow: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/spaces/BilalCode/TaskFlow/resolve/main/src/schemas/chat.py
- Command line
-
hf download hf://spaces/BilalCode/TaskFlow/src/schemas/chat.py
-
curl -L -o chat.py https://huggingface.co/spaces/BilalCode/TaskFlow/resolve/main/src/schemas/chat.py
2.67 kB
| """ | |
| Chat API Schemas | |
| Request and response models for the chat endpoint. | |
| """ | |
| from pydantic import BaseModel, Field, field_validator | |
| from typing import Optional, List, Dict, Any | |
| from datetime import datetime | |
| class ChatRequest(BaseModel): | |
| """Request model for chat endpoint.""" | |
| message: str = Field( | |
| ..., | |
| min_length=1, | |
| max_length=2000, | |
| description="User's natural language message" | |
| ) | |
| conversation_id: Optional[int] = Field( | |
| default=None, | |
| description="Existing conversation ID to continue (omit for new conversation)" | |
| ) | |
| def validate_message(cls, v: str) -> str: | |
| """Validate message is not empty or whitespace-only.""" | |
| if not v or v.strip() == "": | |
| raise ValueError("Message cannot be empty or whitespace-only") | |
| return v.strip() | |
| class ToolCallResult(BaseModel): | |
| """Tool call result metadata.""" | |
| tool: str = Field(..., description="Tool name") | |
| parameters: Dict[str, Any] = Field(..., description="Tool parameters") | |
| result: Dict[str, Any] = Field(..., description="Tool execution result") | |
| duration_ms: Optional[int] = Field(None, description="Execution time in milliseconds") | |
| class ChatResponse(BaseModel): | |
| """Response model for chat endpoint.""" | |
| conversation_id: int = Field(..., description="Conversation identifier") | |
| message_id: int = Field(..., description="Assistant message ID") | |
| assistant_message: str = Field(..., description="Natural language response from agent") | |
| tool_calls: Optional[List[ToolCallResult]] = Field( | |
| default=None, | |
| description="List of MCP tool invocations (empty if no tools used)" | |
| ) | |
| timestamp: datetime = Field(..., description="Response generation timestamp") | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "conversation_id": 456, | |
| "message_id": 789, | |
| "assistant_message": "I've added 'Buy groceries tomorrow' to your tasks. Task created successfully!", | |
| "tool_calls": [ | |
| { | |
| "tool": "create_task", | |
| "parameters": { | |
| "title": "Buy groceries tomorrow", | |
| "description": "" | |
| }, | |
| "result": { | |
| "task_id": 101, | |
| "status": "success" | |
| }, | |
| "duration_ms": 45 | |
| } | |
| ], | |
| "timestamp": "2026-02-03T10:30:00Z" | |
| } | |
| } | |