HariLogicgo's picture
added id returning
8cceab7
from __future__ import annotations
from typing import Optional
from bson import ObjectId
from pydantic import BaseModel, Field, field_validator
class CategorizeRequest(BaseModel):
notes: str = Field(..., min_length=1, description="Full transaction note.")
user_id: str = Field(..., description="User identifier associated with the request.")
class CategoryPrediction(BaseModel):
headcategory_id: str = Field(..., description="High-level category ObjectId.")
headcategory_title: str = Field(..., description="High-level category title.")
category_id: str = Field(..., description="Specific subcategory ObjectId chosen by the model.")
category_title: str = Field(..., description="Specific subcategory title chosen by the model.")
@field_validator('headcategory_id', 'category_id')
@classmethod
def validate_object_id(cls, v: str) -> str:
"""Validate that the string is a valid ObjectId."""
if not ObjectId.is_valid(v):
raise ValueError(f"Invalid ObjectId: {v}")
return v
class CategorizeResponse(BaseModel):
status: str = Field(..., description="Outcome of the request (success/fail).")
data: Optional[CategoryPrediction] = Field(
None, description="Predicted category payload when successful."
)
message: Optional[str] = Field(None, description="Error message when failed.")