mirror of
https://github.com/yzh503/obsidian-aicommander-plugin.git
synced 2026-07-22 07:40:26 +00:00
Compare commits
No commits in common. "master" and "1.3.3" have entirely different histories.
3 changed files with 15 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "ai-commander",
|
||||
"name": "AI Commander",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.3",
|
||||
"minAppVersion": "1.0.0",
|
||||
"description": "Generate audio transcripts, images, and text in context of PDF attachments or web search results using OpenAI (ChatGPT) and Bing API.",
|
||||
"author": "Simon Yang",
|
||||
|
|
|
|||
33
src/main.ts
33
src/main.ts
|
|
@ -55,7 +55,7 @@ export default class AICommanderPlugin extends Plugin {
|
|||
};
|
||||
|
||||
const params = {
|
||||
url: 'https://api.promptperfect.jina.ai/optimize',
|
||||
url: 'https://us-central1-prompt-ops.cloudfunctions.net/optimize',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(data),
|
||||
|
|
@ -63,22 +63,12 @@ export default class AICommanderPlugin extends Plugin {
|
|||
'x-api-key': `token ${this.settings.promptPerfectKey}`,
|
||||
},
|
||||
};
|
||||
try {
|
||||
const response = await requestUrl(params);
|
||||
const responseJson = response.json;
|
||||
const errorMessage = responseJson?.error?.message || response.status;
|
||||
if ('promptOptimized' in responseJson) {
|
||||
return responseJson.promptOptimized as string;
|
||||
} else {
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
} catch(error) {
|
||||
if (error.message.includes('401')) {
|
||||
throw new Error('Prompt Perfect API Key is not valid.');
|
||||
} else {
|
||||
throw new Error('Prompt Perfect: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
const response = await requestUrl(params);
|
||||
|
||||
if ('promptOptimized' in response.json.result)
|
||||
return response.json.result.promptOptimized as string;
|
||||
else throw new Error('Prompt Perfect API: ' + JSON.stringify(response.json));
|
||||
}
|
||||
|
||||
async generateText(prompt: string, editor: Editor, currentLn: number, contextPrompt?: string) {
|
||||
|
|
@ -95,11 +85,14 @@ export default class AICommanderPlugin extends Plugin {
|
|||
|
||||
// Optionally improve the prompt
|
||||
if (this.settings.usePromptPerfect) {
|
||||
finalPrompt = await this.improvePrompt(prompt, this.settings.model);
|
||||
try {
|
||||
finalPrompt = await this.improvePrompt(prompt, 'chatgpt');
|
||||
} catch (error) {
|
||||
console.error('Prompt improvement failed:', error);
|
||||
// Proceed with the original prompt if improvement fails
|
||||
}
|
||||
}
|
||||
|
||||
console.log({finalPrompt})
|
||||
|
||||
const messages: any[] = [];
|
||||
|
||||
// Add context or search results if needed
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"1.3.4": "1.0.0"
|
||||
"1.3.3": "1.0.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue