From 4897bf2f8514f5b243f89afed165a327469ea988 Mon Sep 17 00:00:00 2001 From: Xi Yan Date: Mon, 30 Sep 2024 16:18:12 -0700 Subject: [PATCH] allow --name to re-build from config --- llama_stack/cli/stack/build.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/llama_stack/cli/stack/build.py b/llama_stack/cli/stack/build.py index 31cf991be..4eb73175e 100644 --- a/llama_stack/cli/stack/build.py +++ b/llama_stack/cli/stack/build.py @@ -29,6 +29,26 @@ def available_templates_specs() -> List[BuildConfig]: return template_specs +def get_build_config_from_name(name: str) -> Optional[Path]: + if os.getenv("CONDA_PREFIX", ""): + conda_dir = ( + Path(os.getenv("CONDA_PREFIX")).parent / f"llamastack-{args.config}" + ) + else: + cprint( + "Cannot find CONDA_PREFIX. Trying default conda path ~/.conda/envs...", + color="green", + ) + conda_dir = ( + Path(os.path.expanduser("~/.conda/envs")) / f"llamastack-{args.config}" + ) + + build_config_file = Path(conda_dir) / f"{args.config}-build.yaml" + if build_config_file.exists(): + return build_config_file + + return None + class StackBuild(Subcommand): def __init__(self, subparsers: argparse._SubParsersAction): @@ -189,6 +209,16 @@ class StackBuild(Subcommand): return + # try to see if we can find a pre-existing build config file through name + if args.name: + maybe_build_config = get_build_config_from_name(args.name) + if maybe_build_config: + print(f"Building from existing build config for {args.name} in {str(maybe_build_config)}") + with open(maybe_build_config, "r") as f: + build_config = BuildConfig(**yaml.safe_load(f)) + self._run_stack_build_command_from_build_config(build_config) + return + if not args.config and not args.template: if not args.name: name = prompt(