mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-31 16:01:46 +00:00
pip install helptext
This commit is contained in:
parent
164aeca848
commit
33ea496cf9
5 changed files with 53 additions and 134 deletions
|
@ -47,19 +47,12 @@ class ApiInput(BaseModel):
|
||||||
api: Api
|
api: Api
|
||||||
provider: str
|
provider: str
|
||||||
|
|
||||||
|
def get_provider_dependencies(config_providers: Dict[str, List[Provider]]) -> tuple[list[str], list[str]]:
|
||||||
def build_image(build_config: BuildConfig, build_file_path: Path):
|
"""Get normal and special dependencies from provider configuration."""
|
||||||
package_deps = Dependencies(
|
|
||||||
docker_image=build_config.distribution_spec.docker_image or "python:3.10-slim",
|
|
||||||
pip_packages=SERVER_DEPENDENCIES,
|
|
||||||
)
|
|
||||||
|
|
||||||
# extend package dependencies based on providers spec
|
|
||||||
all_providers = get_provider_registry()
|
all_providers = get_provider_registry()
|
||||||
for (
|
deps = []
|
||||||
api_str,
|
|
||||||
provider_or_providers,
|
for api_str, provider_or_providers in config_providers.items():
|
||||||
) in build_config.distribution_spec.providers.items():
|
|
||||||
providers_for_api = all_providers[Api(api_str)]
|
providers_for_api = all_providers[Api(api_str)]
|
||||||
|
|
||||||
providers = (
|
providers = (
|
||||||
|
@ -69,25 +62,51 @@ def build_image(build_config: BuildConfig, build_file_path: Path):
|
||||||
)
|
)
|
||||||
|
|
||||||
for provider in providers:
|
for provider in providers:
|
||||||
if provider not in providers_for_api:
|
# Providers from BuildConfig and RunConfig are subtly different – not great
|
||||||
|
provider_type = provider if isinstance(provider, str) else provider.provider_type
|
||||||
|
|
||||||
|
if provider_type not in providers_for_api:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Provider `{provider}` is not available for API `{api_str}`"
|
f"Provider `{provider}` is not available for API `{api_str}`"
|
||||||
)
|
)
|
||||||
|
|
||||||
provider_spec = providers_for_api[provider]
|
provider_spec = providers_for_api[provider_type]
|
||||||
package_deps.pip_packages.extend(provider_spec.pip_packages)
|
deps.extend(provider_spec.pip_packages)
|
||||||
if provider_spec.docker_image:
|
if provider_spec.docker_image:
|
||||||
raise ValueError("A stack's dependencies cannot have a docker image")
|
raise ValueError("A stack's dependencies cannot have a docker image")
|
||||||
|
|
||||||
|
normal_deps = []
|
||||||
special_deps = []
|
special_deps = []
|
||||||
deps = []
|
for package in deps:
|
||||||
for package in package_deps.pip_packages:
|
|
||||||
if "--no-deps" in package or "--index-url" in package:
|
if "--no-deps" in package or "--index-url" in package:
|
||||||
special_deps.append(package)
|
special_deps.append(package)
|
||||||
else:
|
else:
|
||||||
deps.append(package)
|
normal_deps.append(package)
|
||||||
deps = list(set(deps))
|
|
||||||
special_deps = list(set(special_deps))
|
return list(set(normal_deps)), list(set(special_deps))
|
||||||
|
|
||||||
|
|
||||||
|
def print_pip_install_help(providers: Dict[str, List[Provider]]):
|
||||||
|
normal_deps, special_deps = get_provider_dependencies(providers)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Please install needed dependencies using the following commands:\n\n\tpip install {' '.join(normal_deps)}"
|
||||||
|
)
|
||||||
|
for special_dep in special_deps:
|
||||||
|
print(f"\tpip install {special_dep}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
def build_image(build_config: BuildConfig, build_file_path: Path):
|
||||||
|
package_deps = Dependencies(
|
||||||
|
docker_image=build_config.distribution_spec.docker_image or "python:3.10-slim",
|
||||||
|
pip_packages=SERVER_DEPENDENCIES,
|
||||||
|
)
|
||||||
|
|
||||||
|
# extend package dependencies based on providers spec
|
||||||
|
normal_deps, special_deps = get_provider_dependencies(build_config.distribution_spec.providers)
|
||||||
|
package_deps.pip_packages.extend(normal_deps)
|
||||||
|
package_deps.pip_packages.extend(special_deps)
|
||||||
|
|
||||||
if build_config.image_type == ImageType.docker.value:
|
if build_config.image_type == ImageType.docker.value:
|
||||||
script = pkg_resources.resource_filename(
|
script = pkg_resources.resource_filename(
|
||||||
|
@ -99,7 +118,7 @@ def build_image(build_config: BuildConfig, build_file_path: Path):
|
||||||
package_deps.docker_image,
|
package_deps.docker_image,
|
||||||
str(build_file_path),
|
str(build_file_path),
|
||||||
str(BUILDS_BASE_DIR / ImageType.docker.value),
|
str(BUILDS_BASE_DIR / ImageType.docker.value),
|
||||||
" ".join(deps),
|
" ".join(normal_deps),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
script = pkg_resources.resource_filename(
|
script = pkg_resources.resource_filename(
|
||||||
|
@ -109,7 +128,7 @@ def build_image(build_config: BuildConfig, build_file_path: Path):
|
||||||
script,
|
script,
|
||||||
build_config.name,
|
build_config.name,
|
||||||
str(build_file_path),
|
str(build_file_path),
|
||||||
" ".join(deps),
|
" ".join(normal_deps),
|
||||||
]
|
]
|
||||||
|
|
||||||
if special_deps:
|
if special_deps:
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# This source code is licensed under the terms described in the LICENSE file in
|
|
||||||
# the root directory of this source tree.
|
|
|
@ -1,89 +0,0 @@
|
||||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# This source code is licensed under the terms described in the LICENSE file in
|
|
||||||
# the root directory of this source tree.
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from llama_stack.providers.datatypes import * # noqa: F403
|
|
||||||
from llama_stack.distribution.datatypes import * # noqa: F403
|
|
||||||
from llama_stack.distribution.configure import parse_and_maybe_upgrade_config
|
|
||||||
from llama_stack.distribution.distribution import get_provider_registry
|
|
||||||
from llama_stack.distribution.resolver import resolve_impls
|
|
||||||
|
|
||||||
|
|
||||||
class LlamaStackInline:
|
|
||||||
def __init__(self, run_config_path: str):
|
|
||||||
self.run_config_path = run_config_path
|
|
||||||
self.impls = {}
|
|
||||||
self.run_config = None
|
|
||||||
|
|
||||||
def print_pip_command(self):
|
|
||||||
# TODO: de-dupe this with build.py
|
|
||||||
all_providers = get_provider_registry()
|
|
||||||
deps = []
|
|
||||||
for (
|
|
||||||
api_str,
|
|
||||||
provider_or_providers,
|
|
||||||
) in self.run_config.providers.items():
|
|
||||||
providers_for_api = all_providers[Api(api_str)]
|
|
||||||
|
|
||||||
providers = (
|
|
||||||
provider_or_providers
|
|
||||||
if isinstance(provider_or_providers, list)
|
|
||||||
else [provider_or_providers]
|
|
||||||
)
|
|
||||||
|
|
||||||
for provider in providers:
|
|
||||||
if provider.provider_id not in providers_for_api:
|
|
||||||
raise ValueError(
|
|
||||||
f"Provider `{provider}` is not available for API `{api_str}`"
|
|
||||||
)
|
|
||||||
|
|
||||||
provider_spec = providers_for_api[provider.provider_id]
|
|
||||||
deps.extend(provider_spec.pip_packages)
|
|
||||||
if provider_spec.docker_image:
|
|
||||||
raise ValueError(
|
|
||||||
"A stack's dependencies cannot have a docker image"
|
|
||||||
)
|
|
||||||
|
|
||||||
normal_deps = []
|
|
||||||
special_deps = []
|
|
||||||
for package in deps:
|
|
||||||
if "--no-deps" in package or "--index-url" in package:
|
|
||||||
special_deps.append(package)
|
|
||||||
else:
|
|
||||||
normal_deps.append(package)
|
|
||||||
deps = list(set(deps))
|
|
||||||
special_deps = list(set(special_deps))
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"Please install needed dependencies using the following commands:\n\n\tpip install {' '.join(normal_deps)}"
|
|
||||||
)
|
|
||||||
for special_dep in special_deps:
|
|
||||||
print(f"\tpip install {special_dep}")
|
|
||||||
print()
|
|
||||||
|
|
||||||
async def initialize(self):
|
|
||||||
with open(self.run_config_path, "r") as f:
|
|
||||||
config_dict = yaml.safe_load(f)
|
|
||||||
|
|
||||||
self.run_config = parse_and_maybe_upgrade_config(config_dict)
|
|
||||||
|
|
||||||
all_providers = get_provider_registry()
|
|
||||||
|
|
||||||
try:
|
|
||||||
impls = await resolve_impls(self.run_config, all_providers)
|
|
||||||
self.impls = impls
|
|
||||||
except ModuleNotFoundError as e:
|
|
||||||
print(str(e))
|
|
||||||
self.print_pip_command()
|
|
||||||
|
|
||||||
if "provider_data" in config_dict:
|
|
||||||
provider_id = chosen[api.value][0].provider_id
|
|
||||||
provider_data = config_dict["provider_data"].get(provider_id, {})
|
|
||||||
if provider_data:
|
|
||||||
set_request_provider_data(
|
|
||||||
{"X-LlamaStack-ProviderData": json.dumps(provider_data)}
|
|
||||||
)
|
|
|
@ -1,16 +0,0 @@
|
||||||
from inline import LlamaStackInline
|
|
||||||
from llama_stack.apis.inference.inference import Inference
|
|
||||||
|
|
||||||
from llama_stack.providers.datatypes import * # noqa: F403
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
inline = LlamaStackInline("/home/dalton/.llama/builds/conda/nov5-run.yaml")
|
|
||||||
await inline.initialize()
|
|
||||||
print(inline.impls)
|
|
||||||
|
|
||||||
|
|
||||||
# Run the main function
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
asyncio.run(main())
|
|
|
@ -17,6 +17,7 @@ from llama_stack.distribution.configure import parse_and_maybe_upgrade_config
|
||||||
from llama_stack.distribution.distribution import get_provider_registry
|
from llama_stack.distribution.distribution import get_provider_registry
|
||||||
from llama_stack.distribution.request_headers import set_request_provider_data
|
from llama_stack.distribution.request_headers import set_request_provider_data
|
||||||
from llama_stack.distribution.resolver import resolve_impls
|
from llama_stack.distribution.resolver import resolve_impls
|
||||||
|
from llama_stack.distribution.build import print_pip_install_help
|
||||||
from llama_stack.distribution.store import CachedDiskDistributionRegistry
|
from llama_stack.distribution.store import CachedDiskDistributionRegistry
|
||||||
from llama_stack.providers.utils.kvstore import kvstore_impl, SqliteKVStoreConfig
|
from llama_stack.providers.utils.kvstore import kvstore_impl, SqliteKVStoreConfig
|
||||||
|
|
||||||
|
@ -37,7 +38,12 @@ async def resolve_impls_for_test_v2(
|
||||||
sqlite_file = tempfile.NamedTemporaryFile(delete=False, suffix=".db")
|
sqlite_file = tempfile.NamedTemporaryFile(delete=False, suffix=".db")
|
||||||
dist_kvstore = await kvstore_impl(SqliteKVStoreConfig(db_path=sqlite_file.name))
|
dist_kvstore = await kvstore_impl(SqliteKVStoreConfig(db_path=sqlite_file.name))
|
||||||
dist_registry = CachedDiskDistributionRegistry(dist_kvstore)
|
dist_registry = CachedDiskDistributionRegistry(dist_kvstore)
|
||||||
impls = await resolve_impls(run_config, get_provider_registry(), dist_registry)
|
try:
|
||||||
|
impls = await resolve_impls(run_config, get_provider_registry(), dist_registry)
|
||||||
|
except ModuleNotFoundError as e:
|
||||||
|
print_pip_install_help(providers)
|
||||||
|
print(f"ModuleNotFoundError: {e}") # Add explicit print of error
|
||||||
|
raise e
|
||||||
|
|
||||||
if provider_data:
|
if provider_data:
|
||||||
set_request_provider_data(
|
set_request_provider_data(
|
||||||
|
@ -66,7 +72,11 @@ async def resolve_impls_for_test(api: Api, deps: List[Api] = None):
|
||||||
providers=chosen,
|
providers=chosen,
|
||||||
)
|
)
|
||||||
run_config = parse_and_maybe_upgrade_config(run_config)
|
run_config = parse_and_maybe_upgrade_config(run_config)
|
||||||
impls = await resolve_impls(run_config, get_provider_registry())
|
try:
|
||||||
|
impls = await resolve_impls(run_config, get_provider_registry())
|
||||||
|
except ModuleNotFoundError as e:
|
||||||
|
print_pip_install_help(providers)
|
||||||
|
print(f"ModuleNotFoundError: {e}") # Add explicit print of error
|
||||||
|
|
||||||
if "provider_data" in config_dict:
|
if "provider_data" in config_dict:
|
||||||
provider_id = chosen[api.value][0].provider_id
|
provider_id = chosen[api.value][0].provider_id
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue