kikocis/llama-stack public
Changesets · Branches · Tags · Compare
| Changeset | 111d87ec9830b5a992fec69696cd1b898dcf150b28b620950694791160ec2843 |
|---|---|
| Author | Xi Yan <xiyan@meta.com> · 2024-09-18 14:25 -07:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-18 14:25 -07:00 |
| Parents | 7b7b9b1ba243 |
14 files changed
modified llama_stack/cli/stack/build.py +107 −11
| @@ -8,9 +8,26 @@ | ||
| 8 | 8 | |
| 9 | 9 | from llama_stack.cli.subcommand import Subcommand |
| 10 | 10 | from llama_stack.distribution.datatypes import * # noqa: F403 |
| 11 | +import os | |
| 12 | +from functools import lru_cache | |
| 11 | 13 | from pathlib import Path |
| 12 | 14 | |
| 13 | -import yaml | |
| 15 | +TEMPLATES_PATH = ( | |
| 16 | + Path(os.path.relpath(__file__)).parent.parent.parent / "distribution" / "templates" | |
| 17 | +) | |
| 18 | + | |
| 19 | + | |
| 20 | +@lru_cache() | |
| 21 | +def available_templates_specs() -> List[BuildConfig]: | |
| 22 | + import yaml | |
| 23 | + | |
| 24 | + template_specs = [] | |
| 25 | + for p in TEMPLATES_PATH.rglob("*.yaml"): | |
| 26 | + with open(p, "r") as f: | |
| 27 | + build_config = BuildConfig(**yaml.safe_load(f)) | |
| 28 | + template_specs.append(build_config) | |
| 29 | + | |
| 30 | + return template_specs | |
| 14 | 31 | |
| 15 | 32 | |
| 16 | 33 | class StackBuild(Subcommand): |
| @@ -27,17 +44,38 @@ | ||
| 27 | 44 | |
| 28 | 45 | def _add_arguments(self): |
| 29 | 46 | self.parser.add_argument( |
| 30 | - "config", | |
| 47 | + "--config", | |
| 31 | 48 | type=str, |
| 32 | 49 | default=None, |
| 33 | - nargs="*", | |
| 34 | 50 | 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", |
| 35 | 51 | ) |
| 36 | 52 | |
| 53 | + self.parser.add_argument( | |
| 54 | + "--template", | |
| 55 | + type=str, | |
| 56 | + default=None, | |
| 57 | + help="Name of the example template config to use for build. You may use `llama stack build --list-templates` to check out the available templates", | |
| 58 | + ) | |
| 59 | + | |
| 60 | + self.parser.add_argument( | |
| 61 | + "--list-templates", | |
| 62 | + type=bool, | |
| 63 | + default=False, | |
| 64 | + action=argparse.BooleanOptionalAction, | |
| 65 | + help="Show the available templates for building a Llama Stack distribution", | |
| 66 | + ) | |
| 67 | + | |
| 37 | 68 | self.parser.add_argument( |
| 38 | 69 | "--name", |
| 39 | 70 | type=str, |
| 40 | - help="Name of the llama stack build to override from template config", | |
| 71 | + help="Name of the Llama Stack build to override from template config. This name will be used as paths to store configuration files, build conda environments/docker images. If not specified, will use the name from the template config. ", | |
| 72 | + ) | |
| 73 | + | |
| 74 | + self.parser.add_argument( | |
| 75 | + "--image-type", | |
| 76 | + type=str, | |
| 77 | + help="Image Type to use for the build. This can be either conda or docker. If not specified, will use conda by default", | |
| 78 | + default="conda", | |
| 41 | 79 | ) |
| 42 | 80 | |
| 43 | 81 | def _run_stack_build_command_from_build_config( |
| @@ -46,6 +84,8 @@ | ||
| 46 | 84 | import json |
| 47 | 85 | import os |
| 48 | 86 | |
| 87 | + import yaml | |
| 88 | + | |
| 49 | 89 | from llama_stack.distribution.build import ApiInput, build_image, ImageType |
| 50 | 90 | |
| 51 | 91 | from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR |
| @@ -78,22 +118,80 @@ | ||
| 78 | 118 | f"Build spec configuration saved at {str(build_file_path)}", |
| 79 | 119 | color="blue", |
| 80 | 120 | ) |
| 121 | + | |
| 122 | + configure_name = ( | |
| 123 | + build_config.name | |
| 124 | + if build_config.image_type == "conda" | |
| 125 | + else (f"llamastack-{build_config.name}") | |
| 126 | + ) | |
| 81 | 127 | cprint( |
| 82 | - f"You may now run `llama stack configure {build_config.name}` or `llama stack configure {str(build_file_path)}`", | |
| 128 | + f"You may now run `llama stack configure {configure_name}` or `llama stack configure {str(build_file_path)}`", | |
| 83 | 129 | color="green", |
| 84 | 130 | ) |
| 85 | 131 | |
| 132 | + def _run_template_list_cmd(self, args: argparse.Namespace) -> None: | |
| 133 | + import json | |
| 134 | + | |
| 135 | + import yaml | |
| 136 | + | |
| 137 | + from llama_stack.cli.table import print_table | |
| 138 | + | |
| 139 | + # eventually, this should query a registry at llama.meta.com/llamastack/distributions | |
| 140 | + headers = [ | |
| 141 | + "Template Name", | |
| 142 | + "Providers", | |
| 143 | + "Description", | |
| 144 | + ] | |
| 145 | + | |
| 146 | + rows = [] | |
| 147 | + for spec in available_templates_specs(): | |
| 148 | + rows.append( | |
| 149 | + [ | |
| 150 | + spec.name, | |
| 151 | + json.dumps(spec.distribution_spec.providers, indent=2), | |
| 152 | + spec.distribution_spec.description, | |
| 153 | + ] | |
| 154 | + ) | |
| 155 | + print_table( | |
| 156 | + rows, | |
| 157 | + headers, | |
| 158 | + separate_rows=True, | |
| 159 | + ) | |
| 160 | + | |
| 86 | 161 | def _run_stack_build_command(self, args: argparse.Namespace) -> None: |
| 162 | + import yaml | |
| 87 | 163 | from llama_stack.distribution.distribution import Api, api_providers |
| 88 | 164 | from llama_stack.distribution.utils.dynamic import instantiate_class_type |
| 89 | 165 | from prompt_toolkit import prompt |
| 90 | 166 | from prompt_toolkit.validation import Validator |
| 91 | 167 | from termcolor import cprint |
| 92 | 168 | |
| 93 | - if not args.config: | |
| 94 | - name = prompt( | |
| 95 | - "> Enter a unique name for identifying your Llama Stack build (e.g. my-local-stack): " | |
| 96 | - ) | |
| 169 | + if args.list_templates: | |
| 170 | + self._run_template_list_cmd(args) | |
| 171 | + return | |
| 172 | + | |
| 173 | + if args.template: | |
| 174 | + if not args.name: | |
| 175 | + self.parser.error( | |
| 176 | + "You must specify a name for the build using --name when using a template" | |
| 177 | + ) | |
| 178 | + return | |
| 179 | + build_path = TEMPLATES_PATH / f"{args.template}-build.yaml" | |
| 180 | + if not build_path.exists(): | |
| 181 | + self.parser.error( | |
| 182 | + f"Could not find template {args.template}. Please run `llama stack build --list-templates` to check out the available templates" | |
| 183 | + ) | |
| 184 | + return | |
| 185 | + with open(build_path, "r") as f: | |
| 186 | + build_config = BuildConfig(**yaml.safe_load(f)) | |
| 187 | + build_config.name = args.name | |
| 188 | + build_config.image_type = args.image_type | |
| 189 | + self._run_stack_build_command_from_build_config(build_config) | |
| 190 | + | |
| 191 | + return | |
| 192 | + | |
| 193 | + if not args.config and not args.template: | |
| 194 | + name = prompt("> Enter a name for your Llama Stack (e.g. my-local-stack): ") | |
| 97 | 195 | image_type = prompt( |
| 98 | 196 | "> Enter the image type you want your Llama Stack to be built as (docker or conda): ", |
| 99 | 197 | validator=Validator.from_callable( |
| @@ -154,6 +252,4 @@ | ||
| 154 | 252 | except Exception as e: |
| 155 | 253 | self.parser.error(f"Could not parse config file {args.config}: {e}") |
| 156 | 254 | return |
| 157 | - if args.name: | |
| 158 | - build_config.name = args.name | |
| 159 | 255 | self._run_stack_build_command_from_build_config(build_config) |
modified llama_stack/cli/stack/configure.py +15 −7
| @@ -5,17 +5,10 @@ | ||
| 5 | 5 | # the root directory of this source tree. |
| 6 | 6 | |
| 7 | 7 | import argparse |
| 8 | -import json | |
| 9 | -from pathlib import Path | |
| 10 | - | |
| 11 | -import yaml | |
| 12 | 8 | |
| 13 | 9 | from llama_stack.cli.subcommand import Subcommand |
| 14 | 10 | from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR |
| 15 | - | |
| 16 | -from llama_stack.distribution.utils.exec import run_with_pty | |
| 17 | 11 | from llama_stack.distribution.datatypes import * # noqa: F403 |
| 18 | -import os | |
| 19 | 12 | |
| 20 | 13 | |
| 21 | 14 | class StackConfigure(Subcommand): |
| @@ -46,9 +39,17 @@ | ||
| 46 | 39 | ) |
| 47 | 40 | |
| 48 | 41 | def _run_stack_configure_cmd(self, args: argparse.Namespace) -> None: |
| 42 | + import json | |
| 43 | + import os | |
| 44 | + from pathlib import Path | |
| 45 | + | |
| 49 | 46 | import pkg_resources |
| 50 | 47 | |
| 48 | + import yaml | |
| 49 | + | |
| 51 | 50 | from llama_stack.distribution.build import ImageType |
| 51 | + | |
| 52 | + from llama_stack.distribution.utils.exec import run_with_pty | |
| 52 | 53 | from termcolor import cprint |
| 53 | 54 | |
| 54 | 55 | docker_image = None |
| @@ -98,7 +99,14 @@ | ||
| 98 | 99 | build_config: BuildConfig, |
| 99 | 100 | output_dir: Optional[str] = None, |
| 100 | 101 | ): |
| 102 | + import json | |
| 103 | + import os | |
| 104 | + from pathlib import Path | |
| 105 | + | |
| 106 | + import yaml | |
| 101 | 107 | from llama_stack.distribution.configure import configure_api_providers |
| 108 | + | |
| 109 | + from llama_stack.distribution.utils.exec import run_with_pty | |
| 102 | 110 | from llama_stack.distribution.utils.serialize import EnumEncoder |
| 103 | 111 | from termcolor import cprint |
| 104 | 112 |
modified llama_stack/cli/stack/run.py +3 −4
| @@ -6,10 +6,6 @@ | ||
| 6 | 6 | |
| 7 | 7 | import argparse |
| 8 | 8 | |
| 9 | -from pathlib import Path | |
| 10 | - | |
| 11 | -import yaml | |
| 12 | - | |
| 13 | 9 | from llama_stack.cli.subcommand import Subcommand |
| 14 | 10 | from llama_stack.distribution.datatypes import * # noqa: F403 |
| 15 | 11 | |
| @@ -46,7 +42,10 @@ | ||
| 46 | 42 | ) |
| 47 | 43 | |
| 48 | 44 | def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: |
| 45 | + from pathlib import Path | |
| 46 | + | |
| 49 | 47 | import pkg_resources |
| 48 | + import yaml | |
| 50 | 49 | from llama_stack.distribution.build import ImageType |
| 51 | 50 | from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR |
| 52 | 51 |
deleted llama_stack/distribution/example_configs/conda/local-conda-example-build.yaml +0 −10
| @@ -1,10 +0,0 @@ | ||
| 1 | -name: local-conda-example | |
| 2 | -distribution_spec: | |
| 3 | - description: Use code from `llama_stack` itself to serve all llama stack APIs | |
| 4 | - providers: | |
| 5 | - inference: meta-reference | |
| 6 | - memory: meta-reference | |
| 7 | - safety: meta-reference | |
| 8 | - agents: meta-reference | |
| 9 | - telemetry: meta-reference | |
| 10 | -image_type: conda |
deleted llama_stack/distribution/example_configs/conda/local-fireworks-conda-example-build.yaml +0 −10
| @@ -1,10 +0,0 @@ | ||
| 1 | -name: local-fireworks-conda-example | |
| 2 | -distribution_spec: | |
| 3 | - description: Use Fireworks.ai for running LLM inference | |
| 4 | - providers: | |
| 5 | - inference: remote::fireworks | |
| 6 | - memory: meta-reference | |
| 7 | - safety: meta-reference | |
| 8 | - agents: meta-reference | |
| 9 | - telemetry: meta-reference | |
| 10 | -image_type: conda |
deleted llama_stack/distribution/example_configs/conda/local-ollama-conda-example-build.yaml +0 −10
| @@ -1,10 +0,0 @@ | ||
| 1 | -name: local-ollama-conda-example | |
| 2 | -distribution_spec: | |
| 3 | - description: Like local, but use ollama for running LLM inference | |
| 4 | - providers: | |
| 5 | - inference: remote::ollama | |
| 6 | - memory: meta-reference | |
| 7 | - safety: meta-reference | |
| 8 | - agents: meta-reference | |
| 9 | - telemetry: meta-reference | |
| 10 | -image_type: conda |
deleted llama_stack/distribution/example_configs/conda/local-tgi-conda-example-build.yaml +0 −10
| @@ -1,10 +0,0 @@ | ||
| 1 | -name: local-tgi-conda-example | |
| 2 | -distribution_spec: | |
| 3 | - description: Use TGI (local or with Hugging Face Inference Endpoints for running LLM inference. When using HF Inference Endpoints, you must provide the name of the endpoint). | |
| 4 | - providers: | |
| 5 | - inference: remote::tgi | |
| 6 | - memory: meta-reference | |
| 7 | - safety: meta-reference | |
| 8 | - agents: meta-reference | |
| 9 | - telemetry: meta-reference | |
| 10 | -image_type: conda |
deleted llama_stack/distribution/example_configs/conda/local-together-conda-example-build.yaml +0 −10
| @@ -1,10 +0,0 @@ | ||
| 1 | -name: local-tgi-conda-example | |
| 2 | -distribution_spec: | |
| 3 | - description: Use Together.ai for running LLM inference | |
| 4 | - providers: | |
| 5 | - inference: remote::together | |
| 6 | - memory: meta-reference | |
| 7 | - safety: meta-reference | |
| 8 | - agents: meta-reference | |
| 9 | - telemetry: meta-reference | |
| 10 | -image_type: conda |
deleted llama_stack/distribution/example_configs/docker/local-docker-example-build.yaml +0 −10
| @@ -1,10 +0,0 @@ | ||
| 1 | -name: local-docker-example | |
| 2 | -distribution_spec: | |
| 3 | - description: Use code from `llama_stack` itself to serve all llama stack APIs | |
| 4 | - providers: | |
| 5 | - inference: meta-reference | |
| 6 | - memory: meta-reference | |
| 7 | - safety: meta-reference | |
| 8 | - agents: meta-reference | |
| 9 | - telemetry: meta-reference | |
| 10 | -image_type: docker |
added llama_stack/distribution/templates/local-build.yaml +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +name: local | |
| 2 | +distribution_spec: | |
| 3 | + description: Use code from `llama_stack` itself to serve all llama stack APIs | |
| 4 | + providers: | |
| 5 | + inference: meta-reference | |
| 6 | + memory: meta-reference | |
| 7 | + safety: meta-reference | |
| 8 | + agents: meta-reference | |
| 9 | + telemetry: meta-reference | |
| 10 | +image_type: conda |
added llama_stack/distribution/templates/local-fireworks-build.yaml +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +name: local-fireworks | |
| 2 | +distribution_spec: | |
| 3 | + description: Use Fireworks.ai for running LLM inference | |
| 4 | + providers: | |
| 5 | + inference: remote::fireworks | |
| 6 | + memory: meta-reference | |
| 7 | + safety: meta-reference | |
| 8 | + agents: meta-reference | |
| 9 | + telemetry: meta-reference | |
| 10 | +image_type: conda |
added llama_stack/distribution/templates/local-ollama-build.yaml +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +name: local-ollama | |
| 2 | +distribution_spec: | |
| 3 | + description: Like local, but use ollama for running LLM inference | |
| 4 | + providers: | |
| 5 | + inference: remote::ollama | |
| 6 | + memory: meta-reference | |
| 7 | + safety: meta-reference | |
| 8 | + agents: meta-reference | |
| 9 | + telemetry: meta-reference | |
| 10 | +image_type: conda |
added llama_stack/distribution/templates/local-tgi-build.yaml +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +name: local-tgi | |
| 2 | +distribution_spec: | |
| 3 | + description: Use TGI (local or with Hugging Face Inference Endpoints for running LLM inference. When using HF Inference Endpoints, you must provide the name of the endpoint). | |
| 4 | + providers: | |
| 5 | + inference: remote::tgi | |
| 6 | + memory: meta-reference | |
| 7 | + safety: meta-reference | |
| 8 | + agents: meta-reference | |
| 9 | + telemetry: meta-reference | |
| 10 | +image_type: conda |
added llama_stack/distribution/templates/local-together-build.yaml +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +name: local-together | |
| 2 | +distribution_spec: | |
| 3 | + description: Use Together.ai for running LLM inference | |
| 4 | + providers: | |
| 5 | + inference: remote::together | |
| 6 | + memory: meta-reference | |
| 7 | + safety: meta-reference | |
| 8 | + agents: meta-reference | |
| 9 | + telemetry: meta-reference | |
| 10 | +image_type: conda |