chore: remove impl_getter function

We already have an impl at this point, no need to validate this again.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2025-11-21 12:03:06 +01:00
parent 95e9455335
commit 234eaf4709
No known key found for this signature in database

View file

@ -44,7 +44,7 @@ from llama_stack.core.request_headers import (
request_provider_data_context,
user_from_scope,
)
from llama_stack.core.server.fastapi_router_registry import build_router
from llama_stack.core.server.fastapi_router_registry import build_router, has_router
from llama_stack.core.server.routes import get_all_api_routes
from llama_stack.core.stack import (
Stack,
@ -465,29 +465,22 @@ def create_app() -> StackApp:
apis_to_serve.add("prompts")
apis_to_serve.add("conversations")
def impl_getter(api: Api) -> Any:
"""Get the implementation for a given API."""
try:
return impls[api]
except KeyError as e:
raise ValueError(f"Could not find provider implementation for {api} API") from e
for api_str in apis_to_serve:
api = Api(api_str)
# Try to discover and use a router factory from the API package
router = build_router(api, impl_getter)
if has_router(api):
impl = impls[api]
router = build_router(api, impl)
if router:
app.include_router(router)
logger.debug(f"Registered router for {api} API")
else:
# Fall back to old webmethod-based route discovery until the migration is complete
routes = all_routes[api]
try:
impl = impls[api]
except KeyError as e:
raise ValueError(f"Could not find provider implementation for {api} API") from e
continue
# Fall back to old webmethod-based route discovery until the migration is complete
impl = impls[api]
routes = all_routes[api]
for route, _ in routes:
if not hasattr(impl, route.name):
# ideally this should be a typing violation already