mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-10 20:19:22 +00:00
feat: support listing all for llama stack list-providers
For ease of reading, sort the output rows by type. Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
This commit is contained in:
parent
24385cfd03
commit
89c82dce4f
2 changed files with 26 additions and 7 deletions
|
@ -21,15 +21,19 @@ class StackListProviders(Subcommand):
|
||||||
self._add_arguments()
|
self._add_arguments()
|
||||||
self.parser.set_defaults(func=self._run_providers_list_cmd)
|
self.parser.set_defaults(func=self._run_providers_list_cmd)
|
||||||
|
|
||||||
def _add_arguments(self):
|
@property
|
||||||
|
def providable_apis(self):
|
||||||
from llama_stack.distribution.distribution import providable_apis
|
from llama_stack.distribution.distribution import providable_apis
|
||||||
|
|
||||||
api_values = [api.value for api in providable_apis()]
|
return [api.value for api in providable_apis()]
|
||||||
|
|
||||||
|
def _add_arguments(self):
|
||||||
self.parser.add_argument(
|
self.parser.add_argument(
|
||||||
"api",
|
"api",
|
||||||
type=str,
|
type=str,
|
||||||
choices=api_values,
|
choices=self.providable_apis,
|
||||||
help="API to list providers for (one of: {})".format(api_values),
|
nargs="?",
|
||||||
|
help="API to list providers for. List all if not specified.",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _run_providers_list_cmd(self, args: argparse.Namespace) -> None:
|
def _run_providers_list_cmd(self, args: argparse.Namespace) -> None:
|
||||||
|
@ -37,20 +41,29 @@ class StackListProviders(Subcommand):
|
||||||
from llama_stack.distribution.distribution import Api, get_provider_registry
|
from llama_stack.distribution.distribution import Api, get_provider_registry
|
||||||
|
|
||||||
all_providers = get_provider_registry()
|
all_providers = get_provider_registry()
|
||||||
providers_for_api = all_providers[Api(args.api)]
|
if args.api:
|
||||||
|
providers = [(args.api, all_providers[Api(args.api)])]
|
||||||
|
else:
|
||||||
|
providers = [(k.value, prov) for k, prov in all_providers.items()]
|
||||||
|
|
||||||
|
providers = [p for api, p in providers if api in self.providable_apis]
|
||||||
|
|
||||||
# eventually, this should query a registry at llama.meta.com/llamastack/distributions
|
# eventually, this should query a registry at llama.meta.com/llamastack/distributions
|
||||||
headers = [
|
headers = [
|
||||||
|
"API Type",
|
||||||
"Provider Type",
|
"Provider Type",
|
||||||
"PIP Package Dependencies",
|
"PIP Package Dependencies",
|
||||||
]
|
]
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for spec in providers_for_api.values():
|
|
||||||
|
specs = [spec for p in providers for spec in p.values()]
|
||||||
|
for spec in specs:
|
||||||
if spec.is_sample:
|
if spec.is_sample:
|
||||||
continue
|
continue
|
||||||
rows.append(
|
rows.append(
|
||||||
[
|
[
|
||||||
|
spec.api.value,
|
||||||
spec.provider_type,
|
spec.provider_type,
|
||||||
",".join(spec.pip_packages),
|
",".join(spec.pip_packages),
|
||||||
]
|
]
|
||||||
|
@ -59,4 +72,5 @@ class StackListProviders(Subcommand):
|
||||||
rows,
|
rows,
|
||||||
headers,
|
headers,
|
||||||
separate_rows=True,
|
separate_rows=True,
|
||||||
|
sort_by=(0, 1),
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
from termcolor import cprint
|
from termcolor import cprint
|
||||||
|
|
||||||
|
@ -39,11 +40,15 @@ def format_row(row, col_widths):
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
def print_table(rows, headers=None, separate_rows: bool = False):
|
def print_table(rows, headers=None, separate_rows: bool = False, sort_by: Iterable[int] = tuple()):
|
||||||
def itemlen(item):
|
def itemlen(item):
|
||||||
return max([len(line) for line in strip_ansi_colors(item).split("\n")])
|
return max([len(line) for line in strip_ansi_colors(item).split("\n")])
|
||||||
|
|
||||||
rows = [[x or "" for x in row] for row in rows]
|
rows = [[x or "" for x in row] for row in rows]
|
||||||
|
|
||||||
|
if sort_by:
|
||||||
|
rows.sort(key=lambda x: tuple(x[i] for i in sort_by))
|
||||||
|
|
||||||
if not headers:
|
if not headers:
|
||||||
col_widths = [max(itemlen(item) for item in col) for col in zip(*rows)]
|
col_widths = [max(itemlen(item) for item in col) for col in zip(*rows)]
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue