mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-24 05:44:07 +00:00
fix: apply default model on fresh page load when models load after init
initNewChat() runs on mount via page.subscribe, but $models is loaded asynchronously and the Chat component mounts before that fetch resolves. When initNewChat() runs against an empty $models list, none of its precedence branches (URL/folder/session/settings/default) match and selectedModels is left as ['']. Nothing re-applies the default afterwards, so the configured default model (DEFAULT_MODELS / admin Models defaults) is never selected on a fresh full-page load — only via in-app New Chat once models have loaded. Add a guarded reactive statement that re-applies the default selection once models arrive, for a brand-new chat that still has no valid model selected. It reuses the same availableModels/defaultModels precedence as initNewChat and only fires when the selection is empty and there is no URL model param, so it never overrides a manual pick, a loaded chat, or a folder selection.
This commit is contained in:
parent
4b55e69640
commit
788a66e0ed
1 changed files with 30 additions and 0 deletions
|
|
@ -888,6 +888,36 @@
|
|||
savedModelIds();
|
||||
}
|
||||
|
||||
// initNewChat() runs on mount via page.subscribe, but $models is loaded
|
||||
// asynchronously (getModels() in the app layout) and this component mounts before
|
||||
// that resolves. So initNewChat() can run while $models is still empty, in which
|
||||
// case none of its precedence branches match and selectedModels is left as [''].
|
||||
// Nothing else re-applies the default afterwards, so the default model never gets
|
||||
// selected on a fresh page load. Re-apply the default once models arrive, for a
|
||||
// brand-new chat that still has no valid model selected.
|
||||
$: if (
|
||||
chatIdProp === '' &&
|
||||
$models.length > 0 &&
|
||||
selectedModels.length === 1 &&
|
||||
selectedModels[0] === '' &&
|
||||
!$page.url.searchParams.get('models') &&
|
||||
!$page.url.searchParams.get('model')
|
||||
) {
|
||||
const availableModels = $models
|
||||
.filter((m) => !(m?.info?.meta?.hidden ?? false))
|
||||
.map((m) => m.id);
|
||||
const defaultModels = $config?.default_models ? $config.default_models.split(',') : [];
|
||||
let next = ($settings?.models?.length ? $settings.models : defaultModels).filter((id) =>
|
||||
availableModels.includes(id)
|
||||
);
|
||||
if (next.length === 0 && availableModels.length > 0) {
|
||||
next = [availableModels[0]];
|
||||
}
|
||||
if (next.length > 0) {
|
||||
selectedModels = next;
|
||||
}
|
||||
}
|
||||
|
||||
const stopAudio = () => {
|
||||
try {
|
||||
speechSynthesis.cancel();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue