chore: clarify function and log about which router

It's FastAPI

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2025-11-25 10:51:52 +01:00
parent 3770963130
commit 9a2b4efabd
No known key found for this signature in database
5 changed files with 11 additions and 11 deletions

View file

@ -14,7 +14,7 @@ from typing import Any
from fastapi import FastAPI from fastapi import FastAPI
from llama_stack.core.resolver import api_protocol_map from llama_stack.core.resolver import api_protocol_map
from llama_stack.core.server.fastapi_router_registry import build_router from llama_stack.core.server.fastapi_router_registry import build_fastapi_router
from llama_stack_api import Api from llama_stack_api import Api
from .state import _protocol_methods_cache from .state import _protocol_methods_cache
@ -81,7 +81,7 @@ def create_llama_stack_app() -> FastAPI:
protocols = api_protocol_map() protocols = api_protocol_map()
for api in protocols.keys(): for api in protocols.keys():
# For OpenAPI generation, we don't need a real implementation # For OpenAPI generation, we don't need a real implementation
router = build_router(api, None) router = build_fastapi_router(api, None)
if router: if router:
app.include_router(router) app.include_router(router)
@ -95,7 +95,7 @@ def create_llama_stack_app() -> FastAPI:
for api, routes in api_routes.items(): for api, routes in api_routes.items():
# Skip APIs that have routers - they're already included above # Skip APIs that have routers - they're already included above
if build_router(api, None) is not None: if build_fastapi_router(api, None) is not None:
continue continue
for route, webmethod in routes: for route, webmethod in routes:

View file

@ -10,7 +10,7 @@ from pydantic import BaseModel
from llama_stack.core.datatypes import StackRunConfig from llama_stack.core.datatypes import StackRunConfig
from llama_stack.core.external import load_external_apis from llama_stack.core.external import load_external_apis
from llama_stack.core.server.fastapi_router_registry import build_router from llama_stack.core.server.fastapi_router_registry import build_fastapi_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_api import ( from llama_stack_api import (
Api, Api,
@ -70,7 +70,7 @@ class DistributionInspectImpl(Inspect):
# Process webmethod-based routes (legacy) # Process webmethod-based routes (legacy)
for api, endpoints in all_endpoints.items(): for api, endpoints in all_endpoints.items():
# Skip APIs that have routers - they'll be processed separately # Skip APIs that have routers - they'll be processed separately
if build_router(api, None) is not None: if build_fastapi_router(api, None) is not None:
continue continue
provider_types = get_provider_types(api) provider_types = get_provider_types(api)
@ -114,7 +114,7 @@ class DistributionInspectImpl(Inspect):
protocols = api_protocol_map(external_apis) protocols = api_protocol_map(external_apis)
for api in protocols.keys(): for api in protocols.keys():
# For route inspection, we don't need a real implementation # For route inspection, we don't need a real implementation
router = build_router(api, None) router = build_fastapi_router(api, None)
if not router: if not router:
continue continue

View file

@ -26,7 +26,7 @@ _ROUTER_FACTORIES: dict[str, Any] = {
} }
def build_router(api: "Api", impl: Any) -> APIRouter | None: def build_fastapi_router(api: "Api", impl: Any) -> APIRouter | None:
"""Build a router for an API by combining its router factory with the implementation. """Build a router for an API by combining its router factory with the implementation.
Args: Args:

View file

@ -30,7 +30,7 @@ def get_all_api_routes(
This function only returns routes from APIs that use the legacy @webmethod This function only returns routes from APIs that use the legacy @webmethod
decorator system. For APIs that have been migrated to FastAPI routers, decorator system. For APIs that have been migrated to FastAPI routers,
use the router registry (fastapi_router_registry.has_router() and fastapi_router_registry.build_router()). use the router registry (fastapi_router_registry.has_router() and fastapi_router_registry.build_fastapi_router()).
Args: Args:
external_apis: Optional dictionary of external API specifications external_apis: Optional dictionary of external API specifications

View file

@ -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_fastapi_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,
@ -470,10 +470,10 @@ def create_app() -> StackApp:
# Try to discover and use a router factory from the API package # Try to discover and use a router factory from the API package
impl = impls[api] impl = impls[api]
router = build_router(api, impl) router = build_fastapi_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 FastAPIrouter for {api} API")
continue continue
# Fall back to old webmethod-based route discovery until the migration is complete # Fall back to old webmethod-based route discovery until the migration is complete