mirror of
https://github.com/ahmetildirim/obsidian-inscribe.git
synced 2026-07-22 05:44:10 +00:00
Update provider settings to include connection testing and adjust default enabled state
This commit is contained in:
parent
5deeef0c90
commit
1470724be3
5 changed files with 145 additions and 48 deletions
79
main.js
79
main.js
File diff suppressed because one or more lines are too long
|
|
@ -36,8 +36,8 @@ export class ProviderSettingsModal extends Modal {
|
|||
|
||||
async renderOllamaSettings() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
this.setTitle('Ollama Settings');
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName("Ollama Host")
|
||||
.setDesc("The host of the Ollama API")
|
||||
|
|
@ -49,10 +49,27 @@ export class ProviderSettingsModal extends Modal {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(contentEl)
|
||||
.setHeading()
|
||||
.setName(`Status: ${this.plugin.settings.providers.ollama.configured ? 'Successful' : 'Failed'}`)
|
||||
.addButton(button => {
|
||||
button
|
||||
.setButtonText(`Test Connection`)
|
||||
.onClick(async () => {
|
||||
this.plugin.settings.providers.ollama.configured = await this.plugin.providerFactory.testConnection(ProviderType.OLLAMA);
|
||||
await this.plugin.saveSettings();
|
||||
new Notice(this.plugin.settings.providers.ollama.configured
|
||||
? 'Successfully connected to Ollama'
|
||||
: 'Failed to connect to Ollama');
|
||||
this.renderOllamaSettings();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async renderOpenAISettings() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
this.setTitle('OpenAI Settings');
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -66,10 +83,27 @@ export class ProviderSettingsModal extends Modal {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(contentEl)
|
||||
.setHeading()
|
||||
.setName(`Status: ${this.plugin.settings.providers.openai.configured ? 'Successful' : 'Failed'}`)
|
||||
.addButton(button => {
|
||||
button
|
||||
.setButtonText(`Test Connection`)
|
||||
.onClick(async () => {
|
||||
this.plugin.settings.providers.openai.configured = await this.plugin.providerFactory.testConnection(ProviderType.OPENAI);
|
||||
await this.plugin.saveSettings();
|
||||
new Notice(this.plugin.settings.providers.openai.configured
|
||||
? 'Successfully connected to OpenAI'
|
||||
: 'Failed to connect to OpenAI');
|
||||
this.renderOpenAISettings();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async renderOpenAICompatibleSettings() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
this.setTitle('OpenAI Compatible Provider Settings');
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -95,10 +129,30 @@ export class ProviderSettingsModal extends Modal {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(contentEl)
|
||||
.setHeading()
|
||||
.setName(`Status: ${this.plugin.settings.providers.openai_compatible.configured ? 'Successful' : 'Failed'}`)
|
||||
.addButton(button => {
|
||||
button
|
||||
.setButtonText(`Test Connection`)
|
||||
.onClick(async () => {
|
||||
this.plugin.settings.providers.openai_compatible.configured = await this.plugin.providerFactory.testConnection(ProviderType.OPENAI_COMPATIBLE);
|
||||
await this.plugin.saveSettings();
|
||||
new Notice(this.plugin.settings.providers.openai_compatible.configured
|
||||
? 'Successfully connected to OpenAI Compatible Provider'
|
||||
: 'Failed to connect to OpenAI Compatible Provider');
|
||||
this.renderOpenAICompatibleSettings();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
|
||||
const setting = (this.plugin.app as any).setting;
|
||||
setting.open();
|
||||
setting.openTabById(this.plugin.manifest.id);
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ export interface Settings {
|
|||
export const DEFAULT_PROFILE: ProfileId = "default";
|
||||
export const DEFAULT_PATH = "/";
|
||||
export const DEFAULT_SETTINGS: Settings = {
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
providers: {
|
||||
openai: {
|
||||
integration: ProviderType.OPENAI,
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class GeneralSection {
|
|||
|
||||
async render(): Promise<void> {
|
||||
this.container.empty();
|
||||
this.container.createEl("h3", { text: "General" });
|
||||
this.container.createEl("h2", { text: "General" });
|
||||
this.container.createEl("p", {
|
||||
text: "Configure general settings for Inscribe"
|
||||
});
|
||||
|
|
@ -97,7 +97,7 @@ class ProvidersSection {
|
|||
|
||||
async render(): Promise<void> {
|
||||
this.container.empty();
|
||||
this.container.createEl("h3", { text: "Providers" });
|
||||
this.container.createEl("h2", { text: "Providers" });
|
||||
this.container.createEl("p", {
|
||||
text: "Configure the AI providers you want to use for completions"
|
||||
});
|
||||
|
|
@ -106,38 +106,40 @@ class ProvidersSection {
|
|||
new Setting(this.container)
|
||||
.setName("Ollama")
|
||||
.setDesc("Local AI provider running on your machine")
|
||||
.addButton((button: ButtonComponent) => {
|
||||
button
|
||||
.setButtonText("Configure")
|
||||
.setTooltip("Configure Ollama")
|
||||
.onClick(() => this.openProviderModal(ProviderType.OLLAMA));
|
||||
});
|
||||
.addButton((button: ButtonComponent) => this.createConfigureButton(
|
||||
button,
|
||||
ProviderType.OLLAMA,
|
||||
this.plugin.settings.providers.ollama.configured));
|
||||
|
||||
// OpenAI Provider
|
||||
new Setting(this.container)
|
||||
.setName("OpenAI")
|
||||
.setDesc("OpenAI API provider")
|
||||
.addButton((button: ButtonComponent) => {
|
||||
button
|
||||
.setButtonText("Configure")
|
||||
.setTooltip("Configure OpenAI")
|
||||
.onClick(() => this.openProviderModal(ProviderType.OPENAI));
|
||||
});
|
||||
.setDesc("OpenAI API")
|
||||
.addButton((button: ButtonComponent) => this.createConfigureButton(
|
||||
button,
|
||||
ProviderType.OPENAI,
|
||||
this.plugin.settings.providers.openai.configured));
|
||||
|
||||
// OpenAI Compatible Provider
|
||||
new Setting(this.container)
|
||||
.setName("OpenAI Compatible")
|
||||
.setDesc("OpenAI compatible provider")
|
||||
.addButton((button: ButtonComponent) => {
|
||||
button
|
||||
.setButtonText("Configure")
|
||||
.setTooltip("Configure OpenAI Compatible")
|
||||
.onClick(() => this.openProviderModal(ProviderType.OPENAI_COMPATIBLE));
|
||||
});
|
||||
.addButton((button: ButtonComponent) => this.createConfigureButton(
|
||||
button,
|
||||
ProviderType.OPENAI_COMPATIBLE,
|
||||
this.plugin.settings.providers.openai_compatible.configured));
|
||||
}
|
||||
|
||||
private openProviderModal(type: ProviderType): void {
|
||||
new ProviderSettingsModal(this.app, this.plugin, type).open();
|
||||
private createConfigureButton(button: ButtonComponent, type: ProviderType, configured: boolean): void {
|
||||
button.buttonEl.setCssStyles({
|
||||
color: configured ? "var(--text-success)" : "var(--text-warning)",
|
||||
});
|
||||
button
|
||||
.setIcon(configured ? "circle-check" : "circle-alert")
|
||||
.setTooltip(configured ? "Provider configured" : "Provider not configured")
|
||||
.onClick(() => {
|
||||
new ProviderSettingsModal(this.app, this.plugin, type).open()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +169,7 @@ class ProfilesSection {
|
|||
async render(): Promise<void> {
|
||||
// Clear main container and re-append sub-containers
|
||||
this.container.empty();
|
||||
this.container.createEl("h3", { text: "Profiles" });
|
||||
this.container.createEl("h2", { text: "Profiles" });
|
||||
this.container.createEl("p", {
|
||||
text: "Configure the settings for each profile. A profile can be assigned to paths. The default profile is used when no profile is assigned."
|
||||
});
|
||||
|
|
@ -357,7 +359,7 @@ class ProfilesSection {
|
|||
// User Prompt
|
||||
new Setting(this.profileContainer)
|
||||
.setName("User Prompt")
|
||||
.setDesc("User prompt template")
|
||||
.setDesc("User prompt template.")
|
||||
.addExtraButton((button) => {
|
||||
button
|
||||
.setIcon("list")
|
||||
|
|
@ -405,7 +407,7 @@ class PathConfigsSection {
|
|||
|
||||
async render(): Promise<void> {
|
||||
this.container.empty();
|
||||
this.container.createEl("h3", { text: "Path Configs" });
|
||||
this.container.createEl("h2", { text: "Path Configs" });
|
||||
this.container.createEl("p", {
|
||||
text: "You can assign profiles to paths. Paths are matched by prefix, with longer paths taking precedence. For example, '/Daily' will match all files in the Daily folder."
|
||||
});
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export default class StatusBarItem {
|
|||
.onClick(() => {
|
||||
const setting = (this.plugin.app as any).setting;
|
||||
setting.open();
|
||||
setting.openTabById("obsidian-inscribe");
|
||||
setting.openTabById(this.plugin.manifest.id);
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue