1010from singlestoredb .management .manager import Manager
1111
1212
13+ class ModelOperationResult (object ):
14+ """
15+ Result of a model start or stop operation.
16+
17+ Attributes
18+ ----------
19+ name : str
20+ Name of the model
21+ status : str
22+ Current status of the model (e.g., 'Active', 'Initializing', 'Suspended')
23+ hosting_platform : str
24+ Hosting platform (e.g., 'Nova', 'Amazon', 'Azure')
25+ """
26+
27+ def __init__ (
28+ self ,
29+ name : str ,
30+ status : str ,
31+ hosting_platform : str ,
32+ ):
33+ self .name = name
34+ self .status = status
35+ self .hosting_platform = hosting_platform
36+
37+ @classmethod
38+ def from_start_response (cls , response : Dict [str , Any ]) -> 'ModelOperationResult' :
39+ """
40+ Create a ModelOperationResult from a start operation response.
41+
42+ Parameters
43+ ----------
44+ response : dict
45+ Response from the start endpoint
46+
47+ Returns
48+ -------
49+ ModelOperationResult
50+
51+ """
52+ return cls (
53+ name = response .get ('modelName' , '' ),
54+ status = 'Initializing' ,
55+ hosting_platform = response .get ('hostingPlatform' , '' ),
56+ )
57+
58+ @classmethod
59+ def from_stop_response (cls , response : Dict [str , Any ]) -> 'ModelOperationResult' :
60+ """
61+ Create a ModelOperationResult from a stop operation response.
62+
63+ Parameters
64+ ----------
65+ response : dict
66+ Response from the stop endpoint
67+
68+ Returns
69+ -------
70+ ModelOperationResult
71+
72+ """
73+ return cls (
74+ name = response .get ('name' , '' ),
75+ status = response .get ('status' , 'Suspended' ),
76+ hosting_platform = response .get ('hostingPlatform' , '' ),
77+ )
78+
79+ def get_message (self ) -> str :
80+ """
81+ Get a human-readable message about the operation.
82+
83+ Returns
84+ -------
85+ str
86+ Message describing the operation result
87+
88+ """
89+ return f"Model '{ self .name } ' status is now { self .status } "
90+
91+ def __str__ (self ) -> str :
92+ """Return string representation."""
93+ return vars_to_str (self )
94+
95+ def __repr__ (self ) -> str :
96+ """Return string representation."""
97+ return str (self )
98+
99+
13100class InferenceAPIInfo (object ):
14101 """
15102 Inference API definition.
@@ -80,28 +167,28 @@ def __repr__(self) -> str:
80167 """Return string representation."""
81168 return str (self )
82169
83- def start (self ) -> Dict [ str , Any ] :
170+ def start (self ) -> ModelOperationResult :
84171 """
85172 Start this inference API model.
86173
87174 Returns
88175 -------
89- dict
90- Response from the start operation
176+ ModelOperationResult
177+ Result object containing status information about the started model
91178
92179 """
93180 if self ._manager is None :
94181 raise ManagementError (msg = 'No manager associated with this inference API' )
95182 return self ._manager .start (self .name )
96183
97- def stop (self ) -> Dict [ str , Any ] :
184+ def stop (self ) -> ModelOperationResult :
98185 """
99186 Stop this inference API model.
100187
101188 Returns
102189 -------
103- dict
104- Response from the stop operation
190+ ModelOperationResult
191+ Result object containing status information about the stopped model
105192
106193 """
107194 if self ._manager is None :
@@ -137,7 +224,7 @@ def get(self, model_name: str) -> InferenceAPIInfo:
137224 inference_api ._manager = self # Associate the manager
138225 return inference_api
139226
140- def start (self , model_name : str ) -> Dict [ str , Any ] :
227+ def start (self , model_name : str ) -> ModelOperationResult :
141228 """
142229 Start an inference API model.
143230
@@ -148,16 +235,16 @@ def start(self, model_name: str) -> Dict[str, Any]:
148235
149236 Returns
150237 -------
151- dict
152- Response from the start operation
238+ ModelOperationResult
239+ Result object containing status information about the started model
153240
154241 """
155242 if self ._manager is None :
156243 raise ManagementError (msg = 'Manager not initialized' )
157244 res = self ._manager ._post (f'inferenceapis/{ model_name } /start' )
158- return res .json ()
245+ return ModelOperationResult . from_start_response ( res .json () )
159246
160- def stop (self , model_name : str ) -> Dict [ str , Any ] :
247+ def stop (self , model_name : str ) -> ModelOperationResult :
161248 """
162249 Stop an inference API model.
163250
@@ -168,11 +255,11 @@ def stop(self, model_name: str) -> Dict[str, Any]:
168255
169256 Returns
170257 -------
171- dict
172- Response from the stop operation
258+ ModelOperationResult
259+ Result object containing status information about the stopped model
173260
174261 """
175262 if self ._manager is None :
176263 raise ManagementError (msg = 'Manager not initialized' )
177264 res = self ._manager ._post (f'inferenceapis/{ model_name } /stop' )
178- return res .json ()
265+ return ModelOperationResult . from_stop_response ( res .json () )
0 commit comments