Add prompt check for image generator

This commit is contained in:
Simon Yang 2023-03-14 15:50:43 +11:00
parent 47fb63f0f4
commit 8fda69740f

View file

@ -50,9 +50,7 @@ export default class AICommanderPlugin extends Plugin {
} }
async generateText(prompt: string, contextPrompt?: string) { async generateText(prompt: string, contextPrompt?: string) {
if (prompt.length < 1 ) throw new Error('Cannot find prompt.'); if (prompt.length < 1 ) throw new Error('Cannot find prompt.');
if (this.settings.apiKey.length <= 1) throw new Error('OpenAI API Key is not provided.'); if (this.settings.apiKey.length <= 1) throw new Error('OpenAI API Key is not provided.');
const configuration = new Configuration({ apiKey: this.settings.apiKey }); const configuration = new Configuration({ apiKey: this.settings.apiKey });
@ -124,6 +122,7 @@ export default class AICommanderPlugin extends Plugin {
} }
async generateImage(prompt: string) { async generateImage(prompt: string) {
if (prompt.length < 1 ) throw new Error('Cannot find prompt.');
if (this.settings.apiKey.length <= 1) throw new Error('OpenAI API Key is not provided.'); if (this.settings.apiKey.length <= 1) throw new Error('OpenAI API Key is not provided.');
const configuration = new Configuration({ const configuration = new Configuration({