Skip to content

Commit

Permalink
New version 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ittuann committed Apr 23, 2023
1 parent 106d512 commit f2bdcd3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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` 文件夹中即可。

Expand Down
36 changes: 25 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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();
}));
Expand All @@ -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();
Expand Down
38 changes: 27 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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')
Expand Down

0 comments on commit f2bdcd3

Please sign in to comment.