mirror of
https://github.com/aidantilgner/AutogenObsidianPlugin.git
synced 2026-07-22 09:20:32 +00:00
Merge pull request #2 from stereoplegic/feat/custom-urls
✨ feat: add custom URL
This commit is contained in:
commit
37a8bfa9ab
2 changed files with 22 additions and 2 deletions
21
main.ts
21
main.ts
|
|
@ -17,6 +17,7 @@ import { getClient, getGeneration } from "utils/openai";
|
|||
|
||||
interface AutogenSettings {
|
||||
openaiApiKey: string;
|
||||
customURL?: string;
|
||||
model: ChatCompletionCreateParamsBase["model"];
|
||||
triggerRegex: string;
|
||||
windowSize: number;
|
||||
|
|
@ -25,6 +26,7 @@ interface AutogenSettings {
|
|||
|
||||
const DEFAULT_SETTINGS: AutogenSettings = {
|
||||
openaiApiKey: "",
|
||||
customURL,
|
||||
model: "gpt-3.5-turbo",
|
||||
triggerRegex: "@\\[(.*?)\\]",
|
||||
windowSize: 8000,
|
||||
|
|
@ -59,7 +61,11 @@ export default class Autogen extends Plugin {
|
|||
|
||||
initOpenAIClient() {
|
||||
if (this.settings.openaiApiKey) {
|
||||
this.openaiClient = getClient(this.settings.openaiApiKey);
|
||||
if (this.settings.customURL) {
|
||||
this.openaiClient = getClient(this.settings.openaiApiKey, this.settings.customURL);
|
||||
} else {
|
||||
this.openaiClient = getClient(this.settings.openaiApiKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -330,6 +336,19 @@ class AutogenSettingTab extends PluginSettingTab {
|
|||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Custom URL")
|
||||
.setDesc("Set a custom URL (e.g. for proxy or local models with OpenAI-compatible API)")
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("Custom URL (leave blank for OpenAI default)")
|
||||
.setValue(this.plugin.settings.customURL)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.customURL = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Model")
|
||||
.setDesc("The model to use for generating text")
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import OpenAI from "openai";
|
||||
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
|
||||
|
||||
export const getClient = (apiKey: string) => {
|
||||
export const getClient = (apiKey: string, customURL?: string) => {
|
||||
return new OpenAI({
|
||||
apiKey,
|
||||
customURL,
|
||||
dangerouslyAllowBrowser: true,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue