|
3 | 3 | import os |
4 | 4 | from typing import Any |
5 | 5 | from typing import Dict |
| 6 | +from typing import List |
6 | 7 | from typing import Optional |
7 | 8 |
|
8 | 9 | from .utils import vars_to_str |
@@ -76,6 +77,48 @@ def from_stop_response(cls, response: Dict[str, Any]) -> 'ModelOperationResult': |
76 | 77 | hosting_platform=response.get('hostingPlatform', ''), |
77 | 78 | ) |
78 | 79 |
|
| 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 | + |
79 | 122 | def get_message(self) -> str: |
80 | 123 | """ |
81 | 124 | Get a human-readable message about the operation. |
@@ -195,6 +238,20 @@ def stop(self) -> ModelOperationResult: |
195 | 238 | raise ManagementError(msg='No manager associated with this inference API') |
196 | 239 | return self._manager.stop(self.name) |
197 | 240 |
|
| 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 | + |
198 | 255 |
|
199 | 256 | class InferenceAPIManager(object): |
200 | 257 | """ |
@@ -263,3 +320,38 @@ def stop(self, model_name: str) -> ModelOperationResult: |
263 | 320 | raise ManagementError(msg='Manager not initialized') |
264 | 321 | res = self._manager._post(f'models/{model_name}/stop') |
265 | 322 | 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