forked from phoenix-oss/llama-stack-mirror
Kill --name from llama stack build (#340)
This commit is contained in:
parent
26d1668f7d
commit
4aa1bf6a60
9 changed files with 71 additions and 130 deletions
|
@ -62,17 +62,12 @@ class StackBuild(Subcommand):
|
|||
help="Show the available templates for building a Llama Stack distribution",
|
||||
)
|
||||
|
||||
self.parser.add_argument(
|
||||
"--name",
|
||||
type=str,
|
||||
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. ",
|
||||
)
|
||||
|
||||
self.parser.add_argument(
|
||||
"--image-type",
|
||||
type=str,
|
||||
help="Image Type to use for the build. This can be either conda or docker. If not specified, will use the image type from the template config.",
|
||||
choices=["conda", "docker"],
|
||||
default="conda",
|
||||
)
|
||||
|
||||
def _run_stack_build_command(self, args: argparse.Namespace) -> None:
|
||||
|
@ -91,15 +86,9 @@ class StackBuild(Subcommand):
|
|||
return
|
||||
|
||||
if args.template:
|
||||
if not args.name:
|
||||
self.parser.error(
|
||||
"You must specify a name for the build using --name when using a template"
|
||||
)
|
||||
return
|
||||
available_templates = available_templates_specs()
|
||||
for build_config in available_templates:
|
||||
if build_config.name == args.template:
|
||||
build_config.name = args.name
|
||||
if args.image_type:
|
||||
build_config.image_type = args.image_type
|
||||
else:
|
||||
|
@ -114,30 +103,14 @@ 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 = self._get_build_config_from_name(args)
|
||||
if maybe_build_config:
|
||||
cprint(
|
||||
f"Building from existing build config for {args.name} in {str(maybe_build_config)}...",
|
||||
"green",
|
||||
)
|
||||
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(
|
||||
"> Enter a name for your Llama Stack (e.g. my-local-stack): ",
|
||||
validator=Validator.from_callable(
|
||||
lambda x: len(x) > 0,
|
||||
error_message="Name cannot be empty, please enter a name",
|
||||
),
|
||||
)
|
||||
else:
|
||||
name = args.name
|
||||
name = prompt(
|
||||
"> Enter a name for your Llama Stack (e.g. my-local-stack): ",
|
||||
validator=Validator.from_callable(
|
||||
lambda x: len(x) > 0,
|
||||
error_message="Name cannot be empty, please enter a name",
|
||||
),
|
||||
)
|
||||
|
||||
image_type = prompt(
|
||||
"> Enter the image type you want your Llama Stack to be built as (docker or conda): ",
|
||||
|
@ -203,25 +176,6 @@ class StackBuild(Subcommand):
|
|||
return
|
||||
self._run_stack_build_command_from_build_config(build_config)
|
||||
|
||||
def _get_build_config_from_name(self, args: argparse.Namespace) -> Optional[Path]:
|
||||
if os.getenv("CONDA_PREFIX", ""):
|
||||
conda_dir = (
|
||||
Path(os.getenv("CONDA_PREFIX")).parent / f"llamastack-{args.name}"
|
||||
)
|
||||
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.name}"
|
||||
)
|
||||
build_config_file = Path(conda_dir) / f"{args.name}-build.yaml"
|
||||
if build_config_file.exists():
|
||||
return build_config_file
|
||||
|
||||
return None
|
||||
|
||||
def _run_stack_build_command_from_build_config(
|
||||
self, build_config: BuildConfig
|
||||
) -> None:
|
||||
|
|
|
@ -55,19 +55,12 @@ class StackConfigure(Subcommand):
|
|||
docker_image = None
|
||||
|
||||
build_config_file = Path(args.config)
|
||||
|
||||
if build_config_file.exists():
|
||||
with open(build_config_file, "r") as f:
|
||||
build_config = BuildConfig(**yaml.safe_load(f))
|
||||
self._configure_llama_distribution(build_config, args.output_dir)
|
||||
return
|
||||
|
||||
# if we get here, we need to try to find the conda build config file
|
||||
cprint(
|
||||
f"Could not find {build_config_file}. Trying conda build name instead...",
|
||||
color="green",
|
||||
)
|
||||
|
||||
conda_dir = (
|
||||
Path(os.path.expanduser("~/.conda/envs")) / f"llamastack-{args.config}"
|
||||
)
|
||||
|
@ -80,19 +73,14 @@ class StackConfigure(Subcommand):
|
|||
break
|
||||
|
||||
build_config_file = Path(conda_dir) / f"{args.config}-build.yaml"
|
||||
|
||||
if build_config_file.exists():
|
||||
with open(build_config_file, "r") as f:
|
||||
build_config = BuildConfig(**yaml.safe_load(f))
|
||||
|
||||
cprint(f"Using {build_config_file}...", "green")
|
||||
self._configure_llama_distribution(build_config, args.output_dir)
|
||||
return
|
||||
|
||||
# if we get here, we need to try to find the docker image
|
||||
cprint(
|
||||
f"Could not find {build_config_file}. Trying docker image name instead...",
|
||||
color="green",
|
||||
)
|
||||
docker_image = args.config
|
||||
builds_dir = BUILDS_BASE_DIR / ImageType.docker.value
|
||||
if args.output_dir:
|
||||
|
@ -105,15 +93,10 @@ class StackConfigure(Subcommand):
|
|||
script_args = [script, docker_image, str(builds_dir)]
|
||||
|
||||
return_code = run_with_pty(script_args)
|
||||
|
||||
# we have regenerated the build config file with script, now check if it exists
|
||||
if return_code != 0:
|
||||
self.parser.error(
|
||||
f"Failed to configure container {docker_image} with return code {return_code}. Please run `llama stack build` first. "
|
||||
)
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
def _configure_llama_distribution(
|
||||
self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue