-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprediction.py
More file actions
96 lines (79 loc) · 2.3 KB
/
prediction.py
File metadata and controls
96 lines (79 loc) · 2.3 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from typing import Any, Dict, List, Union, cast
from typing_extensions import NotRequired, TypedDict
from ._config import ClientConfig
from ._types import BaseResponse
from .async_request import AsyncRequest
from .request import Request, RequestConfig
class Dataset(TypedDict):
value: Union[int, float, str]
"""
The value of the dataset.
"""
date: str
"""
The date of the dataset.
"""
class PredictionParams(TypedDict):
dataset: List[Dataset]
"""
The dataset to make predictions on. This is an array of object with keys date and value. See example below for more information.
"""
steps: NotRequired[int]
"""
The number of predictions to make. Min: 1, Max: 500. Default: 5.
"""
class PredictionResponse(BaseResponse):
steps: int
"""
The number of steps predicted.
"""
prediction: List[Dataset]
"""
The predictions made on the dataset.
"""
class Prediction(ClientConfig):
config: RequestConfig
def __init__(
self,
api_key: str,
base_url: str,
headers: Union[Dict[str, str], None] = None,
):
super().__init__(api_key, base_url, headers)
self.config = RequestConfig(
base_url=base_url,
api_key=api_key,
headers=headers,
)
def predict(self, params: PredictionParams) -> PredictionResponse:
path = "/ai/prediction"
resp = Request(
config=self.config,
path=path,
params=cast(Dict[Any, Any], params),
verb="post",
).perform_with_content()
return resp
class AsyncPrediction(ClientConfig):
config: RequestConfig
def __init__(
self,
api_key: str,
base_url: str,
headers: Union[Dict[str, str], None] = None,
):
super().__init__(api_key, base_url, headers)
self.config = RequestConfig(
base_url=base_url,
api_key=api_key,
headers=headers,
)
async def predict(self, params: PredictionParams) -> PredictionResponse:
path = "/ai/prediction"
resp = await AsyncRequest(
config=self.config,
path=path,
params=cast(Dict[Any, Any], params),
verb="post",
).perform_with_content()
return resp