feat(ui): load provider model catalog asynchronously to avoid blocking page render

This commit is contained in:
Will Miao
2026-07-06 10:02:09 +08:00
parent e0e1b804a7
commit 2373edf73c
4 changed files with 56 additions and 5 deletions

View File

@@ -154,10 +154,13 @@ class ModelPageView:
)
self._template_env._i18n_filter_added = True # type: ignore[attr-defined]
from ...services.llm_service import PROVIDER_PRESETS, get_all_provider_models
from ...services.llm_service import PROVIDER_PRESETS
catalog_provider_ids = [p for p in PROVIDER_PRESETS if p != "custom"]
provider_models = await get_all_provider_models(catalog_provider_ids)
# Provider presets are embedded directly (local, no await needed).
# Provider model catalogs are fetched asynchronously by the
# frontend via GET /api/lm/llm/provider-models so page rendering
# never blocks on the remote model catalog (which can take up to
# 30s on cold cache).
template_context = {
"is_initializing": is_initializing,
@@ -167,7 +170,7 @@ class ModelPageView:
"t": self._server_i18n.get_translation,
"version": self._get_app_version(),
"provider_presets_json": json.dumps(PROVIDER_PRESETS),
"provider_models_json": json.dumps(provider_models),
"provider_models_json": "{}",
}
if not is_initializing: