Skip to content

Commit e9ee4d0

Browse files
aura models show and drop commands initial commit
1 parent 72650d5 commit e9ee4d0

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

singlestoredb/fusion/handlers/models.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .files import ShowFilesHandler
1111
from .utils import get_file_space
1212
from .utils import get_inference_api
13+
from .utils import get_inference_api_manager
1314

1415

1516
class ShowModelsHandler(ShowFilesHandler):
@@ -346,3 +347,96 @@ def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
346347

347348

348349
StopModelHandler.register(overwrite=True)
350+
351+
352+
class ShowInferenceAPIsHandler(SQLHandler):
353+
"""
354+
SHOW INFERENCE APIS ;
355+
356+
Description
357+
-----------
358+
Displays the list of inference APIs in the current project.
359+
360+
Example
361+
--------
362+
The following command lists all inference APIs::
363+
364+
SHOW INFERENCE APIS;
365+
366+
See Also
367+
--------
368+
* ``START MODEL model_name``
369+
* ``STOP MODEL model_name``
370+
* ``DROP INFERENCE API model_name``
371+
372+
""" # noqa: E501
373+
374+
def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
375+
inference_api_manager = get_inference_api_manager()
376+
models = inference_api_manager.show()
377+
378+
res = FusionSQLResult()
379+
res.add_field('Model Name', result.STRING)
380+
res.add_field('Status', result.STRING)
381+
382+
rows = []
383+
for model in models:
384+
rows.append((
385+
model.name,
386+
model.status,
387+
))
388+
389+
res.set_rows(rows)
390+
return res
391+
392+
393+
ShowInferenceAPIsHandler.register(overwrite=True)
394+
395+
396+
class DropInferenceAPIHandler(SQLHandler):
397+
"""
398+
DROP INFERENCE API model_name ;
399+
400+
# Model Name
401+
model_name = '<model-name>'
402+
403+
Description
404+
-----------
405+
Drops (deletes) an inference API model.
406+
407+
Arguments
408+
---------
409+
* ``<model-name>``: Name of the model to drop.
410+
411+
Example
412+
--------
413+
The following command drops an inference API::
414+
415+
DROP INFERENCE API my_model;
416+
417+
See Also
418+
--------
419+
* ``START MODEL model_name``
420+
* ``STOP MODEL model_name``
421+
* ``SHOW INFERENCE APIS``
422+
423+
""" # noqa: E501
424+
425+
def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
426+
inference_api = get_inference_api(params)
427+
operation_result = inference_api.drop()
428+
429+
res = FusionSQLResult()
430+
res.add_field('Status', result.STRING)
431+
res.add_field('Message', result.STRING)
432+
res.set_rows([
433+
(
434+
operation_result.status,
435+
operation_result.get_message(),
436+
),
437+
])
438+
439+
return res
440+
441+
442+
DropInferenceAPIHandler.register(overwrite=True)

singlestoredb/management/inference_api.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from typing import Any
55
from typing import Dict
6+
from typing import List
67
from typing import Optional
78

89
from .utils import vars_to_str
@@ -76,6 +77,48 @@ def from_stop_response(cls, response: Dict[str, Any]) -> 'ModelOperationResult':
7677
hosting_platform=response.get('hostingPlatform', ''),
7778
)
7879

80+
@classmethod
81+
def from_drop_response(cls, response: Dict[str, Any]) -> 'ModelOperationResult':
82+
"""
83+
Create a ModelOperationResult from a drop operation response.
84+
85+
Parameters
86+
----------
87+
response : dict
88+
Response from the drop endpoint
89+
90+
Returns
91+
-------
92+
ModelOperationResult
93+
94+
"""
95+
return cls(
96+
name=response.get('name', ''),
97+
status=response.get('status', 'Deleted'),
98+
hosting_platform=response.get('hostingPlatform', ''),
99+
)
100+
101+
@classmethod
102+
def from_show_response(cls, response: Dict[str, Any]) -> 'ModelOperationResult':
103+
"""
104+
Create a ModelOperationResult from a show operation response.
105+
106+
Parameters
107+
----------
108+
response : dict
109+
Response from the show endpoint (single model info)
110+
111+
Returns
112+
-------
113+
ModelOperationResult
114+
115+
"""
116+
return cls(
117+
name=response.get('name', ''),
118+
status=response.get('status', ''),
119+
hosting_platform=response.get('hostingPlatform', ''),
120+
)
121+
79122
def get_message(self) -> str:
80123
"""
81124
Get a human-readable message about the operation.
@@ -195,6 +238,20 @@ def stop(self) -> ModelOperationResult:
195238
raise ManagementError(msg='No manager associated with this inference API')
196239
return self._manager.stop(self.name)
197240

241+
def drop(self) -> ModelOperationResult:
242+
"""
243+
Drop this inference API model.
244+
245+
Returns
246+
-------
247+
ModelOperationResult
248+
Result object containing status information about the dropped model
249+
250+
"""
251+
if self._manager is None:
252+
raise ManagementError(msg='No manager associated with this inference API')
253+
return self._manager.drop(self.name)
254+
198255

199256
class InferenceAPIManager(object):
200257
"""
@@ -263,3 +320,38 @@ def stop(self, model_name: str) -> ModelOperationResult:
263320
raise ManagementError(msg='Manager not initialized')
264321
res = self._manager._post(f'models/{model_name}/stop')
265322
return ModelOperationResult.from_stop_response(res.json())
323+
324+
def show(self) -> List[ModelOperationResult]:
325+
"""
326+
Show all inference APIs in the project.
327+
328+
Returns
329+
-------
330+
List[ModelOperationResult]
331+
List of ModelOperationResult objects with status information
332+
333+
"""
334+
if self._manager is None:
335+
raise ManagementError(msg='Manager not initialized')
336+
res = self._manager._get('models').json()
337+
return [ModelOperationResult.from_show_response(api) for api in res]
338+
339+
def drop(self, model_name: str) -> ModelOperationResult:
340+
"""
341+
Drop an inference API model.
342+
343+
Parameters
344+
----------
345+
model_name : str
346+
Name of the model to drop
347+
348+
Returns
349+
-------
350+
ModelOperationResult
351+
Result object containing status information about the dropped model
352+
353+
"""
354+
if self._manager is None:
355+
raise ManagementError(msg='Manager not initialized')
356+
res = self._manager._delete(f'models/{model_name}/drop')
357+
return ModelOperationResult.from_drop_response(res.json())

0 commit comments

Comments
 (0)