from __future__ import annotations from typing import List from pydantic import BaseModel, Field, field_validator class HealthResponse(BaseModel): status: str model: str model_id: str backend: str device: str ready: bool max_context_length: int max_horizon_step: int class PredictRequest(BaseModel): symbol: str = Field(..., min_length=1, max_length=32) close_prices: List[float] = Field(..., min_length=8) context_length: int = Field(..., ge=8, le=2048) horizons: List[int] = Field(..., min_length=1, max_length=64) @field_validator("symbol") @classmethod def validate_symbol(cls, value: str) -> str: normalized = value.strip().upper() if not normalized: raise ValueError("symbol must not be empty") return normalized @field_validator("close_prices") @classmethod def validate_close_prices(cls, values: List[float]) -> List[float]: if any(price <= 0 for price in values): raise ValueError("close_prices must be positive") return values @field_validator("horizons") @classmethod def validate_horizons(cls, values: List[int]) -> List[int]: if any(step <= 0 for step in values): raise ValueError("horizons must be positive integers") if len(set(values)) != len(values): raise ValueError("horizons must not contain duplicates") return values class PredictionItem(BaseModel): step: int = Field(..., gt=0) pred_price: float = Field(..., gt=0) pred_confidence: float = Field(..., ge=0, le=1) class PredictResponse(BaseModel): model_id: str predictions: List[PredictionItem]