Skip to content

Commit

Permalink
test api key button in settings #13
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpetro committed Jan 15, 2023
1 parent f9ed81f commit caed7dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ class SmartConnectionsPlugin extends Obsidian.Plugin {
return null;
}
}
async test_api_key() {
const embed_input = "This is a test of the OpenAI API.";
const resp = await this.request_embedding_from_input(embed_input);
if(resp && resp.usage) {
console.log("API key is valid");
return true;
}else{
console.log("API key is invalid");
return false;
}
}

find_nearest_embedding(input_vector, current_note=null) {
let nearest = [];
Expand Down Expand Up @@ -1159,9 +1170,19 @@ class SmartConnectionsSettingsTab extends Obsidian.PluginSettingTab {
text: "OpenAI Settings"
});
new Obsidian.Setting(containerEl).setName("api_key").setDesc("api_key").addText((text) => text.setPlaceholder("Enter your api_key").setValue(this.plugin.settings.api_key).onChange(async (value) => {
this.plugin.settings.api_key = value;
this.plugin.settings.api_key = value.trim();
await this.plugin.saveSettings(true);
}));
// add a button to test the API key is working
new Obsidian.Setting(containerEl).setName("Test API Key").setDesc("Test API Key").addButton((button) => button.setButtonText("Test API Key").onClick(async () => {
// test API key
const resp = await this.plugin.test_api_key();
if(resp) {
new Obsidian.Notice("API key is valid");
}else{
new Obsidian.Notice("API key is not working as expected!");
}
}));
containerEl.createEl("h2", {
text: "Exclusions"
});
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Smart Connections",
"author": "Brian Petro",
"description": "Find links to similar notes using artificial intelligence from OpenAI.",
"version": "1.0.45",
"version": "1.0.46",
"minAppVersion": "1.1.0",
"authorUrl": "https://wfhbrian.com",
"isDesktopOnly": true
Expand Down

0 comments on commit caed7dc

Please sign in to comment.