mirror of
https://github.com/yzh503/obsidian-aicommander-plugin.git
synced 2026-07-22 07:40:26 +00:00
Fix prompt perfect
This commit is contained in:
parent
330ce44d20
commit
60c3f51d2c
1 changed files with 20 additions and 13 deletions
33
src/main.ts
33
src/main.ts
|
|
@ -55,7 +55,7 @@ export default class AICommanderPlugin extends Plugin {
|
||||||
};
|
};
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
url: 'https://us-central1-prompt-ops.cloudfunctions.net/optimize',
|
url: 'https://api.promptperfect.jina.ai/optimize',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
|
|
@ -63,12 +63,22 @@ export default class AICommanderPlugin extends Plugin {
|
||||||
'x-api-key': `token ${this.settings.promptPerfectKey}`,
|
'x-api-key': `token ${this.settings.promptPerfectKey}`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
const response = await requestUrl(params);
|
const response = await requestUrl(params);
|
||||||
|
const responseJson = response.json;
|
||||||
if ('promptOptimized' in response.json.result)
|
const errorMessage = responseJson?.error?.message || response.status;
|
||||||
return response.json.result.promptOptimized as string;
|
if ('promptOptimized' in responseJson) {
|
||||||
else throw new Error('Prompt Perfect API: ' + JSON.stringify(response.json));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateText(prompt: string, editor: Editor, currentLn: number, contextPrompt?: string) {
|
async generateText(prompt: string, editor: Editor, currentLn: number, contextPrompt?: string) {
|
||||||
|
|
@ -85,14 +95,11 @@ export default class AICommanderPlugin extends Plugin {
|
||||||
|
|
||||||
// Optionally improve the prompt
|
// Optionally improve the prompt
|
||||||
if (this.settings.usePromptPerfect) {
|
if (this.settings.usePromptPerfect) {
|
||||||
try {
|
finalPrompt = await this.improvePrompt(prompt, this.settings.model);
|
||||||
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[] = [];
|
const messages: any[] = [];
|
||||||
|
|
||||||
// Add context or search results if needed
|
// Add context or search results if needed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue