Skip to content

Commit 7412c46

Browse files
authored
Add features to launch endpoints list (#80)
* add orderby, descending and num_gpus * reverting changes * typing_extensions for py37
1 parent de0b50d commit 7412c46

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

launch/cli/endpoints.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from pprint import pformat
2+
from typing import NamedTuple
23

34
import click
45
import questionary as q
56
from rich.table import Table
7+
from typing_extensions import Literal
68

79
from launch.cli.client import init_client
810
from launch.cli.console import pretty_print, spinner
@@ -16,10 +18,34 @@ def endpoints(ctx: click.Context):
1618
"""Endpoints is a wrapper around model endpoints in Scale Launch"""
1719

1820

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+
1935
@click.pass_context
2036
@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+
)
2147
@click.pass_context
22-
def list_endpoints(ctx: click.Context):
48+
def list_endpoints(ctx: click.Context, orderby, descending):
2349
"""List all of your Endpoints"""
2450
client = init_client(ctx)
2551

@@ -28,20 +54,22 @@ def list_endpoints(ctx: click.Context):
2854
"Endpoint name",
2955
"Bundle name",
3056
"Status",
31-
"Endpoint type",
32-
"Min Workers",
33-
"Max Workers",
34-
"Available Workers",
35-
"Unavailable Workers",
57+
"Endpoint\ntype",
58+
"Min\nWorkers",
59+
"Max\nWorkers",
60+
"Available\nWorkers",
61+
"Unavailable\nWorkers",
62+
"Num\nGPUs",
3663
"Metadata",
3764
title="Endpoints",
3865
title_justify="left",
3966
)
4067

4168
with spinner("Fetching model endpoints"):
4269
model_endpoints = client.list_model_endpoints()
70+
endpoint_rows = []
4371
for servable_endpoint in model_endpoints:
44-
table.add_row(
72+
row = EndpointRow(
4573
servable_endpoint.model_endpoint.id,
4674
servable_endpoint.model_endpoint.name,
4775
servable_endpoint.model_endpoint.bundle_name,
@@ -51,8 +79,18 @@ def list_endpoints(ctx: click.Context):
5179
str((servable_endpoint.model_endpoint.deployment_state or {}).get("max_workers", "")),
5280
str((servable_endpoint.model_endpoint.deployment_state or {}).get("available_workers", "")),
5381
str((servable_endpoint.model_endpoint.deployment_state or {}).get("unavailable_workers", "")),
82+
str((servable_endpoint.model_endpoint.resource_state or {}).get("gpus", "0")),
5483
servable_endpoint.model_endpoint.metadata or "{}",
5584
)
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)
5694

5795
pretty_print(table)
5896

0 commit comments

Comments
 (0)