The API call to /api/models can take a long time. the ui waits until the api call promise is resolved before continuing any other ui state change or conducting any other api call. user sees a blank screen until the request has completed. This PR allows for the models list api call to run without blocking the UI.
This delay can become large if there are many model api urls, or if the servers are offline/are responding slowly.
Changed
set models store asynchronously to prevent UI blocking
src/lib/components/chat/Chat.svelte onMount subscribes to models and runs the initNewChat function when models changes, ensuring the UI is hydrated with the new data.
Additional Information
tested by adding an artificial delay to the endpoint /api/models in backend/open_webui/main.py:
when the api call is done without blocking, the user gets a quick load, and is able to interact with the ui while the request completes in the background.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/12667
**Author:** [@thearyadev](https://github.com/thearyadev)
**Created:** 4/9/2025
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `async-model-list`
---
### 📝 Commits (2)
- [`9f228d2`](https://github.com/open-webui/open-webui/commit/9f228d2c81a166c37894bf942fa02a1283fa1960) fix: prevent model list api call from blocking ui
- [`df274e3`](https://github.com/open-webui/open-webui/commit/df274e35340b6a4b1c7aa61445c4564258cae98c) fix: refactor models.subscribe use
### 📊 Changes
**2 files changed** (+28 additions, -6 deletions)
<details>
<summary>View changed files</summary>
📝 `src/lib/components/chat/Chat.svelte` (+22 -0)
📝 `src/routes/(app)/+layout.svelte` (+6 -6)
</details>
### 📄 Description
# Changelog Entry
### Description
The API call to `/api/models` can take a long time. the ui waits until the api call promise is resolved before continuing any other ui state change or conducting any other api call. user sees a blank screen until the request has completed. This PR allows for the models list api call to run without blocking the UI.
This delay can become large if there are many model api urls, or if the servers are offline/are responding slowly.
### Changed
- set `models` store asynchronously to prevent UI blocking
- `src/lib/components/chat/Chat.svelte` onMount subscribes to `models` and runs the `initNewChat` function when `models` changes, ensuring the UI is hydrated with the new data.
---
### Additional Information
tested by adding an artificial delay to the endpoint `/api/models` in `backend/open_webui/main.py`:
```python
@app.get("/api/models")
async def get_models(request: Request, user=Depends(get_verified_user)):
import asyncio
await asyncio.sleep(10)
...
```
#### before:
this video demonstrates the blank UI while the call to `/api/models` completes
https://github.com/user-attachments/assets/a26ad416-38c0-4606-91b9-5108185b1bd3
#### after:
when the api call is done without blocking, the user gets a quick load, and is able to interact with the ui while the request completes in the background.
https://github.com/user-attachments/assets/1b03d5df-4593-4ba1-81e8-b0e33f0e942f
#### user navigates during model load functions as intended.
the initNewChat function is not called if the user navigates. The model list is still refreshed once it becomes available.
https://github.com/user-attachments/assets/b509e839-bd7a-44a8-9b78-86dbd2885367
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/12667
Author: @thearyadev
Created: 4/9/2025
Status: ❌ Closed
Base:
dev← Head:async-model-list📝 Commits (2)
9f228d2fix: prevent model list api call from blocking uidf274e3fix: refactor models.subscribe use📊 Changes
2 files changed (+28 additions, -6 deletions)
View changed files
📝
src/lib/components/chat/Chat.svelte(+22 -0)📝
src/routes/(app)/+layout.svelte(+6 -6)📄 Description
Changelog Entry
Description
The API call to
/api/modelscan take a long time. the ui waits until the api call promise is resolved before continuing any other ui state change or conducting any other api call. user sees a blank screen until the request has completed. This PR allows for the models list api call to run without blocking the UI.This delay can become large if there are many model api urls, or if the servers are offline/are responding slowly.
Changed
modelsstore asynchronously to prevent UI blockingsrc/lib/components/chat/Chat.svelteonMount subscribes tomodelsand runs theinitNewChatfunction whenmodelschanges, ensuring the UI is hydrated with the new data.Additional Information
tested by adding an artificial delay to the endpoint
/api/modelsinbackend/open_webui/main.py:before:
this video demonstrates the blank UI while the call to
/api/modelscompleteshttps://github.com/user-attachments/assets/a26ad416-38c0-4606-91b9-5108185b1bd3
after:
when the api call is done without blocking, the user gets a quick load, and is able to interact with the ui while the request completes in the background.
https://github.com/user-attachments/assets/1b03d5df-4593-4ba1-81e8-b0e33f0e942f
user navigates during model load functions as intended.
the initNewChat function is not called if the user navigates. The model list is still refreshed once it becomes available.
https://github.com/user-attachments/assets/b509e839-bd7a-44a8-9b78-86dbd2885367
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.