| 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # This source code is licensed under the terms described in the LICENSE file in |
| 5 | # the root directory of this source tree. |
| 6 | |
| 7 | import argparse |
| 8 | |
| 9 | from llama_stack.cli.subcommand import Subcommand |
| 10 | |
| 11 | |
| 12 | class StackListProviders(Subcommand): |
| 13 | def __init__(self, subparsers: argparse._SubParsersAction): |
| 14 | super().__init__() |
| 15 | self.parser = subparsers.add_parser( |
| 16 | "list-providers", |
| 17 | prog="llama stack list-providers", |
| 18 | description="Show available Llama Stack Providers for an API", |
| 19 | formatter_class=argparse.RawTextHelpFormatter, |
| 20 | ) |
| 21 | self._add_arguments() |
| 22 | self.parser.set_defaults(func=self._run_providers_list_cmd) |
| 23 | |
| 24 | def _add_arguments(self): |
| 25 | from llama_stack.distribution.distribution import stack_apis |
| 26 | |
| 27 | api_values = [a.value for a in stack_apis()] |
| 28 | self.parser.add_argument( |
| 29 | "api", |
| 30 | type=str, |
| 31 | choices=api_values, |
| 32 | help="API to list providers for (one of: {})".format(api_values), |
| 33 | ) |
| 34 | |
| 35 | def _run_providers_list_cmd(self, args: argparse.Namespace) -> None: |
| 36 | from llama_stack.cli.table import print_table |
| 37 | from llama_stack.distribution.distribution import Api, api_providers |
| 38 | |
| 39 | all_providers = api_providers() |
| 40 | providers_for_api = all_providers[Api(args.api)] |
| 41 | |
| 42 | # eventually, this should query a registry at llama.meta.com/llamastack/distributions |
| 43 | headers = [ |
| 44 | "Provider Type", |
| 45 | "PIP Package Dependencies", |
| 46 | ] |
| 47 | |
| 48 | rows = [] |
| 49 | for spec in providers_for_api.values(): |
| 50 | if spec.provider_id == "sample": |
| 51 | continue |
| 52 | rows.append( |
| 53 | [ |
| 54 | spec.provider_id, |
| 55 | ",".join(spec.pip_packages), |
| 56 | ] |
| 57 | ) |
| 58 | print_table( |
| 59 | rows, |
| 60 | headers, |
| 61 | separate_rows=True, |
| 62 | ) |