Handles model changes when current model unavailable

Improves model selection logic to automatically switch to the first available model when the current model is no longer valid

Adds fallback mechanism to prevent potential configuration errors
Logs model switching for debugging and transparency
This commit is contained in:
AlexKucera committed 2025-10-24 11:05:45 +02:00
1 parent 5c8314a986
commit de98d4a52d
1 file changed
+9 -2
+9 -2
View File
@@ -261,15 +261,22 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
if (this.modelDropdown) {
this.populateModelDropdown(this.modelDropdown);
// Restore selected model if it still exists
// Restore selected model if it still exists, otherwise use first available
const currentModel = this.plugin.settings.model;
const modelExists = this.availableModels.some(m => m.id === currentModel);
if (modelExists) {
this.modelDropdown.setValue(currentModel);
} else if (this.availableModels.length > 0) {
// Model no longer available - update to first available model
const newModel = this.availableModels[0].id;
this.plugin.settings.model = newModel;
this.modelDropdown.setValue(newModel);
console.log(`Model '${currentModel}' no longer available, switched to '${newModel}'`);
}
}
// Save updated cache
// Save updated cache and any model changes
await this.plugin.saveSettings();
} catch (error) {
console.error('Error refreshing models:', error);