Spaces:
Sleeping
Sleeping
File size: 1,186 Bytes
b4e4aa8 3dd214a b4e4aa8 baee798 a860680 baee798 e784b4f a860680 b4e4aa8 a860680 e784b4f b4e4aa8 e784b4f b4e4aa8 e784b4f a2d9943 5b30cd8 e784b4f b4e4aa8 9248c2e 5b30cd8 9248c2e 5b30cd8 9248c2e 5b30cd8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | from __future__ import annotations
from typing import List, Optional
from datetime import datetime, timezone
from pydantic import BaseModel, Field
# ====== Chat history ======
class Message(BaseModel):
role: str = "user"
content: str = ""
ts: Optional[str] = None
class ChatRequest(BaseModel):
message: str = "" # 🚀 Beri default string kosong agar tidak 422 saat di-ping payload kosong
history: List[Message] = Field(default_factory=list)
username: Optional[str] = "Baka"
# ====== Device register ======
class RegisterRequest(BaseModel):
fcm_token: str
# ====== Scheduler ======
class ScheduleRequest(BaseModel):
task: str
scheduled_time: str
user_id: str
@property
def remind_at_utc(self) -> datetime:
try:
clean_ts = self.scheduled_time.replace("Z", "+00:00")
dt = datetime.fromisoformat(clean_ts)
if dt.tzinfo is None:
return dt.replace(tzinfo=timezone.utc)
return dt.astimezone(timezone.utc)
except ValueError as e:
raise ValueError(
f"Format scheduled_time tidak valid: {self.scheduled_time}"
) from e |