From 1097912054a2a0918b94ce92ceb828508bfe0001 Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Fri, 7 Mar 2025 14:05:58 -0500 Subject: [PATCH] refactor: display defaults in help text (#1480) # What does this PR do? using `formatter_class=argparse.ArgumentDefaultsHelpFormatter` displays (default: DEFAULT_VALUE) for each flag. add this formatter class to build and run to show users some default values like `conda`, `8321`, etc ## Test Plan ran locally with following output: before: ``` llama stack run --help usage: llama stack run [-h] [--port PORT] [--image-name IMAGE_NAME] [--disable-ipv6] [--env KEY=VALUE] [--tls-keyfile TLS_KEYFILE] [--tls-certfile TLS_CERTFILE] [--image-type {conda,container,venv}] config Start the server for a Llama Stack Distribution. You should have already built (or downloaded) and configured the distribution. positional arguments: config Path to config file to use for the run options: -h, --help show this help message and exit --port PORT Port to run the server on. It can also be passed via the env var LLAMA_STACK_PORT. Defaults to 8321 --image-name IMAGE_NAME Name of the image to run. Defaults to the current conda environment --disable-ipv6 Disable IPv6 support --env KEY=VALUE Environment variables to pass to the server in KEY=VALUE format. Can be specified multiple times. --tls-keyfile TLS_KEYFILE Path to TLS key file for HTTPS --tls-certfile TLS_CERTFILE Path to TLS certificate file for HTTPS --image-type {conda,container,venv} Image Type used during the build. This can be either conda or container or venv. ``` after: ``` llama stack run --help usage: llama stack run [-h] [--port PORT] [--image-name IMAGE_NAME] [--disable-ipv6] [--env KEY=VALUE] [--tls-keyfile TLS_KEYFILE] [--tls-certfile TLS_CERTFILE] [--image-type {conda,container,venv}] config Start the server for a Llama Stack Distribution. You should have already built (or downloaded) and configured the distribution. positional arguments: config Path to config file to use for the run options: -h, --help show this help message and exit --port PORT Port to run the server on. It can also be passed via the env var LLAMA_STACK_PORT. (default: 8321) --image-name IMAGE_NAME Name of the image to run. Defaults to the current conda environment (default: None) --disable-ipv6 Disable IPv6 support (default: False) --env KEY=VALUE Environment variables to pass to the server in KEY=VALUE format. Can be specified multiple times. (default: []) --tls-keyfile TLS_KEYFILE Path to TLS key file for HTTPS (default: None) --tls-certfile TLS_CERTFILE Path to TLS certificate file for HTTPS (default: None) --image-type {conda,container,venv} Image Type used during the build. This can be either conda or container or venv. (default: conda) ``` [//]: # (## Documentation) Signed-off-by: Charlie Doern --- docs/source/distributions/building_distro.md | 42 ++++++++++---------- llama_stack/cli/stack/build.py | 2 +- llama_stack/cli/stack/run.py | 5 ++- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/source/distributions/building_distro.md b/docs/source/distributions/building_distro.md index 41c6a70bf..942596b59 100644 --- a/docs/source/distributions/building_distro.md +++ b/docs/source/distributions/building_distro.md @@ -51,25 +51,25 @@ The main points to consider are: ``` llama stack build -h - -usage: llama stack build [-h] [--config CONFIG] [--template TEMPLATE] [--list-templates] - [--image-type {conda,container,venv}] [--image-name IMAGE_NAME] [--print-deps-only] +usage: llama stack build [-h] [--config CONFIG] [--template TEMPLATE] [--list-templates] [--image-type {conda,container,venv}] [--image-name IMAGE_NAME] [--print-deps-only] [--run] Build a Llama stack container options: -h, --help show this help message and exit - --config CONFIG Path to a config file to use for the build. You can find example configs in llama_stack/distributions/**/build.yaml. - If this argument is not provided, you will be prompted to enter information interactively - --template TEMPLATE Name of the example template config to use for build. You may use `llama stack build --list-templates` to check out the available templates - --list-templates Show the available templates for building a Llama Stack distribution + --config CONFIG Path to a config file to use for the build. You can find example configs in llama_stack/distributions/**/build.yaml. If this argument is not provided, you will + be prompted to enter information interactively (default: None) + --template TEMPLATE Name of the example template config to use for build. You may use `llama stack build --list-templates` to check out the available templates (default: None) + --list-templates Show the available templates for building a Llama Stack distribution (default: False) --image-type {conda,container,venv} - Image Type to use for the build. This can be either conda or container or venv. If not specified, will use the image type from the template config. + Image Type to use for the build. This can be either conda or container or venv. If not specified, will use the image type from the template config. (default: + conda) --image-name IMAGE_NAME - [for image-type=conda] Name of the conda environment to use for the build. If - not specified, currently active Conda environment will be used. If no Conda - environment is active, you must specify a name. - --print-deps-only Print the dependencies for the stack only, without building the stack + [for image-type=conda|venv] Name of the conda or virtual environment to use for the build. If not specified, currently active Conda environment will be used if + found. (default: None) + --print-deps-only Print the dependencies for the stack only, without building the stack (default: False) + --run Run the stack after building using the same image type, name, and other applicable arguments (default: False) + ``` After this step is complete, a file named `-build.yaml` and template file `-run.yaml` will be generated and saved at the output file path specified at the end of the command. @@ -212,8 +212,8 @@ Now, let's start the Llama Stack Distribution Server. You will need the YAML con ``` llama stack run -h -usage: llama stack run [-h] [--port PORT] [--image-name IMAGE_NAME] [--disable-ipv6] [--env KEY=VALUE] [--tls-keyfile TLS_KEYFILE] - [--tls-certfile TLS_CERTFILE] [--image-type {conda,container,venv}] +usage: llama stack run [-h] [--port PORT] [--image-name IMAGE_NAME] [--disable-ipv6] [--env KEY=VALUE] [--tls-keyfile TLS_KEYFILE] [--tls-certfile TLS_CERTFILE] + [--image-type {conda,container,venv}] config Start the server for a Llama Stack Distribution. You should have already built (or downloaded) and configured the distribution. @@ -223,17 +223,17 @@ positional arguments: options: -h, --help show this help message and exit - --port PORT Port to run the server on. It can also be passed via the env var LLAMA_STACK_PORT. Defaults to 8321 + --port PORT Port to run the server on. It can also be passed via the env var LLAMA_STACK_PORT. (default: 8321) --image-name IMAGE_NAME - Name of the image to run. Defaults to the current conda environment - --disable-ipv6 Disable IPv6 support - --env KEY=VALUE Environment variables to pass to the server in KEY=VALUE format. Can be specified multiple times. + Name of the image to run. Defaults to the current conda environment (default: None) + --disable-ipv6 Disable IPv6 support (default: False) + --env KEY=VALUE Environment variables to pass to the server in KEY=VALUE format. Can be specified multiple times. (default: []) --tls-keyfile TLS_KEYFILE - Path to TLS key file for HTTPS + Path to TLS key file for HTTPS (default: None) --tls-certfile TLS_CERTFILE - Path to TLS certificate file for HTTPS + Path to TLS certificate file for HTTPS (default: None) --image-type {conda,container,venv} - Image Type used during the build. This can be either conda or container or venv. + Image Type used during the build. This can be either conda or container or venv. (default: conda) ``` diff --git a/llama_stack/cli/stack/build.py b/llama_stack/cli/stack/build.py index 61847a55d..70d74c620 100644 --- a/llama_stack/cli/stack/build.py +++ b/llama_stack/cli/stack/build.py @@ -16,7 +16,7 @@ class StackBuild(Subcommand): "build", prog="llama stack build", description="Build a Llama stack container", - formatter_class=argparse.RawTextHelpFormatter, + formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) self._add_arguments() self.parser.set_defaults(func=self._run_stack_build_command) diff --git a/llama_stack/cli/stack/run.py b/llama_stack/cli/stack/run.py index d4e679e4b..ba2273003 100644 --- a/llama_stack/cli/stack/run.py +++ b/llama_stack/cli/stack/run.py @@ -23,7 +23,7 @@ class StackRun(Subcommand): "run", prog="llama stack run", description="""Start the server for a Llama Stack Distribution. You should have already built (or downloaded) and configured the distribution.""", - formatter_class=argparse.RawTextHelpFormatter, + formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) self._add_arguments() self.parser.set_defaults(func=self._run_stack_run_cmd) @@ -37,12 +37,13 @@ class StackRun(Subcommand): self.parser.add_argument( "--port", type=int, - help="Port to run the server on. It can also be passed via the env var LLAMA_STACK_PORT. Defaults to 8321", + help="Port to run the server on. It can also be passed via the env var LLAMA_STACK_PORT.", default=int(os.getenv("LLAMA_STACK_PORT", 8321)), ) self.parser.add_argument( "--image-name", type=str, + default=os.environ.get("CONDA_DEFAULT_ENV"), help="Name of the image to run. Defaults to the current conda environment", ) self.parser.add_argument(