| 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 | import json |
| 9 | |
| 10 | from llama_toolchain.cli.subcommand import Subcommand |
| 11 | |
| 12 | |
| 13 | class StackListDistributions(Subcommand): |
| 14 | def __init__(self, subparsers: argparse._SubParsersAction): |
| 15 | super().__init__() |
| 16 | self.parser = subparsers.add_parser( |
| 17 | "list-distributions", |
| 18 | prog="llama stack list-distributions", |
| 19 | description="Show available Llama Stack Distributions", |
| 20 | formatter_class=argparse.RawTextHelpFormatter, |
| 21 | ) |
| 22 | self._add_arguments() |
| 23 | self.parser.set_defaults(func=self._run_distribution_list_cmd) |
| 24 | |
| 25 | def _add_arguments(self): |
| 26 | pass |
| 27 | |
| 28 | def _run_distribution_list_cmd(self, args: argparse.Namespace) -> None: |
| 29 | from llama_toolchain.cli.table import print_table |
| 30 | from llama_toolchain.core.distribution_registry import ( |
| 31 | available_distribution_specs, |
| 32 | ) |
| 33 | |
| 34 | # eventually, this should query a registry at llama.meta.com/llamastack/distributions |
| 35 | headers = [ |
| 36 | "Distribution Type", |
| 37 | "Providers", |
| 38 | "Description", |
| 39 | ] |
| 40 | |
| 41 | rows = [] |
| 42 | for spec in available_distribution_specs(): |
| 43 | providers = {k.value: v for k, v in spec.providers.items()} |
| 44 | rows.append( |
| 45 | [ |
| 46 | spec.distribution_type, |
| 47 | json.dumps(providers, indent=2), |
| 48 | spec.description, |
| 49 | ] |
| 50 | ) |
| 51 | print_table( |
| 52 | rows, |
| 53 | headers, |
| 54 | separate_rows=True, |
| 55 | ) |