mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
- Implement llama version command with table and JSON output formats - Add build-time git information capture via scripts/generate_build_info.py - Include comprehensive unit test suite (test_version.py, test_version_simple.py, test_version_integration.py) - Add build system integration with custom setup.py command - Update .gitignore to exclude generated build info file Features: - Display Llama Stack and client versions - Show Python version and build information (git commit, date, branch, tag) - Optional component/provider listing organized by API - Support for both table and JSON output formats - Build-time capture of git metadata for version tracking Testing: - 8 unit tests covering all functionality - Integration tests for CLI execution - Simple dependency-free validation tests - Documentation for test suite and build process Signed-off-by: Akram Ben Aissi <akram.benaissi@gmail.com>
77 lines
2.5 KiB
Python
77 lines
2.5 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)
|
|
|
|
@property
|
|
def providable_apis(self):
|
|
from llama_stack.distribution.distribution import providable_apis
|
|
|
|
return [api.value for api in providable_apis()]
|
|
|
|
def _add_arguments(self):
|
|
choices = self.providable_apis
|
|
self.parser.add_argument(
|
|
"api",
|
|
type=str,
|
|
choices=choices if choices else None,
|
|
nargs="?",
|
|
help="API to list providers for. List all if not specified.",
|
|
)
|
|
|
|
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()
|
|
if args.api:
|
|
providers = [(args.api, all_providers[Api(args.api)])]
|
|
else:
|
|
providers = [(k.value, prov) for k, prov in all_providers.items()]
|
|
|
|
providers = [(api, p) for api, p in providers if api in self.providable_apis]
|
|
|
|
# eventually, this should query a registry at llama.meta.com/llamastack/distributions
|
|
headers = [
|
|
"API Type",
|
|
"Provider Type",
|
|
"PIP Package Dependencies",
|
|
]
|
|
|
|
rows = []
|
|
|
|
specs = [spec for api, p in providers for spec in p.values()]
|
|
for spec in specs:
|
|
if spec.is_sample:
|
|
continue
|
|
rows.append(
|
|
[
|
|
spec.api.value,
|
|
spec.provider_type,
|
|
",".join(spec.pip_packages) if hasattr(spec, "pip_packages") else "",
|
|
]
|
|
)
|
|
print_table(
|
|
rows,
|
|
headers,
|
|
separate_rows=True,
|
|
sort_by=(0, 1),
|
|
)
|