From e0087acfb49b1e273bff3bc02a6c69c2490c10e1 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 22 Feb 2026 22:24:14 +0100 Subject: [PATCH] fix: model fallback routing for all model types and default model selection (#21736) fix: model fallback routing for all model types and default model selection Backend: When ENABLE_CUSTOM_MODEL_FALLBACK is active and a custom model's base model is unavailable, the fallback now swaps the model and form data to the configured default model directly. This ensures routing uses the fallback model's type (pipe, Ollama, or OpenAI) instead of the original model's type, which previously caused "Model not found" errors when the fallback was a different backend type. Frontend: Fixed default model selection in new chat initialization where the admin-configured default models were always overwritten by the first available model. The first-available fallback now only triggers when the configured defaults don't resolve to valid available models. --- backend/open_webui/main.py | 6 ++++-- src/lib/components/chat/Chat.svelte | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 5136eb759..6b2df1b45 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1705,8 +1705,10 @@ async def chat_completion( default_models[0].strip() if default_models[0] else None ) - if fallback_model_id: - request.base_model_id = fallback_model_id + if fallback_model_id and fallback_model_id in request.app.state.MODELS: + # Update model and form_data so routing uses the fallback model's type + model = request.app.state.MODELS[fallback_model_id] + form_data["model"] = fallback_model_id else: raise Exception("Model not found") else: diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index deae018fa..526147ed4 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1031,12 +1031,13 @@ if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) { if (availableModels.length > 0) { if (defaultModels && defaultModels.length > 0) { - // Set from default models selectedModels = defaultModels.filter((modelId) => availableModels.includes(modelId)); } - // Set to first available model - selectedModels = [availableModels?.at(0) ?? '']; + if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) { + // Only fall back to first available model if default models didn't resolve + selectedModels = [availableModels?.at(0) ?? '']; + } } else { selectedModels = ['']; }