forked from phoenix-oss/llama-stack-mirror
CLI Update: build -> configure -> run (#69)
* remove configure from build * remove config from build * configure to regenerate file * update memory providers * remove comments * udpate build script * add reedme * update doc * rename getting started * update build cli * update docker build script * configure update * clean up configure * [tmp fix] hardware requirement tmp fix * clean up build * fix configure * add example build files for conda & docker * remove resolve_distribution_spec * remove available_distribution_specs * example build files * update example build files * more clean up on build * add name args to override name * move distribution to yaml files * generate distribution specs * getting started guide * getting started * add build yaml to Dockerfile * cleanup distribution_dependencies * configure from docker image name * build relative paths * minor comment * getting started * Update getting_started.md * Update getting_started.md * address comments, configure within docker file * remove distribution types! * update getting started * update documentation * remove listing distribution * minor heading * address nits, remove docker_image=null * gitignore
This commit is contained in:
parent
73b71d9689
commit
d9147f3184
27 changed files with 759 additions and 512 deletions
|
@ -21,6 +21,8 @@ from pydantic import BaseModel
|
|||
from termcolor import cprint
|
||||
|
||||
from llama_toolchain.core.datatypes import * # noqa: F403
|
||||
from pathlib import Path
|
||||
|
||||
from llama_toolchain.core.distribution import api_providers, SERVER_DEPENDENCIES
|
||||
|
||||
|
||||
|
@ -39,87 +41,35 @@ class ApiInput(BaseModel):
|
|||
provider: str
|
||||
|
||||
|
||||
def build_package(
|
||||
api_inputs: List[ApiInput],
|
||||
image_type: ImageType,
|
||||
name: str,
|
||||
distribution_type: Optional[str] = None,
|
||||
docker_image: Optional[str] = None,
|
||||
):
|
||||
if not distribution_type:
|
||||
distribution_type = "adhoc"
|
||||
|
||||
build_dir = BUILDS_BASE_DIR / distribution_type / image_type.value
|
||||
os.makedirs(build_dir, exist_ok=True)
|
||||
|
||||
package_name = name.replace("::", "-")
|
||||
package_file = build_dir / f"{package_name}.yaml"
|
||||
|
||||
all_providers = api_providers()
|
||||
|
||||
def build_package(build_config: BuildConfig, build_file_path: Path):
|
||||
package_deps = Dependencies(
|
||||
docker_image=docker_image or "python:3.10-slim",
|
||||
docker_image=build_config.distribution_spec.docker_image or "python:3.10-slim",
|
||||
pip_packages=SERVER_DEPENDENCIES,
|
||||
)
|
||||
|
||||
stub_config = {}
|
||||
for api_input in api_inputs:
|
||||
api = api_input.api
|
||||
providers_for_api = all_providers[api]
|
||||
if api_input.provider not in providers_for_api:
|
||||
# extend package dependencies based on providers spec
|
||||
all_providers = api_providers()
|
||||
for api_str, provider in build_config.distribution_spec.providers.items():
|
||||
providers_for_api = all_providers[Api(api_str)]
|
||||
if provider not in providers_for_api:
|
||||
raise ValueError(
|
||||
f"Provider `{api_input.provider}` is not available for API `{api}`"
|
||||
f"Provider `{provider}` is not available for API `{api_str}`"
|
||||
)
|
||||
|
||||
provider = providers_for_api[api_input.provider]
|
||||
package_deps.pip_packages.extend(provider.pip_packages)
|
||||
if provider.docker_image:
|
||||
provider_spec = providers_for_api[provider]
|
||||
package_deps.pip_packages.extend(provider_spec.pip_packages)
|
||||
if provider_spec.docker_image:
|
||||
raise ValueError("A stack's dependencies cannot have a docker image")
|
||||
|
||||
stub_config[api.value] = {"provider_type": api_input.provider}
|
||||
|
||||
if package_file.exists():
|
||||
cprint(
|
||||
f"Build `{package_name}` exists; will reconfigure",
|
||||
color="yellow",
|
||||
)
|
||||
c = PackageConfig(**yaml.safe_load(package_file.read_text()))
|
||||
for api_str, new_config in stub_config.items():
|
||||
if api_str not in c.providers:
|
||||
c.providers[api_str] = new_config
|
||||
else:
|
||||
existing_config = c.providers[api_str]
|
||||
if existing_config["provider_type"] != new_config["provider_type"]:
|
||||
cprint(
|
||||
f"Provider `{api_str}` has changed from `{existing_config}` to `{new_config}`",
|
||||
color="yellow",
|
||||
)
|
||||
c.providers[api_str] = new_config
|
||||
else:
|
||||
c = PackageConfig(
|
||||
built_at=datetime.now(),
|
||||
package_name=package_name,
|
||||
providers=stub_config,
|
||||
)
|
||||
|
||||
c.distribution_type = distribution_type
|
||||
c.docker_image = package_name if image_type == ImageType.docker else None
|
||||
c.conda_env = package_name if image_type == ImageType.conda 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))
|
||||
|
||||
if image_type == ImageType.docker:
|
||||
if build_config.image_type == ImageType.docker.value:
|
||||
script = pkg_resources.resource_filename(
|
||||
"llama_toolchain", "core/build_container.sh"
|
||||
)
|
||||
args = [
|
||||
script,
|
||||
distribution_type,
|
||||
package_name,
|
||||
build_config.name,
|
||||
package_deps.docker_image,
|
||||
str(package_file),
|
||||
str(build_file_path),
|
||||
" ".join(package_deps.pip_packages),
|
||||
]
|
||||
else:
|
||||
|
@ -128,21 +78,14 @@ def build_package(
|
|||
)
|
||||
args = [
|
||||
script,
|
||||
distribution_type,
|
||||
package_name,
|
||||
str(package_file),
|
||||
build_config.name,
|
||||
" ".join(package_deps.pip_packages),
|
||||
]
|
||||
|
||||
return_code = run_with_pty(args)
|
||||
if return_code != 0:
|
||||
cprint(
|
||||
f"Failed to build target {package_name} with return code {return_code}",
|
||||
f"Failed to build target {build_config.name} with return code {return_code}",
|
||||
color="red",
|
||||
)
|
||||
return
|
||||
|
||||
cprint(
|
||||
f"Target `{package_name}` built with configuration at {str(package_file)}",
|
||||
color="green",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue