kikocis/llama-stack public
Changesets · Branches · Tags · Compare
| Changeset | 7b7b9b1ba2432a488b2742db71a646dc6780d208978b06adfe9f58d2f12deef1 |
|---|---|
| Author | Xi Yan <xiyan@meta.com> · 2024-09-18 11:41 -07:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-18 11:41 -07:00 |
| Parents | 8cad8e6fa124 |
4 files changed
modified docs/getting_started.md +35 −17
| @@ -8,43 +8,61 @@ | ||
| 8 | 8 | - Quick 3 line command to build and start a LlamaStack server using our Meta Reference implementation for all API endpoints with `conda` as build type. |
| 9 | 9 | |
| 10 | 10 | **`llama stack build`** |
| 11 | +- You'll be prompted to enter build information interactively. | |
| 11 | 12 | ``` |
| 12 | -llama stack build ./llama_stack/distribution/example_configs/conda/local-conda-example-build.yaml --name my-local-llama-stack | |
| 13 | -... | |
| 14 | -... | |
| 15 | -Build spec configuration saved at ~/.llama/distributions/conda/my-local-llama-stack-build.yaml | |
| 13 | +llama stack build | |
| 14 | + | |
| 15 | +> Enter an unique name for identifying your Llama Stack build distribution (e.g. my-local-stack): my-local-llama-stack | |
| 16 | +> Enter the image type you want your distribution to be built with (docker or conda): conda | |
| 17 | + | |
| 18 | + Llama Stack is composed of several APIs working together. Let's configure the providers (implementations) you want to use for these APIs. | |
| 19 | +> Enter the API provider for the inference API: (default=meta-reference): meta-reference | |
| 20 | +> Enter the API provider for the safety API: (default=meta-reference): meta-reference | |
| 21 | +> Enter the API provider for the agents API: (default=meta-reference): meta-reference | |
| 22 | +> Enter the API provider for the memory API: (default=meta-reference): meta-reference | |
| 23 | +> Enter the API provider for the telemetry API: (default=meta-reference): meta-reference | |
| 24 | + | |
| 25 | + > (Optional) Enter a short description for your Llama Stack distribution: | |
| 26 | + | |
| 27 | +Build spec configuration saved at ~/.conda/envs/llamastack-my-local-llama-stack/my-local-llama-stack-build.yaml | |
| 16 | 28 | ``` |
| 17 | 29 | |
| 18 | 30 | **`llama stack configure`** |
| 19 | 31 | ``` |
| 20 | -llama stack configure ~/.llama/distributions/conda/my-local-llama-stack-build.yaml | |
| 32 | +llama stack configure my-local-llama-stack | |
| 33 | + | |
| 34 | +Configuring APIs to serve... | |
| 35 | +Enter comma-separated list of APIs to serve: | |
| 21 | 36 | |
| 22 | -Configuring API: inference (meta-reference) | |
| 37 | +Configuring API `inference`... | |
| 38 | + | |
| 39 | +Configuring provider `meta-reference`... | |
| 23 | 40 | Enter value for model (default: Meta-Llama3.1-8B-Instruct) (required): |
| 24 | -Enter value for quantization (optional): | |
| 41 | +Do you want to configure quantization? (y/n): n | |
| 25 | 42 | Enter value for torch_seed (optional): |
| 26 | 43 | Enter value for max_seq_len (required): 4096 |
| 27 | 44 | Enter value for max_batch_size (default: 1) (required): |
| 45 | +Configuring API `safety`... | |
| 28 | 46 | |
| 29 | -Configuring API: memory (meta-reference-faiss) | |
| 30 | - | |
| 31 | -Configuring API: safety (meta-reference) | |
| 47 | +Configuring provider `meta-reference`... | |
| 32 | 48 | Do you want to configure llama_guard_shield? (y/n): n |
| 33 | 49 | Do you want to configure prompt_guard_shield? (y/n): n |
| 50 | +Configuring API `agents`... | |
| 34 | 51 | |
| 35 | -Configuring API: agentic_system (meta-reference) | |
| 36 | -Enter value for brave_search_api_key (optional): | |
| 37 | -Enter value for bing_search_api_key (optional): | |
| 38 | -Enter value for wolfram_api_key (optional): | |
| 52 | +Configuring provider `meta-reference`... | |
| 53 | +Configuring API `memory`... | |
| 39 | 54 | |
| 40 | -Configuring API: telemetry (console) | |
| 55 | +Configuring provider `meta-reference`... | |
| 56 | +Configuring API `telemetry`... | |
| 41 | 57 | |
| 42 | -YAML configuration has been written to ~/.llama/builds/conda/my-local-llama-stack-run.yaml | |
| 58 | +Configuring provider `meta-reference`... | |
| 59 | +> YAML configuration has been written to /home/xiyan/.llama/builds/conda/my-local-llama-stack-run.yaml. | |
| 60 | +You can now run `llama stack run my-local-llama-stack --port PORT` or `llama stack run /home/xiyan/.llama/builds/conda/my-local-llama-stack-run.yaml --port PORT | |
| 43 | 61 | ``` |
| 44 | 62 | |
| 45 | 63 | **`llama stack run`** |
| 46 | 64 | ``` |
| 47 | -llama stack run ~/.llama/builds/conda/my-local-llama-stack-run.yaml | |
| 65 | +llama stack run my-local-llama-stack | |
| 48 | 66 | |
| 49 | 67 | ... |
| 50 | 68 | > initializing model parallel with size 1 |
modified llama_stack/cli/stack/build.py +71 −6
| @@ -29,7 +29,9 @@ | ||
| 29 | 29 | self.parser.add_argument( |
| 30 | 30 | "config", |
| 31 | 31 | type=str, |
| 32 | - help="Path to a config file to use for the build. You may find example configs in llama_stack/distribution/example_configs", | |
| 32 | + default=None, | |
| 33 | + nargs="*", | |
| 34 | + help="Path to a config file to use for the build. You can find example configs in llama_stack/distribution/example_configs. If this argument is not provided, you will be prompted to enter information interactively", | |
| 33 | 35 | ) |
| 34 | 36 | |
| 35 | 37 | self.parser.add_argument( |
| @@ -44,9 +46,10 @@ | ||
| 44 | 46 | import json |
| 45 | 47 | import os |
| 46 | 48 | |
| 49 | + from llama_stack.distribution.build import ApiInput, build_image, ImageType | |
| 50 | + | |
| 47 | 51 | from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR |
| 48 | 52 | from llama_stack.distribution.utils.serialize import EnumEncoder |
| 49 | - from llama_stack.distribution.build import ApiInput, build_image, ImageType | |
| 50 | 53 | from termcolor import cprint |
| 51 | 54 | |
| 52 | 55 | # save build.yaml spec for building same distribution again |
| @@ -57,7 +60,10 @@ | ||
| 57 | 60 | llama_stack_path / "configs/distributions" / build_config.image_type |
| 58 | 61 | ) |
| 59 | 62 | else: |
| 60 | - build_dir = DISTRIBS_BASE_DIR / build_config.image_type | |
| 63 | + build_dir = ( | |
| 64 | + Path(os.getenv("CONDA_PREFIX")).parent | |
| 65 | + / f"llamastack-{build_config.name}" | |
| 66 | + ) | |
| 61 | 67 | |
| 62 | 68 | os.makedirs(build_dir, exist_ok=True) |
| 63 | 69 | build_file_path = build_dir / f"{build_config.name}-build.yaml" |
| @@ -70,17 +76,76 @@ | ||
| 70 | 76 | |
| 71 | 77 | cprint( |
| 72 | 78 | f"Build spec configuration saved at {str(build_file_path)}", |
| 79 | + color="blue", | |
| 80 | + ) | |
| 81 | + cprint( | |
| 82 | + f"You may now run `llama stack configure {build_config.name}` or `llama stack configure {str(build_file_path)}`", | |
| 73 | 83 | color="green", |
| 74 | 84 | ) |
| 75 | 85 | |
| 76 | 86 | def _run_stack_build_command(self, args: argparse.Namespace) -> None: |
| 77 | - from llama_stack.distribution.utils.prompt_for_config import prompt_for_config | |
| 87 | + from llama_stack.distribution.distribution import Api, api_providers | |
| 78 | 88 | from llama_stack.distribution.utils.dynamic import instantiate_class_type |
| 89 | + from prompt_toolkit import prompt | |
| 90 | + from prompt_toolkit.validation import Validator | |
| 91 | + from termcolor import cprint | |
| 79 | 92 | |
| 80 | 93 | if not args.config: |
| 81 | - self.parser.error( | |
| 82 | - "No config file specified. Please use `llama stack build /path/to/*-build.yaml`. Example config files can be found in llama_stack/distribution/example_configs" | |
| 94 | + name = prompt( | |
| 95 | + "> Enter a unique name for identifying your Llama Stack build (e.g. my-local-stack): " | |
| 96 | + ) | |
| 97 | + image_type = prompt( | |
| 98 | + "> Enter the image type you want your Llama Stack to be built as (docker or conda): ", | |
| 99 | + validator=Validator.from_callable( | |
| 100 | + lambda x: x in ["docker", "conda"], | |
| 101 | + error_message="Invalid image type, please enter conda or docker", | |
| 102 | + ), | |
| 103 | + default="conda", | |
| 104 | + ) | |
| 105 | + | |
| 106 | + cprint( | |
| 107 | + f"\n Llama Stack is composed of several APIs working together. Let's configure the providers (implementations) you want to use for these APIs.", | |
| 108 | + color="green", | |
| 109 | + ) | |
| 110 | + | |
| 111 | + providers = dict() | |
| 112 | + for api in Api: | |
| 113 | + all_providers = api_providers() | |
| 114 | + providers_for_api = all_providers[api] | |
| 115 | + | |
| 116 | + api_provider = prompt( | |
| 117 | + "> Enter the API provider for the {} API: (default=meta-reference): ".format( | |
| 118 | + api.value | |
| 119 | + ), | |
| 120 | + validator=Validator.from_callable( | |
| 121 | + lambda x: x in providers_for_api, | |
| 122 | + error_message="Invalid provider, please enter one of the following: {}".format( | |
| 123 | + providers_for_api.keys() | |
| 124 | + ), | |
| 125 | + ), | |
| 126 | + default=( | |
| 127 | + "meta-reference" | |
| 128 | + if "meta-reference" in providers_for_api | |
| 129 | + else list(providers_for_api.keys())[0] | |
| 130 | + ), | |
| 131 | + ) | |
| 132 | + | |
| 133 | + providers[api.value] = api_provider | |
| 134 | + | |
| 135 | + description = prompt( | |
| 136 | + "\n > (Optional) Enter a short description for your Llama Stack: ", | |
| 137 | + default="", | |
| 138 | + ) | |
| 139 | + | |
| 140 | + distribution_spec = DistributionSpec( | |
| 141 | + providers=providers, | |
| 142 | + description=description, | |
| 143 | + ) | |
| 144 | + | |
| 145 | + build_config = BuildConfig( | |
| 146 | + name=name, image_type=image_type, distribution_spec=distribution_spec | |
| 83 | 147 | ) |
| 148 | + self._run_stack_build_command_from_build_config(build_config) | |
| 84 | 149 | return |
| 85 | 150 | |
| 86 | 151 | with open(args.config, "r") as f: |
modified llama_stack/cli/stack/configure.py +13 −4
| @@ -9,7 +9,6 @@ | ||
| 9 | 9 | from pathlib import Path |
| 10 | 10 | |
| 11 | 11 | import yaml |
| 12 | -from termcolor import cprint | |
| 13 | 12 | |
| 14 | 13 | from llama_stack.cli.subcommand import Subcommand |
| 15 | 14 | from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR |
| @@ -50,9 +49,12 @@ | ||
| 50 | 49 | import pkg_resources |
| 51 | 50 | |
| 52 | 51 | from llama_stack.distribution.build import ImageType |
| 52 | + from termcolor import cprint | |
| 53 | 53 | |
| 54 | 54 | docker_image = None |
| 55 | - build_config_file = Path(args.config) | |
| 55 | + conda_dir = Path(os.getenv("CONDA_PREFIX")).parent / f"llamastack-{args.config}" | |
| 56 | + build_config_file = Path(conda_dir) / f"{args.config}-build.yaml" | |
| 57 | + | |
| 56 | 58 | if not build_config_file.exists(): |
| 57 | 59 | cprint( |
| 58 | 60 | f"Could not find {build_config_file}. Trying docker image name instead...", |
| @@ -79,8 +81,9 @@ | ||
| 79 | 81 | ) |
| 80 | 82 | |
| 81 | 83 | build_name = docker_image.removeprefix("llamastack-") |
| 84 | + saved_file = str(builds_dir / f"{build_name}-run.yaml") | |
| 82 | 85 | cprint( |
| 83 | - f"YAML configuration has been written to {builds_dir / f'{build_name}-run.yaml'}", | |
| 86 | + f"YAML configuration has been written to {saved_file}. You can now run `llama stack run {saved_file}`", | |
| 84 | 87 | color="green", |
| 85 | 88 | ) |
| 86 | 89 | return |
| @@ -97,6 +100,7 @@ | ||
| 97 | 100 | ): |
| 98 | 101 | from llama_stack.distribution.configure import configure_api_providers |
| 99 | 102 | from llama_stack.distribution.utils.serialize import EnumEncoder |
| 103 | + from termcolor import cprint | |
| 100 | 104 | |
| 101 | 105 | builds_dir = BUILDS_BASE_DIR / build_config.image_type |
| 102 | 106 | if output_dir: |
| @@ -132,6 +136,11 @@ | ||
| 132 | 136 | f.write(yaml.dump(to_write, sort_keys=False)) |
| 133 | 137 | |
| 134 | 138 | cprint( |
| 135 | - f"> YAML configuration has been written to {run_config_file}", | |
| 139 | + f"> YAML configuration has been written to {run_config_file}.", | |
| 136 | 140 | color="blue", |
| 137 | 141 | ) |
| 142 | + | |
| 143 | + cprint( | |
| 144 | + f"You can now run `llama stack run {image_name} --port PORT` or `llama stack run {run_config_file} --port PORT`", | |
| 145 | + color="green", | |
| 146 | + ) |
modified llama_stack/cli/stack/run.py +15 −3
| @@ -47,6 +47,8 @@ | ||
| 47 | 47 | |
| 48 | 48 | def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: |
| 49 | 49 | import pkg_resources |
| 50 | + from llama_stack.distribution.build import ImageType | |
| 51 | + from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR | |
| 50 | 52 | |
| 51 | 53 | from llama_stack.distribution.utils.exec import run_with_pty |
| 52 | 54 | |
| @@ -54,12 +56,22 @@ | ||
| 54 | 56 | self.parser.error("Must specify a config file to run") |
| 55 | 57 | return |
| 56 | 58 | |
| 57 | - path = args.config | |
| 58 | - config_file = Path(path) | |
| 59 | + config_file = Path(args.config) | |
| 60 | + if not config_file.exists() and not args.config.endswith(".yaml"): | |
| 61 | + # check if it's a build config saved to conda dir | |
| 62 | + config_file = Path( | |
| 63 | + BUILDS_BASE_DIR / ImageType.conda.value / f"{args.config}-run.yaml" | |
| 64 | + ) | |
| 65 | + | |
| 66 | + if not config_file.exists() and not args.config.endswith(".yaml"): | |
| 67 | + # check if it's a build config saved to docker dir | |
| 68 | + config_file = Path( | |
| 69 | + BUILDS_BASE_DIR / ImageType.docker.value / f"{args.config}-run.yaml" | |
| 70 | + ) | |
| 59 | 71 | |
| 60 | 72 | if not config_file.exists(): |
| 61 | 73 | self.parser.error( |
| 62 | - f"File {str(config_file)} does not exist. Did you run `llama stack build`?" | |
| 74 | + f"File {str(config_file)} does not exist. Please run `llama stack build` and `llama stack configure <name>` to generate a run.yaml file" | |
| 63 | 75 | ) |
| 64 | 76 | return |
| 65 | 77 |