File size: 1,755 Bytes
effed4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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]