Skip to content

Commit e436a8d

Browse files
review changes
1 parent 44abeed commit e436a8d

File tree

2 files changed

+132
-18
lines changed

2 files changed

+132
-18
lines changed

singlestoredb/fusion/handlers/models.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from ..handler import SQLHandler
88
from ..result import FusionSQLResult
9+
from .. import result
910
from .files import ShowFilesHandler
1011
from .utils import get_file_space
1112
from .utils import get_inference_api
@@ -281,8 +282,21 @@ class StartModelHandler(SQLHandler):
281282

282283
def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
283284
inference_api = get_inference_api(params)
284-
inference_api.start()
285-
return None
285+
operation_result = inference_api.start()
286+
287+
res = FusionSQLResult()
288+
res.add_field('Model', result.STRING)
289+
res.add_field('Status', result.STRING)
290+
res.add_field('Message', result.STRING)
291+
res.set_rows([
292+
(
293+
operation_result.name,
294+
operation_result.status,
295+
operation_result.get_message(),
296+
),
297+
])
298+
299+
return res
286300

287301

288302
StartModelHandler.register(overwrite=True)
@@ -318,8 +332,21 @@ class StopModelHandler(SQLHandler):
318332

319333
def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
320334
inference_api = get_inference_api(params)
321-
inference_api.stop()
322-
return None
335+
operation_result = inference_api.stop()
336+
337+
res = FusionSQLResult()
338+
res.add_field('Model', result.STRING)
339+
res.add_field('Status', result.STRING)
340+
res.add_field('Message', result.STRING)
341+
res.set_rows([
342+
(
343+
operation_result.name,
344+
operation_result.status,
345+
operation_result.get_message(),
346+
),
347+
])
348+
349+
return res
323350

324351

325352
StopModelHandler.register(overwrite=True)

singlestoredb/management/inference_api.py

Lines changed: 101 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,93 @@
1010
from 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+
13100
class 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

Comments
 (0)