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 15:24:14 -06:00
committed by GitHub
parent 1f474187a7
commit e0087acfb4
2 changed files with 8 additions and 5 deletions
+4 -3
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 = [''];
}