mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 09:53:45 +00:00
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:
parent
95e9455335
commit
234eaf4709
1 changed files with 31 additions and 38 deletions
|
|
@ -44,7 +44,7 @@ from llama_stack.core.request_headers import (
|
||||||
request_provider_data_context,
|
request_provider_data_context,
|
||||||
user_from_scope,
|
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.server.routes import get_all_api_routes
|
||||||
from llama_stack.core.stack import (
|
from llama_stack.core.stack import (
|
||||||
Stack,
|
Stack,
|
||||||
|
|
@ -465,29 +465,22 @@ def create_app() -> StackApp:
|
||||||
apis_to_serve.add("prompts")
|
apis_to_serve.add("prompts")
|
||||||
apis_to_serve.add("conversations")
|
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:
|
for api_str in apis_to_serve:
|
||||||
api = Api(api_str)
|
api = Api(api_str)
|
||||||
|
|
||||||
# Try to discover and use a router factory from the API package
|
# 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:
|
if router:
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
logger.debug(f"Registered router for {api} API")
|
logger.debug(f"Registered router for {api} API")
|
||||||
else:
|
continue
|
||||||
# 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
|
|
||||||
|
|
||||||
|
# Fall back to old webmethod-based route discovery until the migration is complete
|
||||||
|
impl = impls[api]
|
||||||
|
|
||||||
|
routes = all_routes[api]
|
||||||
for route, _ in routes:
|
for route, _ in routes:
|
||||||
if not hasattr(impl, route.name):
|
if not hasattr(impl, route.name):
|
||||||
# ideally this should be a typing violation already
|
# ideally this should be a typing violation already
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue