mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 20:14:13 +00:00
llama distribution -> llama stack + containers (WIP)
This commit is contained in:
parent
45987996c4
commit
fd3b65b718
16 changed files with 204 additions and 80 deletions
|
@ -47,7 +47,7 @@ def get_dependencies(
|
|||
|
||||
return Dependencies(
|
||||
docker_image=provider.docker_image,
|
||||
pip_packages=pip_packages + SERVER_DEPENDENCIES
|
||||
pip_packages=pip_packages + SERVER_DEPENDENCIES,
|
||||
)
|
||||
|
||||
|
||||
|
@ -161,18 +161,29 @@ class ApiBuild(Subcommand):
|
|||
},
|
||||
**provider_deps,
|
||||
}
|
||||
with open(package_file, "w") as f:
|
||||
|
||||
# properly handle the case where package exists but has
|
||||
# inconsistent configuration for the providers. if possible,
|
||||
# we don't want to overwrite the existing configuration.
|
||||
if package_file.exists():
|
||||
cprint(
|
||||
f"Build `{package_name}` exists; will reconfigure",
|
||||
color="yellow",
|
||||
)
|
||||
c = PackageConfig(**yaml.safe_load(package_file.read_text()))
|
||||
else:
|
||||
c = PackageConfig(
|
||||
built_at=datetime.now(),
|
||||
package_name=package_name,
|
||||
docker_image=(
|
||||
package_name if args.type == BuildType.container.value else None
|
||||
),
|
||||
conda_env=(
|
||||
package_name if args.type == BuildType.conda_env.value else None
|
||||
),
|
||||
providers=stub_config,
|
||||
)
|
||||
|
||||
c.docker_image = (
|
||||
package_name if args.type == BuildType.container.value else None
|
||||
)
|
||||
c.conda_env = package_name if args.type == BuildType.conda_env.value else None
|
||||
|
||||
with open(package_file, "w") as f:
|
||||
to_write = json.loads(json.dumps(c.dict(), cls=EnumEncoder))
|
||||
f.write(yaml.dump(to_write, sort_keys=False))
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ def configure_llama_provider(config_file: Path) -> None:
|
|||
|
||||
try:
|
||||
existing_provider_config = config_type(**stub_config)
|
||||
except KeyError:
|
||||
except Exception:
|
||||
existing_provider_config = None
|
||||
|
||||
provider_config = prompt_for_config(
|
||||
|
|
|
@ -75,7 +75,7 @@ class ApiStart(Subcommand):
|
|||
config.conda_env,
|
||||
]
|
||||
|
||||
run_args.extend(["--yaml_config", str(config_file), "--port", str(args.port)])
|
||||
run_args.extend([str(config_file), str(args.port)])
|
||||
if args.disable_ipv6:
|
||||
run_args.append("--disable-ipv6")
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
import argparse
|
||||
|
||||
from .api import ApiParser
|
||||
from .distribution import DistributionParser
|
||||
from .download import Download
|
||||
from .model import ModelParser
|
||||
from .stack import StackParser
|
||||
|
||||
|
||||
class LlamaCLIParser:
|
||||
|
@ -30,8 +30,8 @@ class LlamaCLIParser:
|
|||
# Add sub-commands
|
||||
Download.create(subparsers)
|
||||
ModelParser.create(subparsers)
|
||||
DistributionParser.create(subparsers)
|
||||
ApiParser.create(subparsers)
|
||||
StackParser.create(subparsers)
|
||||
|
||||
# Import sub-commands from agentic_system if they exist
|
||||
try:
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from .distribution import DistributionParser # noqa
|
||||
from .stack import StackParser # noqa
|
|
@ -9,13 +9,13 @@ import json
|
|||
import shlex
|
||||
|
||||
import yaml
|
||||
from termcolor import cprint
|
||||
|
||||
from llama_toolchain.cli.subcommand import Subcommand
|
||||
from llama_toolchain.common.config_dirs import DISTRIBS_BASE_DIR
|
||||
from termcolor import cprint
|
||||
|
||||
|
||||
class DistributionConfigure(Subcommand):
|
||||
class StackConfigure(Subcommand):
|
||||
"""Llama cli for configuring llama toolchain configs"""
|
||||
|
||||
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||
|
@ -38,7 +38,7 @@ class DistributionConfigure(Subcommand):
|
|||
)
|
||||
|
||||
def _run_distribution_configure_cmd(self, args: argparse.Namespace) -> None:
|
||||
from llama_toolchain.distribution.datatypes import DistributionConfig
|
||||
from llama_toolchain.distribution.datatypes import StackConfig
|
||||
from llama_toolchain.distribution.registry import resolve_distribution_spec
|
||||
|
||||
config_file = DISTRIBS_BASE_DIR / args.name / "config.yaml"
|
||||
|
@ -50,7 +50,7 @@ class DistributionConfigure(Subcommand):
|
|||
|
||||
# we need to find the spec from the name
|
||||
with open(config_file, "r") as f:
|
||||
config = DistributionConfig(**yaml.safe_load(f))
|
||||
config = StackConfig(**yaml.safe_load(f))
|
||||
|
||||
dist = resolve_distribution_spec(config.spec)
|
||||
if dist is None:
|
||||
|
@ -59,7 +59,7 @@ class DistributionConfigure(Subcommand):
|
|||
configure_llama_distribution(dist, config)
|
||||
|
||||
|
||||
def configure_llama_distribution(dist: "Distribution", config: "DistributionConfig"):
|
||||
def configure_llama_distribution(dist: "Stack", config: "StackConfig"):
|
||||
from llama_toolchain.common.exec import run_command
|
||||
from llama_toolchain.common.prompt_for_config import prompt_for_config
|
||||
from llama_toolchain.common.serialize import EnumEncoder
|
|
@ -9,7 +9,7 @@ import argparse
|
|||
from llama_toolchain.cli.subcommand import Subcommand
|
||||
|
||||
|
||||
class DistributionCreate(Subcommand):
|
||||
class StackCreate(Subcommand):
|
||||
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||
super().__init__()
|
||||
self.parser = subparsers.add_parser(
|
||||
|
@ -37,7 +37,7 @@ class DistributionCreate(Subcommand):
|
|||
|
||||
dist = resolve_distribution_spec(args.name)
|
||||
if dist is not None:
|
||||
self.parser.error(f"Distribution with name {args.name} already exists")
|
||||
self.parser.error(f"Stack with name {args.name} already exists")
|
||||
return
|
||||
|
||||
raise NotImplementedError()
|
|
@ -10,13 +10,13 @@ import os
|
|||
import pkg_resources
|
||||
import yaml
|
||||
|
||||
from termcolor import cprint
|
||||
|
||||
from llama_toolchain.cli.subcommand import Subcommand
|
||||
from llama_toolchain.common.config_dirs import DISTRIBS_BASE_DIR
|
||||
|
||||
from termcolor import cprint
|
||||
|
||||
|
||||
class DistributionInstall(Subcommand):
|
||||
class StackInstall(Subcommand):
|
||||
"""Llama cli for configuring llama toolchain configs"""
|
||||
|
||||
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||
|
@ -36,7 +36,7 @@ class DistributionInstall(Subcommand):
|
|||
self.parser.add_argument(
|
||||
"--spec",
|
||||
type=str,
|
||||
help="Distribution spec to install (try local-ollama)",
|
||||
help="Stack spec to install (try local-ollama)",
|
||||
required=True,
|
||||
choices=[d.spec_id for d in available_distribution_specs()],
|
||||
)
|
||||
|
@ -54,7 +54,7 @@ class DistributionInstall(Subcommand):
|
|||
|
||||
def _run_distribution_install_cmd(self, args: argparse.Namespace) -> None:
|
||||
from llama_toolchain.common.exec import run_with_pty
|
||||
from llama_toolchain.distribution.datatypes import DistributionConfig
|
||||
from llama_toolchain.distribution.datatypes import StackConfig
|
||||
from llama_toolchain.distribution.distribution import distribution_dependencies
|
||||
from llama_toolchain.distribution.registry import resolve_distribution_spec
|
||||
|
||||
|
@ -80,7 +80,7 @@ class DistributionInstall(Subcommand):
|
|||
|
||||
config_file = distrib_dir / "config.yaml"
|
||||
if config_file.exists():
|
||||
c = DistributionConfig(**yaml.safe_load(config_file.read_text()))
|
||||
c = StackConfig(**yaml.safe_load(config_file.read_text()))
|
||||
if c.spec != dist.spec_id:
|
||||
self.parser.error(
|
||||
f"already installed distribution with `spec={c.spec}` does not match provided spec `{args.spec}`"
|
||||
|
@ -93,7 +93,7 @@ class DistributionInstall(Subcommand):
|
|||
return
|
||||
else:
|
||||
with open(config_file, "w") as f:
|
||||
c = DistributionConfig(
|
||||
c = StackConfig(
|
||||
spec=dist.spec_id,
|
||||
name=args.name,
|
||||
conda_env=conda_env,
|
||||
|
@ -106,6 +106,6 @@ class DistributionInstall(Subcommand):
|
|||
f"Failed to install distribution {dist.spec_id}", color="red"
|
||||
)
|
||||
cprint(
|
||||
f"Distribution `{args.name}` (with spec {dist.spec_id}) has been installed successfully!",
|
||||
f"Stack `{args.name}` (with spec {dist.spec_id}) has been installed successfully!",
|
||||
color="green",
|
||||
)
|
|
@ -10,7 +10,7 @@ import json
|
|||
from llama_toolchain.cli.subcommand import Subcommand
|
||||
|
||||
|
||||
class DistributionList(Subcommand):
|
||||
class StackList(Subcommand):
|
||||
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||
super().__init__()
|
||||
self.parser = subparsers.add_parser(
|
|
@ -8,14 +8,14 @@ import argparse
|
|||
|
||||
from llama_toolchain.cli.subcommand import Subcommand
|
||||
|
||||
from .configure import DistributionConfigure
|
||||
from .create import DistributionCreate
|
||||
from .install import DistributionInstall
|
||||
from .list import DistributionList
|
||||
from .start import DistributionStart
|
||||
from .configure import StackConfigure
|
||||
from .create import StackCreate
|
||||
from .install import StackInstall
|
||||
from .list import StackList
|
||||
from .start import StackStart
|
||||
|
||||
|
||||
class DistributionParser(Subcommand):
|
||||
class StackParser(Subcommand):
|
||||
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||
super().__init__()
|
||||
self.parser = subparsers.add_parser(
|
||||
|
@ -27,8 +27,8 @@ class DistributionParser(Subcommand):
|
|||
subparsers = self.parser.add_subparsers(title="distribution_subcommands")
|
||||
|
||||
# Add sub-commands
|
||||
DistributionList.create(subparsers)
|
||||
DistributionInstall.create(subparsers)
|
||||
DistributionCreate.create(subparsers)
|
||||
DistributionConfigure.create(subparsers)
|
||||
DistributionStart.create(subparsers)
|
||||
StackList.create(subparsers)
|
||||
StackInstall.create(subparsers)
|
||||
StackCreate.create(subparsers)
|
||||
StackConfigure.create(subparsers)
|
||||
StackStart.create(subparsers)
|
|
@ -13,7 +13,7 @@ from llama_toolchain.cli.subcommand import Subcommand
|
|||
from llama_toolchain.common.config_dirs import DISTRIBS_BASE_DIR
|
||||
|
||||
|
||||
class DistributionStart(Subcommand):
|
||||
class StackStart(Subcommand):
|
||||
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||
super().__init__()
|
||||
self.parser = subparsers.add_parser(
|
Loading…
Add table
Add a link
Reference in a new issue