mirror of
https://github.com/ittuann/obsidian-gpt-liteinquirer-plugin.git
synced 2026-07-22 07:40:27 +00:00
New version 1.1.3
This commit is contained in:
parent
106d5128cc
commit
f2bdcd3807
4 changed files with 55 additions and 25 deletions
|
|
@ -52,7 +52,7 @@ If you enjoy this plugin or would like to show your support, please consider giv
|
|||
|
||||
## 🧩 Configuration
|
||||
|
||||
You need to **first** set your own OpenAI API key in the Plugin Settings , so that the plugin can work properly.
|
||||
You **MUST** need to set your own OpenAI API key in the Plugin Settings first, so that the plugin can work properly.
|
||||
|
||||
1. Generate an OpenAI API key on the official website. [Click here](https://beta.openai.com/account/api-keys)
|
||||
2. In Obsidian, go to `Settings`, click `Community Plugins` in the left menu , and enable `GPT-LiteInquirer` in the Installed Plugins.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
<div align="right">
|
||||
Language:
|
||||
<a title="English" href="https://github.com/ittuann/obsidian-gpt-liteinquirer-plugin">:gb: English</a> ·
|
||||
<a title="English" href="https://github.com/ittuann/obsidian-gpt-liteinquirer-plugin#readme">:gb: English</a> ·
|
||||
:cn: 简体中文</a>
|
||||
</div>
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ Language:
|
|||
|
||||
如果您喜欢这个插件或想要支持它,请考虑在 GitHub 上免费给它点个星~
|
||||
|
||||
**在 Obsidian 中自动安装和查看此插件**:[点击这里](https://obsidian.md/plugins?id=gpt-liteinquirer)\*\*
|
||||
**在 Obsidian 中自动安装和查看此插件:[点击这里](https://obsidian.md/plugins?id=gpt-liteinquirer)**
|
||||
|
||||
**手动安装:[点击这里](https://github.com/ittuann/obsidian-gpt-liteinquirer-plugin/releases/latest)**。您只需要手动下载 `main.js`、`styles.css` 和 `manifest.json`,然后将它们放在 `.obsidian\plugins\gpt-liteinquirer` 文件夹中即可。
|
||||
|
||||
|
|
|
|||
36
main.js
36
main.js
|
|
@ -259,12 +259,12 @@ ${this.plugin.settings.defaultPrompt}
|
|||
]
|
||||
})
|
||||
});
|
||||
const result = JSON.parse(response);
|
||||
if (result.choices && result.choices.length > 0) {
|
||||
const gptResponse = result.choices[0].message.content;
|
||||
const currentResult = JSON.parse(response);
|
||||
if (currentResult.choices && currentResult.choices.length > 0) {
|
||||
const gptResponse = currentResult.choices[0].message.content;
|
||||
return gptResponse;
|
||||
} else if (result.error) {
|
||||
throw new Error(JSON.stringify(result.error));
|
||||
} else if (currentResult.error) {
|
||||
throw new Error(JSON.stringify(currentResult.error));
|
||||
} else {
|
||||
throw new Error("Unexpected API response format");
|
||||
}
|
||||
|
|
@ -338,11 +338,21 @@ var LightweightChatGPTSettingTab = class extends import_obsidian.PluginSettingTa
|
|||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
containerEl.createEl("h2", { text: "Settings Lightweight ChatGPT Window" });
|
||||
new import_obsidian.Setting(containerEl).setName("API Key*").setDesc("Enter your OpenAI API key").addText((text) => text.setPlaceholder("Enter your API key").setValue(this.plugin.settings.apiKey).onChange(async (value) => {
|
||||
new import_obsidian.Setting(containerEl).setName("API Key*").setDesc(
|
||||
createFragment((frag) => {
|
||||
frag.appendText("Enter your OpenAI API key. ");
|
||||
frag.appendText("If you don't have it, you can ");
|
||||
frag.createEl("a", {
|
||||
href: "https://platform.openai.com/account/api-keys",
|
||||
text: "Click Here"
|
||||
});
|
||||
frag.appendText(" to apply.");
|
||||
})
|
||||
).addText((text) => text.setPlaceholder("Enter your API key").setValue(this.plugin.settings.apiKey).onChange(async (value) => {
|
||||
this.plugin.settings.apiKey = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
new import_obsidian.Setting(containerEl).setName("OpenAI Model").setDesc("Select the OpenAI model to use").addDropdown((dropDown) => dropDown.addOption("gpt-3.5-turbo", "gpt-3.5-turbo").setValue(this.plugin.settings.chatGPTModel).onChange(async (value) => {
|
||||
new import_obsidian.Setting(containerEl).setName("OpenAI Model").setDesc("Select the OpenAI model to use.").addDropdown((dropDown) => dropDown.addOption("gpt-3.5-turbo", "gpt-3.5-turbo").setValue(this.plugin.settings.chatGPTModel).onChange(async (value) => {
|
||||
this.plugin.settings.chatGPTModel = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
|
@ -365,18 +375,22 @@ var LightweightChatGPTSettingTab = class extends import_obsidian.PluginSettingTa
|
|||
this.plugin.settings.temperature = parsedValue;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
new import_obsidian.Setting(containerEl).setName("Default Max Tokens").setDesc("Enter the maximum number of tokens for the API response (integer, min: 1, max: 2048)").addText((text) => text.setPlaceholder("Enter max tokens").setValue(this.plugin.settings.maxTokens.toString()).onChange(async (value) => {
|
||||
new import_obsidian.Setting(containerEl).setName("Default Max Tokens").setDesc(this.plugin.settings.chatGPTModel === "gpt-4" ? "Enter the maximum number of tokens for the API response (integer, min: 1, max: 4096)" : "Enter the maximum number of tokens for the API response (integer, min: 1, max: 2048)").addText((text) => text.setPlaceholder("Enter max tokens").setValue(this.plugin.settings.maxTokens.toString()).onChange(async (value) => {
|
||||
let parsedValue = parseInt(value);
|
||||
let parsedMaxValue = 2048;
|
||||
if (this.plugin.settings.chatGPTModel === "gpt-4") {
|
||||
parsedMaxValue = 4096;
|
||||
}
|
||||
if (parsedValue < 1) {
|
||||
parsedValue = 1;
|
||||
} else if (parsedValue > 2048) {
|
||||
parsedValue = 2048;
|
||||
} else if (parsedValue > parsedMaxValue) {
|
||||
parsedValue = parsedMaxValue;
|
||||
}
|
||||
this.plugin.settings.maxTokens = parsedValue;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
new import_obsidian.Setting(containerEl).setName("Default Prompt").setDesc(
|
||||
"The Default Prompt filled in here will be automatically inserted into the requested Prompt."
|
||||
"Default Prompt will be automatically inserted into the requested Prompt. (Not necessary)"
|
||||
).addTextArea((text) => text.setPlaceholder("Enter Default Prompt").setValue(this.plugin.settings.defaultPrompt).onChange(async (value) => {
|
||||
this.plugin.settings.defaultPrompt = value;
|
||||
await this.plugin.saveSettings();
|
||||
|
|
|
|||
38
main.ts
38
main.ts
|
|
@ -320,12 +320,12 @@ class LightweightChatGPTWindow extends Modal {
|
|||
})
|
||||
});
|
||||
|
||||
const result = JSON.parse(response);
|
||||
if (result.choices && result.choices.length > 0) {
|
||||
const gptResponse = result.choices[0].message.content;
|
||||
const currentResult = JSON.parse(response);
|
||||
if (currentResult.choices && currentResult.choices.length > 0) {
|
||||
const gptResponse = currentResult.choices[0].message.content;
|
||||
return gptResponse;
|
||||
} else if (result.error) {
|
||||
throw new Error(JSON.stringify(result.error));
|
||||
} else if (currentResult.error) {
|
||||
throw new Error(JSON.stringify(currentResult.error));
|
||||
} else {
|
||||
throw new Error('Unexpected API response format');
|
||||
}
|
||||
|
|
@ -413,7 +413,17 @@ class LightweightChatGPTSettingTab extends PluginSettingTab {
|
|||
|
||||
new Setting(containerEl)
|
||||
.setName('API Key*')
|
||||
.setDesc('Enter your OpenAI API key')
|
||||
.setDesc(
|
||||
createFragment((frag) => {
|
||||
frag.appendText('Enter your OpenAI API key. ');
|
||||
frag.appendText('If you don\'t have it, you can ');
|
||||
frag.createEl('a', {
|
||||
href: 'https://platform.openai.com/account/api-keys',
|
||||
text: 'Click Here',
|
||||
});
|
||||
frag.appendText(' to apply.');
|
||||
}),
|
||||
)
|
||||
.addText(text => text
|
||||
.setPlaceholder('Enter your API key')
|
||||
.setValue(this.plugin.settings.apiKey)
|
||||
|
|
@ -424,7 +434,7 @@ class LightweightChatGPTSettingTab extends PluginSettingTab {
|
|||
|
||||
new Setting(containerEl)
|
||||
.setName('OpenAI Model')
|
||||
.setDesc('Select the OpenAI model to use')
|
||||
.setDesc('Select the OpenAI model to use.')
|
||||
.addDropdown(dropDown => dropDown
|
||||
.addOption('gpt-3.5-turbo', 'gpt-3.5-turbo')
|
||||
.setValue(this.plugin.settings.chatGPTModel)
|
||||
|
|
@ -476,16 +486,22 @@ class LightweightChatGPTSettingTab extends PluginSettingTab {
|
|||
|
||||
new Setting(containerEl)
|
||||
.setName('Default Max Tokens')
|
||||
.setDesc('Enter the maximum number of tokens for the API response (integer, min: 1, max: 2048)')
|
||||
.setDesc(this.plugin.settings.chatGPTModel === "gpt-4"
|
||||
? 'Enter the maximum number of tokens for the API response (integer, min: 1, max: 4096)'
|
||||
: 'Enter the maximum number of tokens for the API response (integer, min: 1, max: 2048)')
|
||||
.addText(text => text
|
||||
.setPlaceholder('Enter max tokens')
|
||||
.setValue(this.plugin.settings.maxTokens.toString())
|
||||
.onChange(async (value) => {
|
||||
let parsedValue = parseInt(value);
|
||||
let parsedMaxValue = 2048;
|
||||
if (this.plugin.settings.chatGPTModel === "gpt-4") {
|
||||
parsedMaxValue = 4096;
|
||||
}
|
||||
if (parsedValue < 1) {
|
||||
parsedValue = 1;
|
||||
} else if (parsedValue > 2048) {
|
||||
parsedValue = 2048;
|
||||
} else if (parsedValue > parsedMaxValue) {
|
||||
parsedValue = parsedMaxValue;
|
||||
}
|
||||
this.plugin.settings.maxTokens = parsedValue;
|
||||
await this.plugin.saveSettings();
|
||||
|
|
@ -494,7 +510,7 @@ class LightweightChatGPTSettingTab extends PluginSettingTab {
|
|||
new Setting(containerEl)
|
||||
.setName('Default Prompt')
|
||||
.setDesc(
|
||||
'The Default Prompt filled in here will be automatically inserted into the requested Prompt.'
|
||||
'Default Prompt will be automatically inserted into the requested Prompt. (Not necessary)'
|
||||
)
|
||||
.addTextArea(text => text
|
||||
.setPlaceholder('Enter Default Prompt')
|
||||
|
|
|
|||
Loading…
Reference in a new issue