Spaces:
Sleeping
Sleeping
| from datetime import datetime | |
| from typing import Optional, Any | |
| from pydantic import BaseModel, Field | |
| class ChatMessage(BaseModel): | |
| """MongoDB ChatMessage model. | |
| Field alignment with the LLM layer (ai_service/db/database.py): | |
| - ``role`` (was ``sender``) β user | assistant | scan_event | |
| - ``content`` (was ``message``) β message body | |
| - ``plant_id`` β links message to a plant thread | |
| - ``scan_id`` β optional link to a scan_history document | |
| """ | |
| id: Optional[str] = Field(default=None, alias="_id") | |
| plant_id: str # Reference to plant (AI layer is per-plant) | |
| user_id: Optional[str] = None # Reference to user (None for scan_event) | |
| role: str # user | assistant | scan_event | |
| content: str # message body | |
| scan_id: Optional[Any] = None # reference to scan_history document | |
| created_at: datetime = Field(default_factory=datetime.utcnow) | |
| class Config: | |
| populate_by_name = True | |