forked from jcollingj/caret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveCustomModel.ts
52 lines (42 loc) · 1.91 KB
/
removeCustomModel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { App, Modal } from "obsidian";
import { CustomModels } from "../types";
export class RemoveCustomModelModal extends Modal {
plugin: any;
constructor(app: App, plugin: any) {
super(app);
this.plugin = plugin;
}
onOpen() {
const { contentEl, modalEl } = this;
contentEl.empty();
contentEl.createEl("h2", { text: "Remove Custom Model", cls: "insert-file-header" });
// Set the width of the modal
modalEl.style.width = "800px"; // Adjust the width as needed
const table = contentEl.createEl("table", { cls: "custom-models-table" });
const headerRow = table.createEl("tr");
headerRow.createEl("th", { text: "Name" });
headerRow.createEl("th", { text: "Context Window" });
headerRow.createEl("th", { text: "URL" });
headerRow.createEl("th", { text: "Action" });
const custom_models: { [key: string]: CustomModels } = this.plugin.settings.custom_endpoints;
for (const [model_id, model] of Object.entries(custom_models)) {
const row = table.createEl("tr");
row.createEl("td", { text: model.name });
row.createEl("td", { text: model.context_window.toString() });
row.createEl("td", { text: model.endpoint });
const deleteButtonContainer = row.createEl("td", { cls: "delete-btn-container" });
const deleteButton = deleteButtonContainer.createEl("button", { text: "Delete", cls: "mod-warning" });
deleteButton.addEventListener("click", async () => {
delete custom_models[model_id];
await this.plugin.saveSettings();
this.onOpen(); // Refresh the modal to reflect changes
});
}
// Apply minimum width to contentEl
contentEl.style.minWidth = "600px";
}
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}