feat: add Aktualisieren button to fetch models from API

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-03-27 21:24:17 +01:00
parent 989cdad514
commit 1736a74d10
+29 -4
View File
@@ -1,4 +1,4 @@
import { App, PluginSettingTab, Setting } from "obsidian"; import { App, ButtonComponent, DropdownComponent, Notice, PluginSettingTab, Setting } from "obsidian";
import type MemexChatPlugin from "./main"; import type MemexChatPlugin from "./main";
import { EMBEDDING_MODELS } from "./EmbedSearch"; import { EMBEDDING_MODELS } from "./EmbedSearch";
@@ -32,7 +32,7 @@ export interface MemexChatSettings {
export const DEFAULT_SETTINGS: MemexChatSettings = { export const DEFAULT_SETTINGS: MemexChatSettings = {
apiKey: "", apiKey: "",
model: "claude-opus-4-5-20251101", model: "claude-opus-4-6",
maxTokens: 8192, maxTokens: 8192,
maxContextNotes: 6, maxContextNotes: 6,
maxCharsPerNote: 2500, maxCharsPerNote: 2500,
@@ -70,8 +70,8 @@ Wenn du Fragen beantwortest:
}; };
export const MODELS = [ export const MODELS = [
{ id: "claude-opus-4-5-20251101", name: "Claude Opus 4.5 (Stärkste)" }, { id: "claude-opus-4-6", name: "Claude Opus 4.6 (Stärkste)" },
{ id: "claude-sonnet-4-5-20250929", name: "Claude Sonnet 4.5 (Empfohlen)" }, { id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6 (Empfohlen)" },
{ id: "claude-haiku-4-5-20251001", name: "Claude Haiku 4.5 (Schnell)" }, { id: "claude-haiku-4-5-20251001", name: "Claude Haiku 4.5 (Schnell)" },
]; ];
@@ -148,15 +148,40 @@ export class MemexChatSettingsTab extends PluginSettingTab {
}) })
); );
let modelDrop: DropdownComponent;
let refreshBtn: ButtonComponent;
new Setting(containerEl) new Setting(containerEl)
.setName("Modell") .setName("Modell")
.setDesc("Welches Claude-Modell verwenden?") .setDesc("Welches Claude-Modell verwenden?")
.addDropdown((drop) => { .addDropdown((drop) => {
modelDrop = drop;
for (const m of MODELS) drop.addOption(m.id, m.name); for (const m of MODELS) drop.addOption(m.id, m.name);
drop.setValue(this.plugin.settings.model).onChange(async (value) => { drop.setValue(this.plugin.settings.model).onChange(async (value) => {
this.plugin.settings.model = value; this.plugin.settings.model = value;
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); });
})
.addButton((btn) => {
refreshBtn = btn;
btn.setButtonText("Aktualisieren").onClick(async () => {
const prev = modelDrop.getValue();
refreshBtn.setDisabled(true);
refreshBtn.setButtonText("...");
try {
const models = await this.plugin.claude.fetchModels(this.plugin.settings.apiKey);
modelDrop.selectEl.empty();
for (const m of models) modelDrop.addOption(m.id, m.name);
modelDrop.setValue(prev);
this.plugin.settings.model = modelDrop.getValue();
await this.plugin.saveSettings();
} catch (err) {
new Notice("Modelle konnten nicht geladen werden: " + (err as Error).message);
} finally {
refreshBtn.setDisabled(false);
refreshBtn.setButtonText("Aktualisieren");
}
});
}); });
new Setting(containerEl) new Setting(containerEl)