From 17172a8bf9ece0d4fbd5acc1f54da83ab511f4de Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Tue, 17 Sep 2024 11:29:07 -0700 Subject: [PATCH] move core -> distribution --- llama_stack/apis/agents/client.py | 2 +- llama_stack/apis/inference/client.py | 2 +- llama_stack/apis/memory/client.py | 2 +- llama_stack/apis/safety/client.py | 2 +- llama_stack/{ => apis}/stack.py | 0 llama_stack/cli/download.py | 6 +++--- llama_stack/cli/model/describe.py | 2 +- llama_stack/cli/stack/build.py | 12 ++++++------ llama_stack/cli/stack/configure.py | 14 +++++++------- llama_stack/cli/stack/list_apis.py | 2 +- llama_stack/cli/stack/list_providers.py | 4 ++-- llama_stack/cli/stack/run.py | 8 ++++---- llama_stack/{common => distribution}/__init__.py | 0 .../{core/package.py => distribution/build.py} | 10 +++++----- .../{core => distribution}/build_conda_env.sh | 0 .../{core => distribution}/build_container.sh | 2 +- llama_stack/{core => distribution}/common.sh | 0 llama_stack/{core => distribution}/configure.py | 9 +++++---- .../{core => distribution}/configure_container.sh | 0 llama_stack/{core => distribution}/datatypes.py | 2 +- llama_stack/{core => distribution}/distribution.py | 0 llama_stack/distribution/server/__init__.py | 12 ++++++++++++ .../{core => distribution/server}/server.py | 2 +- .../{core => distribution}/start_conda_env.sh | 2 +- .../{core => distribution}/start_container.sh | 2 +- .../{core => distribution/utils}/__init__.py | 0 .../{common => distribution/utils}/config_dirs.py | 0 .../{core => distribution/utils}/dynamic.py | 2 +- llama_stack/{common => distribution/utils}/exec.py | 0 .../{common => distribution/utils}/model_utils.py | 0 .../utils}/prompt_for_config.py | 0 .../{common => distribution/utils}/serialize.py | 0 .../adapters/inference/ollama/__init__.py | 2 +- .../providers/adapters/memory/chroma/__init__.py | 2 +- .../impls/meta_reference/agents/__init__.py | 2 +- .../impls/meta_reference/inference/generation.py | 2 +- .../impls/meta_reference/safety/safety.py | 2 +- llama_stack/providers/registry/agents.py | 2 +- llama_stack/providers/registry/control_plane.py | 2 +- llama_stack/providers/registry/inference.py | 2 +- llama_stack/providers/registry/memory.py | 2 +- llama_stack/providers/registry/safety.py | 2 +- llama_stack/providers/registry/telemetry.py | 2 +- llama_stack/providers/routers/memory/__init__.py | 2 +- llama_stack/providers/routers/memory/memory.py | 2 +- rfcs/openapi_generator/generate.py | 2 +- 46 files changed, 70 insertions(+), 57 deletions(-) rename llama_stack/{ => apis}/stack.py (100%) rename llama_stack/{common => distribution}/__init__.py (100%) rename llama_stack/{core/package.py => distribution/build.py} (88%) rename llama_stack/{core => distribution}/build_conda_env.sh (100%) rename llama_stack/{core => distribution}/build_container.sh (97%) rename llama_stack/{core => distribution}/common.sh (100%) rename llama_stack/{core => distribution}/configure.py (91%) rename llama_stack/{core => distribution}/configure_container.sh (100%) rename llama_stack/{core => distribution}/datatypes.py (99%) rename llama_stack/{core => distribution}/distribution.py (100%) create mode 100644 llama_stack/distribution/server/__init__.py rename llama_stack/{core => distribution/server}/server.py (99%) rename llama_stack/{core => distribution}/start_conda_env.sh (95%) rename llama_stack/{core => distribution}/start_container.sh (94%) rename llama_stack/{core => distribution/utils}/__init__.py (100%) rename llama_stack/{common => distribution/utils}/config_dirs.py (100%) rename llama_stack/{core => distribution/utils}/dynamic.py (97%) rename llama_stack/{common => distribution/utils}/exec.py (100%) rename llama_stack/{common => distribution/utils}/model_utils.py (100%) rename llama_stack/{common => distribution/utils}/prompt_for_config.py (100%) rename llama_stack/{common => distribution/utils}/serialize.py (100%) diff --git a/llama_stack/apis/agents/client.py b/llama_stack/apis/agents/client.py index d02de6916..8071440bc 100644 --- a/llama_stack/apis/agents/client.py +++ b/llama_stack/apis/agents/client.py @@ -16,7 +16,7 @@ from pydantic import BaseModel from termcolor import cprint from llama_models.llama3.api.datatypes import * # noqa: F403 -from llama_stack.core.datatypes import RemoteProviderConfig +from llama_stack.distribution.datatypes import RemoteProviderConfig from .agents import * # noqa: F403 from .event_logger import EventLogger diff --git a/llama_stack/apis/inference/client.py b/llama_stack/apis/inference/client.py index 951f4596e..f5321c628 100644 --- a/llama_stack/apis/inference/client.py +++ b/llama_stack/apis/inference/client.py @@ -11,7 +11,7 @@ from typing import Any, AsyncGenerator import fire import httpx -from llama_stack.core.datatypes import RemoteProviderConfig +from llama_stack.distribution.datatypes import RemoteProviderConfig from pydantic import BaseModel from termcolor import cprint diff --git a/llama_stack/apis/memory/client.py b/llama_stack/apis/memory/client.py index 3862fc5ac..d2845326b 100644 --- a/llama_stack/apis/memory/client.py +++ b/llama_stack/apis/memory/client.py @@ -14,7 +14,7 @@ from typing import Any, Dict, List, Optional import fire import httpx -from llama_stack.core.datatypes import RemoteProviderConfig +from llama_stack.distribution.datatypes import RemoteProviderConfig from termcolor import cprint from .memory import * # noqa: F403 diff --git a/llama_stack/apis/safety/client.py b/llama_stack/apis/safety/client.py index d09961a72..b7472686a 100644 --- a/llama_stack/apis/safety/client.py +++ b/llama_stack/apis/safety/client.py @@ -14,7 +14,7 @@ import httpx from llama_models.llama3.api.datatypes import UserMessage -from llama_stack.core.datatypes import RemoteProviderConfig +from llama_stack.distribution.datatypes import RemoteProviderConfig from pydantic import BaseModel from termcolor import cprint diff --git a/llama_stack/stack.py b/llama_stack/apis/stack.py similarity index 100% rename from llama_stack/stack.py rename to llama_stack/apis/stack.py diff --git a/llama_stack/cli/download.py b/llama_stack/cli/download.py index 3ec165f34..618036665 100644 --- a/llama_stack/cli/download.py +++ b/llama_stack/cli/download.py @@ -92,7 +92,7 @@ def _hf_download( from huggingface_hub import snapshot_download from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError - from llama_stack.common.model_utils import model_local_dir + from llama_stack.distribution.utils.model_utils import model_local_dir repo_id = model.huggingface_repo if repo_id is None: @@ -126,7 +126,7 @@ def _hf_download( def _meta_download(model: "Model", meta_url: str): from llama_models.sku_list import llama_meta_net_info - from llama_stack.common.model_utils import model_local_dir + from llama_stack.distribution.utils.model_utils import model_local_dir output_dir = Path(model_local_dir(model.descriptor())) os.makedirs(output_dir, exist_ok=True) @@ -188,7 +188,7 @@ class Manifest(BaseModel): def _download_from_manifest(manifest_file: str): - from llama_stack.common.model_utils import model_local_dir + from llama_stack.distribution.utils.model_utils import model_local_dir with open(manifest_file, "r") as f: d = json.load(f) diff --git a/llama_stack/cli/model/describe.py b/llama_stack/cli/model/describe.py index 24af7dd14..b100f7544 100644 --- a/llama_stack/cli/model/describe.py +++ b/llama_stack/cli/model/describe.py @@ -13,7 +13,7 @@ from termcolor import colored from llama_stack.cli.subcommand import Subcommand from llama_stack.cli.table import print_table -from llama_stack.common.serialize import EnumEncoder +from llama_stack.distribution.utils.serialize import EnumEncoder class ModelDescribe(Subcommand): diff --git a/llama_stack/cli/stack/build.py b/llama_stack/cli/stack/build.py index da4cb6161..c2df591c8 100644 --- a/llama_stack/cli/stack/build.py +++ b/llama_stack/cli/stack/build.py @@ -7,7 +7,7 @@ import argparse from llama_stack.cli.subcommand import Subcommand -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 from pathlib import Path import yaml @@ -44,9 +44,9 @@ class StackBuild(Subcommand): import json import os - from llama_stack.common.config_dirs import DISTRIBS_BASE_DIR - from llama_stack.common.serialize import EnumEncoder - from llama_stack.core.package import ApiInput, build_image, ImageType + from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR + from llama_stack.distribution.utils.serialize import EnumEncoder + from llama_stack.distribution.build import ApiInput, build_image, ImageType from termcolor import cprint # save build.yaml spec for building same distribution again @@ -74,8 +74,8 @@ class StackBuild(Subcommand): ) def _run_stack_build_command(self, args: argparse.Namespace) -> None: - from llama_stack.common.prompt_for_config import prompt_for_config - from llama_stack.core.dynamic import instantiate_class_type + from llama_stack.distribution.utils.prompt_for_config import prompt_for_config + from llama_stack.distribution.utils.dynamic import instantiate_class_type if not args.config: self.parser.error( diff --git a/llama_stack/cli/stack/configure.py b/llama_stack/cli/stack/configure.py index 6a1e7c740..0263166ce 100644 --- a/llama_stack/cli/stack/configure.py +++ b/llama_stack/cli/stack/configure.py @@ -14,10 +14,10 @@ import yaml from termcolor import cprint from llama_stack.cli.subcommand import Subcommand -from llama_stack.common.config_dirs import BUILDS_BASE_DIR +from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR -from llama_stack.common.exec import run_with_pty -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.utils.exec import run_with_pty +from llama_stack.distribution.datatypes import * # noqa: F403 import os @@ -49,7 +49,7 @@ class StackConfigure(Subcommand): ) def _run_stack_configure_cmd(self, args: argparse.Namespace) -> None: - from llama_stack.core.package import ImageType + from llama_stack.distribution.build import ImageType docker_image = None build_config_file = Path(args.config) @@ -66,7 +66,7 @@ class StackConfigure(Subcommand): os.makedirs(builds_dir, exist_ok=True) script = pkg_resources.resource_filename( - "llama_stack", "core/configure_container.sh" + "llama_stack", "distribution/configure_container.sh" ) script_args = [script, docker_image, str(builds_dir)] @@ -95,8 +95,8 @@ class StackConfigure(Subcommand): build_config: BuildConfig, output_dir: Optional[str] = None, ): - from llama_stack.common.serialize import EnumEncoder - from llama_stack.core.configure import configure_api_providers + from llama_stack.distribution.configure import configure_api_providers + from llama_stack.distribution.utils.serialize import EnumEncoder builds_dir = BUILDS_BASE_DIR / build_config.image_type if output_dir: diff --git a/llama_stack/cli/stack/list_apis.py b/llama_stack/cli/stack/list_apis.py index 6eed5ca51..cac803f92 100644 --- a/llama_stack/cli/stack/list_apis.py +++ b/llama_stack/cli/stack/list_apis.py @@ -26,7 +26,7 @@ class StackListApis(Subcommand): def _run_apis_list_cmd(self, args: argparse.Namespace) -> None: from llama_stack.cli.table import print_table - from llama_stack.core.distribution import stack_apis + from llama_stack.distribution.distribution import stack_apis # eventually, this should query a registry at llama.meta.com/llamastack/distributions headers = [ diff --git a/llama_stack/cli/stack/list_providers.py b/llama_stack/cli/stack/list_providers.py index 7568c69c9..33cfe6939 100644 --- a/llama_stack/cli/stack/list_providers.py +++ b/llama_stack/cli/stack/list_providers.py @@ -22,7 +22,7 @@ class StackListProviders(Subcommand): self.parser.set_defaults(func=self._run_providers_list_cmd) def _add_arguments(self): - from llama_stack.core.distribution import stack_apis + from llama_stack.distribution.distribution import stack_apis api_values = [a.value for a in stack_apis()] self.parser.add_argument( @@ -34,7 +34,7 @@ class StackListProviders(Subcommand): def _run_providers_list_cmd(self, args: argparse.Namespace) -> None: from llama_stack.cli.table import print_table - from llama_stack.core.distribution import Api, api_providers + from llama_stack.distribution.distribution import Api, api_providers all_providers = api_providers() providers_for_api = all_providers[Api(args.api)] diff --git a/llama_stack/cli/stack/run.py b/llama_stack/cli/stack/run.py index 614132f61..acdbcf3bc 100644 --- a/llama_stack/cli/stack/run.py +++ b/llama_stack/cli/stack/run.py @@ -12,7 +12,7 @@ import pkg_resources import yaml from llama_stack.cli.subcommand import Subcommand -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 class StackRun(Subcommand): @@ -47,7 +47,7 @@ class StackRun(Subcommand): ) def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: - from llama_stack.common.exec import run_with_pty + from llama_stack.distribution.utils.exec import run_with_pty if not args.config: self.parser.error("Must specify a config file to run") @@ -68,13 +68,13 @@ class StackRun(Subcommand): if config.docker_image: script = pkg_resources.resource_filename( "llama_stack", - "core/start_container.sh", + "distribution/start_container.sh", ) run_args = [script, config.docker_image] else: script = pkg_resources.resource_filename( "llama_stack", - "core/start_conda_env.sh", + "distribution/start_conda_env.sh", ) run_args = [ script, diff --git a/llama_stack/common/__init__.py b/llama_stack/distribution/__init__.py similarity index 100% rename from llama_stack/common/__init__.py rename to llama_stack/distribution/__init__.py diff --git a/llama_stack/core/package.py b/llama_stack/distribution/build.py similarity index 88% rename from llama_stack/core/package.py rename to llama_stack/distribution/build.py index 7e364f517..95cea6caa 100644 --- a/llama_stack/core/package.py +++ b/llama_stack/distribution/build.py @@ -12,12 +12,12 @@ from pydantic import BaseModel from termcolor import cprint -from llama_stack.common.exec import run_with_pty +from llama_stack.distribution.utils.exec import run_with_pty -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 from pathlib import Path -from llama_stack.core.distribution import api_providers, SERVER_DEPENDENCIES +from llama_stack.distribution.distribution import api_providers, SERVER_DEPENDENCIES class ImageType(Enum): @@ -68,7 +68,7 @@ def build_image(build_config: BuildConfig, build_file_path: Path): if build_config.image_type == ImageType.docker.value: script = pkg_resources.resource_filename( - "llama_stack", "core/build_container.sh" + "llama_stack", "distribution/build_container.sh" ) args = [ script, @@ -79,7 +79,7 @@ def build_image(build_config: BuildConfig, build_file_path: Path): ] else: script = pkg_resources.resource_filename( - "llama_stack", "core/build_conda_env.sh" + "llama_stack", "distribution/build_conda_env.sh" ) args = [ script, diff --git a/llama_stack/core/build_conda_env.sh b/llama_stack/distribution/build_conda_env.sh similarity index 100% rename from llama_stack/core/build_conda_env.sh rename to llama_stack/distribution/build_conda_env.sh diff --git a/llama_stack/core/build_container.sh b/llama_stack/distribution/build_container.sh similarity index 97% rename from llama_stack/core/build_container.sh rename to llama_stack/distribution/build_container.sh index 964557c41..c993fcec5 100755 --- a/llama_stack/core/build_container.sh +++ b/llama_stack/distribution/build_container.sh @@ -90,7 +90,7 @@ add_to_docker < List[ProviderSpec]: diff --git a/llama_stack/providers/registry/control_plane.py b/llama_stack/providers/registry/control_plane.py index 8e240b913..7465c4534 100644 --- a/llama_stack/providers/registry/control_plane.py +++ b/llama_stack/providers/registry/control_plane.py @@ -6,7 +6,7 @@ from typing import List -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 def available_providers() -> List[ProviderSpec]: diff --git a/llama_stack/providers/registry/inference.py b/llama_stack/providers/registry/inference.py index 202a316e6..c8050cdca 100644 --- a/llama_stack/providers/registry/inference.py +++ b/llama_stack/providers/registry/inference.py @@ -6,7 +6,7 @@ from typing import List -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 def available_providers() -> List[ProviderSpec]: diff --git a/llama_stack/providers/registry/memory.py b/llama_stack/providers/registry/memory.py index 02f4958f1..12487567a 100644 --- a/llama_stack/providers/registry/memory.py +++ b/llama_stack/providers/registry/memory.py @@ -6,7 +6,7 @@ from typing import List -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 EMBEDDING_DEPS = [ "blobfile", diff --git a/llama_stack/providers/registry/safety.py b/llama_stack/providers/registry/safety.py index 764af258e..6e9583066 100644 --- a/llama_stack/providers/registry/safety.py +++ b/llama_stack/providers/registry/safety.py @@ -6,7 +6,7 @@ from typing import List -from llama_stack.core.datatypes import Api, InlineProviderSpec, ProviderSpec +from llama_stack.distribution.datatypes import Api, InlineProviderSpec, ProviderSpec def available_providers() -> List[ProviderSpec]: diff --git a/llama_stack/providers/registry/telemetry.py b/llama_stack/providers/registry/telemetry.py index 0199666da..29c57fd86 100644 --- a/llama_stack/providers/registry/telemetry.py +++ b/llama_stack/providers/registry/telemetry.py @@ -6,7 +6,7 @@ from typing import List -from llama_stack.core.datatypes import * # noqa: F403 +from llama_stack.distribution.datatypes import * # noqa: F403 def available_providers() -> List[ProviderSpec]: diff --git a/llama_stack/providers/routers/memory/__init__.py b/llama_stack/providers/routers/memory/__init__.py index 4843d688b..d4dbbb1d4 100644 --- a/llama_stack/providers/routers/memory/__init__.py +++ b/llama_stack/providers/routers/memory/__init__.py @@ -6,7 +6,7 @@ from typing import Any, List, Tuple -from llama_stack.core.datatypes import Api +from llama_stack.distribution.datatypes import Api async def get_router_impl(inner_impls: List[Tuple[str, Any]], deps: List[Api]): diff --git a/llama_stack/providers/routers/memory/memory.py b/llama_stack/providers/routers/memory/memory.py index 85c284e2f..b96cde626 100644 --- a/llama_stack/providers/routers/memory/memory.py +++ b/llama_stack/providers/routers/memory/memory.py @@ -6,7 +6,7 @@ from typing import Any, Dict, List, Tuple -from llama_stack.core.datatypes import Api +from llama_stack.distribution.datatypes import Api from llama_stack.apis.memory import * # noqa: F403 diff --git a/rfcs/openapi_generator/generate.py b/rfcs/openapi_generator/generate.py index bdc67fbed..0eda7282b 100644 --- a/rfcs/openapi_generator/generate.py +++ b/rfcs/openapi_generator/generate.py @@ -31,7 +31,7 @@ from .pyopenapi.utility import Specification schema_utils.json_schema_type = json_schema_type -from llama_stack.stack import LlamaStack +from llama_stack.apis.stack import LlamaStack # TODO: this should be fixed in the generator itself so it reads appropriate annotations