Skip to content

Commit 43a2fe0

Browse files
authored
Improve models, shields list tables (#105)
Better rendering to avoid truncating most important pieces of information ## Test Plan Small width <img width="821" alt="image" src="https://github.com/user-attachments/assets/055bd4c4-76b1-4718-8894-4841cd0b2323" /> Large width <img width="1684" alt="image" src="https://github.com/user-attachments/assets/84b770d6-ad59-4809-84d4-b62152f8f57b" />
1 parent c57d9ec commit 43a2fe0

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ dist
1414
.envrc
1515
codegen.log
1616
Brewfile.lock.json
17+
.DS_Store

src/llama_stack_client/lib/cli/models/models.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,42 @@ def list_models(ctx):
2727
console = Console()
2828

2929
headers = [
30+
"model_type",
3031
"identifier",
31-
"provider_id",
32-
"provider_resource_id",
32+
"provider_alias",
3333
"metadata",
34-
"model_type",
34+
"provider_id",
3535
]
3636
response = client.models.list()
3737
if response:
38-
table = Table()
39-
for header in headers:
40-
table.add_column(header)
38+
table = Table(
39+
show_lines=True, # Add lines between rows for better readability
40+
padding=(0, 1), # Add horizontal padding
41+
expand=True, # Allow table to use full width
42+
)
43+
44+
# Configure columns with specific styling
45+
table.add_column("model_type", style="blue")
46+
table.add_column("identifier", style="bold cyan", no_wrap=True, overflow="fold")
47+
table.add_column(
48+
"provider_resource_id", style="yellow", no_wrap=True, overflow="fold"
49+
)
50+
table.add_column("metadata", style="magenta", max_width=30, overflow="fold")
51+
table.add_column("provider_id", style="green", max_width=20)
4152

4253
for item in response:
43-
row = [str(getattr(item, header)) for header in headers]
44-
table.add_row(*row)
54+
table.add_row(
55+
item.model_type,
56+
item.identifier,
57+
item.provider_resource_id,
58+
str(item.metadata or ""),
59+
item.provider_id,
60+
)
61+
62+
# Create a title for the table
63+
console.print("\n[bold]Available Models[/bold]\n")
4564
console.print(table)
65+
console.print(f"\nTotal models: {len(response)}\n")
4666

4767

4868
@click.command(name="get")

src/llama_stack_client/lib/cli/shields/shields.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,48 @@ def list(ctx):
2929
console = Console()
3030

3131
shields_list_response = client.shields.list()
32-
headers = []
33-
if shields_list_response and len(shields_list_response) > 0:
34-
headers = sorted(shields_list_response[0].__dict__.keys())
32+
headers = [
33+
"identifier",
34+
"provider_alias",
35+
"params",
36+
"provider_id",
37+
]
3538

3639
if shields_list_response:
37-
table = Table()
38-
for header in headers:
39-
table.add_column(header)
40+
table = Table(
41+
show_lines=True, # Add lines between rows for better readability
42+
padding=(0, 1), # Add horizontal padding
43+
expand=True, # Allow table to use full width
44+
)
45+
46+
table.add_column("identifier", style="bold cyan", no_wrap=True, overflow="fold")
47+
table.add_column(
48+
"provider_alias", style="yellow", no_wrap=True, overflow="fold"
49+
)
50+
table.add_column("params", style="magenta", max_width=30, overflow="fold")
51+
table.add_column("provider_id", style="green", max_width=20)
4052

4153
for item in shields_list_response:
42-
table.add_row(*[str(getattr(item, header)) for header in headers])
54+
table.add_row(
55+
item.identifier,
56+
item.provider_resource_id,
57+
str(item.params or ""),
58+
item.provider_id,
59+
)
60+
4361
console.print(table)
4462

4563

4664
@shields.command()
4765
@click.option("--shield-id", required=True, help="Id of the shield")
4866
@click.option("--provider-id", help="Provider ID for the shield", default=None)
4967
@click.option("--provider-shield-id", help="Provider's shield ID", default=None)
50-
@click.option("--params", type=str, help="JSON configuration parameters for the shield", default=None)
68+
@click.option(
69+
"--params",
70+
type=str,
71+
help="JSON configuration parameters for the shield",
72+
default=None,
73+
)
5174
@click.pass_context
5275
@handle_client_errors("register shield")
5376
def register(

0 commit comments

Comments
 (0)