forked from phoenix-oss/llama-stack-mirror
# What does this PR do? Before: ``` llama stack list-providers agents +------------------------+-----------------------------------------------------------------------+ | Provider Type | PIP Package Dependencies | +------------------------+-----------------------------------------------------------------------+ | inline::meta-reference | matplotlib,pillow,pandas,scikit-learn,aiosqlite,psycopg2-binary,redis | +------------------------+-----------------------------------------------------------------------+ | remote::sample | | +------------------------+-----------------------------------------------------------------------+ ``` After: ``` llama stack list-providers agents +------------------------+-----------------------------------------------------------------------+ | Provider Type | PIP Package Dependencies | +------------------------+-----------------------------------------------------------------------+ | inline::meta-reference | matplotlib,pillow,pandas,scikit-learn,aiosqlite,psycopg2-binary,redis | +------------------------+-----------------------------------------------------------------------+ ``` [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan Manually. [//]: # (## Documentation) Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
62 lines
2 KiB
Python
62 lines
2 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
import argparse
|
|
|
|
from llama_stack.cli.subcommand import Subcommand
|
|
|
|
|
|
class StackListProviders(Subcommand):
|
|
def __init__(self, subparsers: argparse._SubParsersAction):
|
|
super().__init__()
|
|
self.parser = subparsers.add_parser(
|
|
"list-providers",
|
|
prog="llama stack list-providers",
|
|
description="Show available Llama Stack Providers for an API",
|
|
formatter_class=argparse.RawTextHelpFormatter,
|
|
)
|
|
self._add_arguments()
|
|
self.parser.set_defaults(func=self._run_providers_list_cmd)
|
|
|
|
def _add_arguments(self):
|
|
from llama_stack.distribution.distribution import providable_apis
|
|
|
|
api_values = [api.value for api in providable_apis()]
|
|
self.parser.add_argument(
|
|
"api",
|
|
type=str,
|
|
choices=api_values,
|
|
help="API to list providers for (one of: {})".format(api_values),
|
|
)
|
|
|
|
def _run_providers_list_cmd(self, args: argparse.Namespace) -> None:
|
|
from llama_stack.cli.table import print_table
|
|
from llama_stack.distribution.distribution import Api, get_provider_registry
|
|
|
|
all_providers = get_provider_registry()
|
|
providers_for_api = all_providers[Api(args.api)]
|
|
|
|
# eventually, this should query a registry at llama.meta.com/llamastack/distributions
|
|
headers = [
|
|
"Provider Type",
|
|
"PIP Package Dependencies",
|
|
]
|
|
|
|
rows = []
|
|
for spec in providers_for_api.values():
|
|
if spec.is_sample:
|
|
continue
|
|
rows.append(
|
|
[
|
|
spec.provider_type,
|
|
",".join(spec.pip_packages),
|
|
]
|
|
)
|
|
print_table(
|
|
rows,
|
|
headers,
|
|
separate_rows=True,
|
|
)
|