From 9c5c6501370dbc0bc03d217728fb115241dcf3d2 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Thu, 30 Jan 2025 10:38:27 -0800 Subject: [PATCH 1/2] Improve models, shields list tables --- .gitignore | 1 + .../lib/cli/models/models.py | 37 +++++++++++++---- .../lib/cli/shields/shields.py | 40 +++++++++++++++---- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 87797408..bcfc2a3c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ dist .envrc codegen.log Brewfile.lock.json +.DS_Store diff --git a/src/llama_stack_client/lib/cli/models/models.py b/src/llama_stack_client/lib/cli/models/models.py index a7eb2c44..1f1ec1ac 100644 --- a/src/llama_stack_client/lib/cli/models/models.py +++ b/src/llama_stack_client/lib/cli/models/models.py @@ -27,22 +27,43 @@ def list_models(ctx): console = Console() headers = [ + "model_type", "identifier", - "provider_id", - "provider_resource_id", + "provider_alias", "metadata", - "model_type", + "provider_id", ] response = client.models.list() if response: - table = Table() - for header in headers: - table.add_column(header) + table = Table( + show_lines=True, # Add lines between rows for better readability + padding=(0, 1), # Add horizontal padding + expand=True, # Allow table to use full width + row_styles=["none", "dim"], # Alternate row colors + ) + + # Configure columns with specific styling + table.add_column("model_type", style="blue") + table.add_column("identifier", style="bold cyan", no_wrap=True, overflow="fold") + table.add_column( + "provider_resource_id", style="yellow", no_wrap=True, overflow="fold" + ) + table.add_column("metadata", style="magenta", max_width=30, overflow="fold") + table.add_column("provider_id", style="green", max_width=20) for item in response: - row = [str(getattr(item, header)) for header in headers] - table.add_row(*row) + table.add_row( + item.model_type, + item.identifier, + item.provider_resource_id, + str(item.metadata or ""), + item.provider_id, + ) + + # Create a title for the table + console.print("\n[bold]Available Models[/bold]\n") console.print(table) + console.print(f"\nTotal models: {len(response)}\n") @click.command(name="get") diff --git a/src/llama_stack_client/lib/cli/shields/shields.py b/src/llama_stack_client/lib/cli/shields/shields.py index ec12b4ab..cecdc8c1 100644 --- a/src/llama_stack_client/lib/cli/shields/shields.py +++ b/src/llama_stack_client/lib/cli/shields/shields.py @@ -29,17 +29,36 @@ def list(ctx): console = Console() shields_list_response = client.shields.list() - headers = [] - if shields_list_response and len(shields_list_response) > 0: - headers = sorted(shields_list_response[0].__dict__.keys()) + headers = [ + "identifier", + "provider_alias", + "params", + "provider_id", + ] if shields_list_response: - table = Table() - for header in headers: - table.add_column(header) + table = Table( + show_lines=True, # Add lines between rows for better readability + padding=(0, 1), # Add horizontal padding + expand=True, # Allow table to use full width + row_styles=["none", "dim"], # Alternate row colors + ) + + table.add_column("identifier", style="bold cyan", no_wrap=True, overflow="fold") + table.add_column( + "provider_alias", style="yellow", no_wrap=True, overflow="fold" + ) + table.add_column("params", style="magenta", max_width=30, overflow="fold") + table.add_column("provider_id", style="green", max_width=20) for item in shields_list_response: - table.add_row(*[str(getattr(item, header)) for header in headers]) + table.add_row( + item.identifier, + item.provider_resource_id, + str(item.params or ""), + item.provider_id, + ) + console.print(table) @@ -47,7 +66,12 @@ def list(ctx): @click.option("--shield-id", required=True, help="Id of the shield") @click.option("--provider-id", help="Provider ID for the shield", default=None) @click.option("--provider-shield-id", help="Provider's shield ID", default=None) -@click.option("--params", type=str, help="JSON configuration parameters for the shield", default=None) +@click.option( + "--params", + type=str, + help="JSON configuration parameters for the shield", + default=None, +) @click.pass_context @handle_client_errors("register shield") def register( From 5bd112b3afd1740cfbbcc4ad6c5bf6e9c5974480 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Thu, 30 Jan 2025 10:41:46 -0800 Subject: [PATCH 2/2] Avoid the alternate dim vs not madness --- src/llama_stack_client/lib/cli/models/models.py | 1 - src/llama_stack_client/lib/cli/shields/shields.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/llama_stack_client/lib/cli/models/models.py b/src/llama_stack_client/lib/cli/models/models.py index 1f1ec1ac..12734806 100644 --- a/src/llama_stack_client/lib/cli/models/models.py +++ b/src/llama_stack_client/lib/cli/models/models.py @@ -39,7 +39,6 @@ def list_models(ctx): show_lines=True, # Add lines between rows for better readability padding=(0, 1), # Add horizontal padding expand=True, # Allow table to use full width - row_styles=["none", "dim"], # Alternate row colors ) # Configure columns with specific styling diff --git a/src/llama_stack_client/lib/cli/shields/shields.py b/src/llama_stack_client/lib/cli/shields/shields.py index cecdc8c1..3c0999c1 100644 --- a/src/llama_stack_client/lib/cli/shields/shields.py +++ b/src/llama_stack_client/lib/cli/shields/shields.py @@ -41,7 +41,6 @@ def list(ctx): show_lines=True, # Add lines between rows for better readability padding=(0, 1), # Add horizontal padding expand=True, # Allow table to use full width - row_styles=["none", "dim"], # Alternate row colors ) table.add_column("identifier", style="bold cyan", no_wrap=True, overflow="fold")