provider_type -> provider_id ... less confusing

This commit is contained in:
Ashwin Bharambe 2024-09-16 12:09:53 -07:00
parent ce6c868499
commit 6f5d9a3df8
11 changed files with 25 additions and 33 deletions

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

View file

@ -32,7 +32,7 @@ class ApiEndpoint(BaseModel):
@json_schema_type
class ProviderSpec(BaseModel):
api: Api
provider_type: str
provider_id: str
config_class: str = Field(
...,
description="Fully-qualified classname of the config for this provider",
@ -101,7 +101,7 @@ class RemoteProviderConfig(BaseModel):
return url.rstrip("/")
def remote_provider_type(adapter_id: str) -> str:
def remote_provider_id(adapter_id: str) -> str:
return f"remote::{adapter_id}"
@ -142,10 +142,10 @@ def remote_provider_spec(
if adapter and adapter.config_class
else "llama_toolchain.core.datatypes.RemoteProviderConfig"
)
provider_type = remote_provider_type(adapter.adapter_id) if adapter else "remote"
provider_id = remote_provider_id(adapter.adapter_id) if adapter else "remote"
return RemoteProviderSpec(
api=api, provider_type=provider_type, config_class=config_class, adapter=adapter
api=api, provider_id=provider_id, config_class=config_class, adapter=adapter
)

View file

@ -14,14 +14,7 @@ from llama_toolchain.memory.api import Memory
from llama_toolchain.safety.api import Safety
from llama_toolchain.telemetry.api import Telemetry
from .datatypes import (
Api,
ApiEndpoint,
DistributionSpec,
InlineProviderSpec,
ProviderSpec,
remote_provider_spec,
)
from .datatypes import Api, ApiEndpoint, ProviderSpec, remote_provider_spec
# These are the dependencies needed by the distribution server.
# `llama-toolchain` is automatically installed by the installation script.
@ -77,7 +70,7 @@ def api_providers() -> Dict[Api, Dict[str, ProviderSpec]]:
module = importlib.import_module(f"llama_toolchain.{name}.providers")
ret[api] = {
"remote": remote_provider_spec(api),
**{a.provider_type: a for a in module.available_providers()},
**{a.provider_id: a for a in module.available_providers()},
}
return ret

View file

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