Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom_host setting #229

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Add custom host setting
---
# Smart Connections: AI-Powered Note Connections for Obsidian
Ever felt overwhelmed by a growing collection of notes in Obsidian, wondering how to uncover hidden connections and insights? Discover Smart Connections, an AI-powered plugin that transforms your note-taking experience and helps you tap into the full potential of your ideas.

Expand Down
12 changes: 9 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const crypto = require("crypto");

const DEFAULT_SETTINGS = {
api_key: "",
api_host: "https://api.openai.com",
chat_open: true,
file_exclusions: "",
folder_exclusions: "",
Expand Down Expand Up @@ -1090,7 +1091,7 @@ class SmartConnectionsPlugin extends Obsidian.Plugin {
};
// console.log(this.settings.api_key);
const reqParams = {
url: `https://api.openai.com/v1/embeddings`,
url: `${this.settings.api_host}/v1/embeddings`,
method: "POST",
body: JSON.stringify(usedParams),
headers: {
Expand Down Expand Up @@ -2513,6 +2514,11 @@ class SmartConnectionsSettingsTab extends Obsidian.PluginSettingTab {
this.plugin.settings.api_key = value.trim();
await this.plugin.saveSettings(true);
}));
// add custom host
new Obsidian.Setting(containerEl).setName("custom_host").setDesc("custom_host").addText((text) => text.setPlaceholder("Enter your custom_host").setValue(this.plugin.settings.api_host).onChange(async (value) => {
this.plugin.settings.api_host = 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
Expand Down Expand Up @@ -3210,7 +3216,7 @@ class SmartConnectionsChatView extends Obsidian.ItemView {
const full_str = await new Promise((resolve, reject) => {
try {
// console.log("stream", opts);
const url = "https://api.openai.com/v1/chat/completions";
const url = `${this.settings.api_host}/v1/chat/completions`;
this.active_stream = new ScStreamer(url, {
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -3264,7 +3270,7 @@ class SmartConnectionsChatView extends Obsidian.ItemView {
}else{
try{
const response = await (0, Obsidian.requestUrl)({
url: `https://api.openai.com/v1/chat/completions`,
url: `${this.settings.api_host}/v1/chat/completions`,
method: "POST",
headers: {
Authorization: `Bearer ${this.plugin.settings.api_key}`,
Expand Down