Files

44 lines
1.5 KiB
Python

"""Routes for the bundled base-model catalog."""
import asyncio
from ..request_utils import read_bool_field
from ..sources.popular import (
get_base_models_config,
get_base_models_status,
update_base_models_from_remote,
)
def register_base_model_routes(routes, web, json_api_endpoint):
"""Register base-model catalog endpoints."""
@routes.get("/model_resolver/base-models")
@json_api_endpoint("base-models")
async def get_base_models(request):
"""Return the bundled base-model configuration."""
data = get_base_models_config()
return web.json_response(data)
@routes.get("/model_resolver/base-models/status")
@json_api_endpoint("base-models status")
async def get_base_models_status_route(request):
"""Get local and optional remote base-model status."""
try:
check_remote = read_bool_field(
request.query,
"check_remote",
contract_name="Base models status request",
)
except TypeError as exc:
return web.json_response({"error": str(exc)}, status=400)
status = await asyncio.to_thread(get_base_models_status, check_remote)
return web.json_response(status)
@routes.post("/model_resolver/base-models/update")
@json_api_endpoint("base-models update")
async def update_base_models_route(request):
"""Update the base-model list from CivitAI."""
status = await asyncio.to_thread(update_base_models_from_remote)
return web.json_response(status)