Update distribution_id -> distribution_type, provider_id -> provider_type

This commit is contained in:
Ashwin Bharambe 2024-09-07 08:42:28 -07:00
parent 3f090d1975
commit 70e682fbdf
18 changed files with 66 additions and 66 deletions

View file

@ -248,8 +248,8 @@ llama stack list-distributions
``` ```
<pre style="font-family: monospace;"> <pre style="font-family: monospace;">
i+--------------------------------+---------------------------------------+----------------------------------------------------------------------+ i+-------------------------------+---------------------------------------+----------------------------------------------------------------------+
| Distribution ID | Providers | Description | | Distribution Type | Providers | Description |
+--------------------------------+---------------------------------------+----------------------------------------------------------------------+ +--------------------------------+---------------------------------------+----------------------------------------------------------------------+
| local | { | Use code from `llama_toolchain` itself to serve all llama stack APIs | | local | { | Use code from `llama_toolchain` itself to serve all llama stack APIs |
| | "inference": "meta-reference", | | | | "inference": "meta-reference", | |

View file

@ -13,7 +13,7 @@ def available_agentic_system_providers() -> List[ProviderSpec]:
return [ return [
InlineProviderSpec( InlineProviderSpec(
api=Api.agentic_system, api=Api.agentic_system,
provider_id="meta-reference", provider_type="meta-reference",
pip_packages=[ pip_packages=[
"codeshield", "codeshield",
"matplotlib", "matplotlib",

View file

@ -52,7 +52,7 @@ class StackBuild(Subcommand):
BuildType, BuildType,
) )
allowed_ids = [d.distribution_id for d in available_distribution_specs()] allowed_ids = [d.distribution_type for d in available_distribution_specs()]
self.parser.add_argument( self.parser.add_argument(
"distribution", "distribution",
type=str, type=str,
@ -101,7 +101,7 @@ class StackBuild(Subcommand):
api_inputs.append( api_inputs.append(
ApiInput( ApiInput(
api=api, api=api,
provider=provider_spec.provider_id, provider=provider_spec.provider_type,
) )
) )
docker_image = None docker_image = None
@ -115,11 +115,11 @@ class StackBuild(Subcommand):
self.parser.error(f"Could not find distribution {args.distribution}") self.parser.error(f"Could not find distribution {args.distribution}")
return return
for api, provider_id in dist.providers.items(): for api, provider_type in dist.providers.items():
api_inputs.append( api_inputs.append(
ApiInput( ApiInput(
api=api, api=api,
provider=provider_id, provider=provider_type,
) )
) )
docker_image = dist.docker_image docker_image = dist.docker_image
@ -128,6 +128,6 @@ class StackBuild(Subcommand):
api_inputs, api_inputs,
build_type=BuildType(args.type), build_type=BuildType(args.type),
name=args.name, name=args.name,
distribution_id=args.distribution, distribution_type=args.distribution,
docker_image=docker_image, docker_image=docker_image,
) )

View file

@ -36,7 +36,7 @@ class StackConfigure(Subcommand):
) )
from llama_toolchain.core.package import BuildType from llama_toolchain.core.package import BuildType
allowed_ids = [d.distribution_id for d in available_distribution_specs()] allowed_ids = [d.distribution_type for d in available_distribution_specs()]
self.parser.add_argument( self.parser.add_argument(
"distribution", "distribution",
type=str, type=str,
@ -84,7 +84,7 @@ def configure_llama_distribution(config_file: Path) -> None:
if config.providers: if config.providers:
cprint( cprint(
f"Configuration already exists for {config.distribution_id}. Will overwrite...", f"Configuration already exists for {config.distribution_type}. Will overwrite...",
"yellow", "yellow",
attrs=["bold"], attrs=["bold"],
) )

View file

@ -33,7 +33,7 @@ class StackListDistributions(Subcommand):
# eventually, this should query a registry at llama.meta.com/llamastack/distributions # eventually, this should query a registry at llama.meta.com/llamastack/distributions
headers = [ headers = [
"Distribution ID", "Distribution Type",
"Providers", "Providers",
"Description", "Description",
] ]
@ -43,7 +43,7 @@ class StackListDistributions(Subcommand):
providers = {k.value: v for k, v in spec.providers.items()} providers = {k.value: v for k, v in spec.providers.items()}
rows.append( rows.append(
[ [
spec.distribution_id, spec.distribution_type,
json.dumps(providers, indent=2), json.dumps(providers, indent=2),
spec.description, spec.description,
] ]

View file

@ -41,7 +41,7 @@ class StackListProviders(Subcommand):
# eventually, this should query a registry at llama.meta.com/llamastack/distributions # eventually, this should query a registry at llama.meta.com/llamastack/distributions
headers = [ headers = [
"Provider ID", "Provider Type",
"PIP Package Dependencies", "PIP Package Dependencies",
] ]
@ -49,7 +49,7 @@ class StackListProviders(Subcommand):
for spec in providers_for_api.values(): for spec in providers_for_api.values():
rows.append( rows.append(
[ [
spec.provider_id, spec.provider_type,
",".join(spec.pip_packages), ",".join(spec.pip_packages),
] ]
) )

View file

@ -80,7 +80,7 @@ class StackRun(Subcommand):
with open(config_file, "r") as f: with open(config_file, "r") as f:
config = PackageConfig(**yaml.safe_load(f)) config = PackageConfig(**yaml.safe_load(f))
if not config.distribution_id: if not config.distribution_type:
raise ValueError("Build config appears to be corrupt.") raise ValueError("Build config appears to be corrupt.")
if config.docker_image: if config.docker_image:

View file

@ -20,12 +20,12 @@ fi
set -euo pipefail set -euo pipefail
if [ "$#" -ne 3 ]; then if [ "$#" -ne 3 ]; then
echo "Usage: $0 <distribution_id> <build_name> <pip_dependencies>" >&2 echo "Usage: $0 <distribution_type> <build_name> <pip_dependencies>" >&2
echo "Example: $0 <distribution_id> mybuild 'numpy pandas scipy'" >&2 echo "Example: $0 <distribution_type> mybuild 'numpy pandas scipy'" >&2
exit 1 exit 1
fi fi
distribution_id="$1" distribution_type="$1"
build_name="$2" build_name="$2"
env_name="llamastack-$build_name" env_name="llamastack-$build_name"
pip_dependencies="$3" pip_dependencies="$3"
@ -117,4 +117,4 @@ ensure_conda_env_python310 "$env_name" "$pip_dependencies"
printf "${GREEN}Successfully setup conda environment. Configuring build...${NC}\n" printf "${GREEN}Successfully setup conda environment. Configuring build...${NC}\n"
$CONDA_PREFIX/bin/python3 -m llama_toolchain.cli.llama stack configure $distribution_id --name "$build_name" --type conda_env $CONDA_PREFIX/bin/python3 -m llama_toolchain.cli.llama stack configure $distribution_type --name "$build_name" --type conda_env

View file

@ -5,12 +5,12 @@ LLAMA_TOOLCHAIN_DIR=${LLAMA_TOOLCHAIN_DIR:-}
TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-} TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-}
if [ "$#" -ne 4 ]; then if [ "$#" -ne 4 ]; then
echo "Usage: $0 <distribution_id> <build_name> <docker_base> <pip_dependencies> echo "Usage: $0 <distribution_type> <build_name> <docker_base> <pip_dependencies>
echo "Example: $0 distribution_id my-fastapi-app python:3.9-slim 'fastapi uvicorn' echo "Example: $0 distribution_type my-fastapi-app python:3.9-slim 'fastapi uvicorn'
exit 1 exit 1
fi fi
distribution_id=$1 distribution_type=$1
build_name="$2" build_name="$2"
image_name="llamastack-$build_name" image_name="llamastack-$build_name"
docker_base=$3 docker_base=$3
@ -110,4 +110,4 @@ set +x
printf "${GREEN}Succesfully setup Podman image. Configuring build...${NC}" printf "${GREEN}Succesfully setup Podman image. Configuring build...${NC}"
echo "You can run it with: podman run -p 8000:8000 $image_name" echo "You can run it with: podman run -p 8000:8000 $image_name"
$CONDA_PREFIX/bin/python3 -m llama_toolchain.cli.llama stack configure $distribution_id --name "$build_name" --type container $CONDA_PREFIX/bin/python3 -m llama_toolchain.cli.llama stack configure $distribution_type --name "$build_name" --type container

View file

@ -21,14 +21,14 @@ def configure_api_providers(existing_configs: Dict[str, Any]) -> None:
for api_str, stub_config in existing_configs.items(): for api_str, stub_config in existing_configs.items():
api = Api(api_str) api = Api(api_str)
providers = all_providers[api] providers = all_providers[api]
provider_id = stub_config["provider_id"] provider_type = stub_config["provider_type"]
if provider_id not in providers: if provider_type not in providers:
raise ValueError( raise ValueError(
f"Unknown provider `{provider_id}` is not available for API `{api_str}`" f"Unknown provider `{provider_type}` is not available for API `{api_str}`"
) )
provider_spec = providers[provider_id] provider_spec = providers[provider_type]
cprint(f"Configuring API: {api_str} ({provider_id})", "white", attrs=["bold"]) cprint(f"Configuring API: {api_str} ({provider_type})", "white", attrs=["bold"])
config_type = instantiate_class_type(provider_spec.config_class) config_type = instantiate_class_type(provider_spec.config_class)
try: try:
@ -43,7 +43,7 @@ def configure_api_providers(existing_configs: Dict[str, Any]) -> None:
print("") print("")
provider_configs[api_str] = { provider_configs[api_str] = {
"provider_id": provider_id, "provider_type": provider_type,
**provider_config.dict(), **provider_config.dict(),
} }

View file

@ -31,7 +31,7 @@ class ApiEndpoint(BaseModel):
@json_schema_type @json_schema_type
class ProviderSpec(BaseModel): class ProviderSpec(BaseModel):
api: Api api: Api
provider_id: str provider_type: str
config_class: str = Field( config_class: str = Field(
..., ...,
description="Fully-qualified classname of the config for this provider", description="Fully-qualified classname of the config for this provider",
@ -100,7 +100,7 @@ class RemoteProviderConfig(BaseModel):
return url.rstrip("/") return url.rstrip("/")
def remote_provider_id(adapter_id: str) -> str: def remote_provider_type(adapter_id: str) -> str:
return f"remote::{adapter_id}" return f"remote::{adapter_id}"
@ -141,22 +141,22 @@ def remote_provider_spec(
if adapter and adapter.config_class if adapter and adapter.config_class
else "llama_toolchain.core.datatypes.RemoteProviderConfig" else "llama_toolchain.core.datatypes.RemoteProviderConfig"
) )
provider_id = remote_provider_id(adapter.adapter_id) if adapter else "remote" provider_type = remote_provider_type(adapter.adapter_id) if adapter else "remote"
return RemoteProviderSpec( return RemoteProviderSpec(
api=api, provider_id=provider_id, config_class=config_class, adapter=adapter api=api, provider_type=provider_type, config_class=config_class, adapter=adapter
) )
@json_schema_type @json_schema_type
class DistributionSpec(BaseModel): class DistributionSpec(BaseModel):
distribution_id: str distribution_type: str
description: str description: str
docker_image: Optional[str] = None docker_image: Optional[str] = None
providers: Dict[Api, str] = Field( providers: Dict[Api, str] = Field(
default_factory=dict, default_factory=dict,
description="Provider IDs for each of the APIs provided by this distribution", description="Provider Types for each of the APIs provided by this distribution",
) )
@ -171,7 +171,7 @@ Reference to the distribution this package refers to. For unregistered (adhoc) p
this could be just a hash this could be just a hash
""", """,
) )
distribution_id: Optional[str] = None distribution_type: Optional[str] = None
docker_image: Optional[str] = Field( docker_image: Optional[str] = Field(
default=None, default=None,

View file

@ -83,18 +83,18 @@ def api_endpoints() -> Dict[Api, List[ApiEndpoint]]:
def api_providers() -> Dict[Api, Dict[str, ProviderSpec]]: def api_providers() -> Dict[Api, Dict[str, ProviderSpec]]:
inference_providers_by_id = { inference_providers_by_id = {
a.provider_id: a for a in available_inference_providers() a.provider_type: a for a in available_inference_providers()
} }
safety_providers_by_id = {a.provider_id: a for a in available_safety_providers()} safety_providers_by_id = {a.provider_type: a for a in available_safety_providers()}
agentic_system_providers_by_id = { agentic_system_providers_by_id = {
a.provider_id: a for a in available_agentic_system_providers() a.provider_type: a for a in available_agentic_system_providers()
} }
ret = { ret = {
Api.inference: inference_providers_by_id, Api.inference: inference_providers_by_id,
Api.safety: safety_providers_by_id, Api.safety: safety_providers_by_id,
Api.agentic_system: agentic_system_providers_by_id, Api.agentic_system: agentic_system_providers_by_id,
Api.memory: {a.provider_id: a for a in available_memory_providers()}, Api.memory: {a.provider_type: a for a in available_memory_providers()},
} }
for k, v in ret.items(): for k, v in ret.items():
v["remote"] = remote_provider_spec(k) v["remote"] = remote_provider_spec(k)

View file

@ -14,7 +14,7 @@ from .datatypes import * # noqa: F403
def available_distribution_specs() -> List[DistributionSpec]: def available_distribution_specs() -> List[DistributionSpec]:
return [ return [
DistributionSpec( DistributionSpec(
distribution_id="local", distribution_type="local",
description="Use code from `llama_toolchain` itself to serve all llama stack APIs", description="Use code from `llama_toolchain` itself to serve all llama stack APIs",
providers={ providers={
Api.inference: "meta-reference", Api.inference: "meta-reference",
@ -24,35 +24,35 @@ def available_distribution_specs() -> List[DistributionSpec]:
}, },
), ),
DistributionSpec( DistributionSpec(
distribution_id="remote", distribution_type="remote",
description="Point to remote services for all llama stack APIs", description="Point to remote services for all llama stack APIs",
providers={x: "remote" for x in Api}, providers={x: "remote" for x in Api},
), ),
DistributionSpec( DistributionSpec(
distribution_id="local-ollama", distribution_type="local-ollama",
description="Like local, but use ollama for running LLM inference", description="Like local, but use ollama for running LLM inference",
providers={ providers={
Api.inference: remote_provider_id("ollama"), Api.inference: remote_provider_type("ollama"),
Api.safety: "meta-reference", Api.safety: "meta-reference",
Api.agentic_system: "meta-reference", Api.agentic_system: "meta-reference",
Api.memory: "meta-reference-faiss", Api.memory: "meta-reference-faiss",
}, },
), ),
DistributionSpec( DistributionSpec(
distribution_id="local-plus-fireworks-inference", distribution_type="local-plus-fireworks-inference",
description="Use Fireworks.ai for running LLM inference", description="Use Fireworks.ai for running LLM inference",
providers={ providers={
Api.inference: remote_provider_id("fireworks"), Api.inference: remote_provider_type("fireworks"),
Api.safety: "meta-reference", Api.safety: "meta-reference",
Api.agentic_system: "meta-reference", Api.agentic_system: "meta-reference",
Api.memory: "meta-reference-faiss", Api.memory: "meta-reference-faiss",
}, },
), ),
DistributionSpec( DistributionSpec(
distribution_id="local-plus-together-inference", distribution_type="local-plus-together-inference",
description="Use Together.ai for running LLM inference", description="Use Together.ai for running LLM inference",
providers={ providers={
Api.inference: remote_provider_id("together"), Api.inference: remote_provider_type("together"),
Api.safety: "meta-reference", Api.safety: "meta-reference",
Api.agentic_system: "meta-reference", Api.agentic_system: "meta-reference",
Api.memory: "meta-reference-faiss", Api.memory: "meta-reference-faiss",
@ -62,8 +62,8 @@ def available_distribution_specs() -> List[DistributionSpec]:
@lru_cache() @lru_cache()
def resolve_distribution_spec(distribution_id: str) -> Optional[DistributionSpec]: def resolve_distribution_spec(distribution_type: str) -> Optional[DistributionSpec]:
for spec in available_distribution_specs(): for spec in available_distribution_specs():
if spec.distribution_id == distribution_id: if spec.distribution_type == distribution_type:
return spec return spec
return None return None

View file

@ -46,13 +46,13 @@ def build_package(
api_inputs: List[ApiInput], api_inputs: List[ApiInput],
build_type: BuildType, build_type: BuildType,
name: str, name: str,
distribution_id: Optional[str] = None, distribution_type: Optional[str] = None,
docker_image: Optional[str] = None, docker_image: Optional[str] = None,
): ):
if not distribution_id: if not distribution_type:
distribution_id = "adhoc" distribution_type = "adhoc"
build_dir = BUILDS_BASE_DIR / distribution_id / build_type.descriptor() build_dir = BUILDS_BASE_DIR / distribution_type / build_type.descriptor()
os.makedirs(build_dir, exist_ok=True) os.makedirs(build_dir, exist_ok=True)
package_name = name.replace("::", "-") package_name = name.replace("::", "-")
@ -79,7 +79,7 @@ def build_package(
if provider.docker_image: if provider.docker_image:
raise ValueError("A stack's dependencies cannot have a docker image") raise ValueError("A stack's dependencies cannot have a docker image")
stub_config[api.value] = {"provider_id": api_input.provider} stub_config[api.value] = {"provider_type": api_input.provider}
if package_file.exists(): if package_file.exists():
cprint( cprint(
@ -92,7 +92,7 @@ def build_package(
c.providers[api_str] = new_config c.providers[api_str] = new_config
else: else:
existing_config = c.providers[api_str] existing_config = c.providers[api_str]
if existing_config["provider_id"] != new_config["provider_id"]: if existing_config["provider_type"] != new_config["provider_type"]:
cprint( cprint(
f"Provider `{api_str}` has changed from `{existing_config}` to `{new_config}`", f"Provider `{api_str}` has changed from `{existing_config}` to `{new_config}`",
color="yellow", color="yellow",
@ -105,7 +105,7 @@ def build_package(
providers=stub_config, providers=stub_config,
) )
c.distribution_id = distribution_id c.distribution_type = distribution_type
c.docker_image = package_name if build_type == BuildType.container else None c.docker_image = package_name if build_type == BuildType.container else None
c.conda_env = package_name if build_type == BuildType.conda_env else None c.conda_env = package_name if build_type == BuildType.conda_env else None
@ -119,7 +119,7 @@ def build_package(
) )
args = [ args = [
script, script,
distribution_id, distribution_type,
package_name, package_name,
package_deps.docker_image, package_deps.docker_image,
" ".join(package_deps.pip_packages), " ".join(package_deps.pip_packages),
@ -130,7 +130,7 @@ def build_package(
) )
args = [ args = [
script, script,
distribution_id, distribution_type,
package_name, package_name,
" ".join(package_deps.pip_packages), " ".join(package_deps.pip_packages),
] ]

View file

@ -284,13 +284,13 @@ def main(yaml_config: str, port: int = 5000, disable_ipv6: bool = False):
for api_str, provider_config in config["providers"].items(): for api_str, provider_config in config["providers"].items():
api = Api(api_str) api = Api(api_str)
providers = all_providers[api] providers = all_providers[api]
provider_id = provider_config["provider_id"] provider_type = provider_config["provider_type"]
if provider_id not in providers: if provider_type not in providers:
raise ValueError( raise ValueError(
f"Unknown provider `{provider_id}` is not available for API `{api}`" f"Unknown provider `{provider_type}` is not available for API `{api}`"
) )
provider_specs[api] = providers[provider_id] provider_specs[api] = providers[provider_type]
impls = resolve_impls(provider_specs, config) impls = resolve_impls(provider_specs, config)

View file

@ -13,7 +13,7 @@ def available_inference_providers() -> List[ProviderSpec]:
return [ return [
InlineProviderSpec( InlineProviderSpec(
api=Api.inference, api=Api.inference,
provider_id="meta-reference", provider_type="meta-reference",
pip_packages=[ pip_packages=[
"accelerate", "accelerate",
"blobfile", "blobfile",

View file

@ -18,7 +18,7 @@ def available_memory_providers() -> List[ProviderSpec]:
return [ return [
InlineProviderSpec( InlineProviderSpec(
api=Api.memory, api=Api.memory,
provider_id="meta-reference-faiss", provider_type="meta-reference-faiss",
pip_packages=EMBEDDING_DEPS + ["faiss-cpu"], pip_packages=EMBEDDING_DEPS + ["faiss-cpu"],
module="llama_toolchain.memory.meta_reference.faiss", module="llama_toolchain.memory.meta_reference.faiss",
config_class="llama_toolchain.memory.meta_reference.faiss.FaissImplConfig", config_class="llama_toolchain.memory.meta_reference.faiss.FaissImplConfig",

View file

@ -13,7 +13,7 @@ def available_safety_providers() -> List[ProviderSpec]:
return [ return [
InlineProviderSpec( InlineProviderSpec(
api=Api.safety, api=Api.safety,
provider_id="meta-reference", provider_type="meta-reference",
pip_packages=[ pip_packages=[
"accelerate", "accelerate",
"codeshield", "codeshield",