def build_factory_api_endpoint(
    path: str, endpoint: Callable[..., Any]
) -> Callable[..., Awaitable[Any]]:
    """Build a factory endpoint for API routes.

    Args:
        path: The path for the route.
        endpoint: openai resource factory function.
    """
    resource = compile_openai_resource_factory(endpoint)

    # index 1 of `compile_path` contains path_format output
    model_prefix = compile_model_prefix(compile_path(path)[1], resource)
    request_model = create_request_model(resource, model_prefix)

    async def factory_endpoint(
        request: request_model, resource: OpenAIResource = Depends(endpoint)
    ):
        return StreamingResponse(resource=resource, **model_dump(request))

    return factory_endpoint
Build a factory endpoint for API routes.

    Args:
        path: The path for the route.
        endpoint: openai resource factory function.
    
lanarky/adapters/openai/utils.py