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.
This commit is contained in:
Classic298
2026-02-22 22:24:14 +01:00
committed by GitHub
parent 1f474187a7
commit e0087acfb4
2 changed files with 8 additions and 5 deletions

View File

@@ -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:

View File

@@ -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 = [''];
}