1
1
from pprint import pformat
2
+ from typing import NamedTuple
2
3
3
4
import click
4
5
import questionary as q
5
6
from rich .table import Table
7
+ from typing_extensions import Literal
6
8
7
9
from launch .cli .client import init_client
8
10
from launch .cli .console import pretty_print , spinner
@@ -16,10 +18,34 @@ def endpoints(ctx: click.Context):
16
18
"""Endpoints is a wrapper around model endpoints in Scale Launch"""
17
19
18
20
21
+ class EndpointRow (NamedTuple ):
22
+ id : str
23
+ endpoint_name : str
24
+ bundle_name : str
25
+ status : Literal ["READY" , "UPDATE_PENDING" , "UPDATE_IN_PROGRESS" , "UPDATE_FAILED" , "DELETE_IN_PROGRESS" ]
26
+ endpoint_type : Literal ["async" , "sync" ]
27
+ min_workers : str # rich.table requires all strings
28
+ max_workers : str
29
+ available_workers : str
30
+ unavailable_workers : str
31
+ num_gpus : str
32
+ metadata : str
33
+
34
+
19
35
@click .pass_context
20
36
@endpoints .command ("list" )
37
+ @click .option ("-o" , "--orderby" , required = False , type = click .Choice (EndpointRow ._fields ), help = "How to order the table" )
38
+ @click .option (
39
+ "-d" ,
40
+ "--descending" ,
41
+ required = False ,
42
+ is_flag = True ,
43
+ type = bool ,
44
+ default = False ,
45
+ help = "Whether to sort in descending order" ,
46
+ )
21
47
@click .pass_context
22
- def list_endpoints (ctx : click .Context ):
48
+ def list_endpoints (ctx : click .Context , orderby , descending ):
23
49
"""List all of your Endpoints"""
24
50
client = init_client (ctx )
25
51
@@ -28,20 +54,22 @@ def list_endpoints(ctx: click.Context):
28
54
"Endpoint name" ,
29
55
"Bundle name" ,
30
56
"Status" ,
31
- "Endpoint type" ,
32
- "Min Workers" ,
33
- "Max Workers" ,
34
- "Available Workers" ,
35
- "Unavailable Workers" ,
57
+ "Endpoint\n type" ,
58
+ "Min\n Workers" ,
59
+ "Max\n Workers" ,
60
+ "Available\n Workers" ,
61
+ "Unavailable\n Workers" ,
62
+ "Num\n GPUs" ,
36
63
"Metadata" ,
37
64
title = "Endpoints" ,
38
65
title_justify = "left" ,
39
66
)
40
67
41
68
with spinner ("Fetching model endpoints" ):
42
69
model_endpoints = client .list_model_endpoints ()
70
+ endpoint_rows = []
43
71
for servable_endpoint in model_endpoints :
44
- table . add_row (
72
+ row = EndpointRow (
45
73
servable_endpoint .model_endpoint .id ,
46
74
servable_endpoint .model_endpoint .name ,
47
75
servable_endpoint .model_endpoint .bundle_name ,
@@ -51,8 +79,18 @@ def list_endpoints(ctx: click.Context):
51
79
str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("max_workers" , "" )),
52
80
str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("available_workers" , "" )),
53
81
str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("unavailable_workers" , "" )),
82
+ str ((servable_endpoint .model_endpoint .resource_state or {}).get ("gpus" , "0" )),
54
83
servable_endpoint .model_endpoint .metadata or "{}" ,
55
84
)
85
+ endpoint_rows .append (row )
86
+
87
+ if orderby is not None :
88
+ endpoint_rows = sorted (endpoint_rows , key = lambda x : getattr (x , orderby ), reverse = descending )
89
+
90
+ for row in endpoint_rows :
91
+ table .add_row (* row )
92
+
93
+ pretty_print (table )
56
94
57
95
pretty_print (table )
58
96
0 commit comments