diff --git a/package-lock.json b/package-lock.json index 7fbd399..9d3b368 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@yonashailug/chatgpt-cli", - "version": "0.1.6", + "version": "0.2.1", "license": "MIT", "dependencies": { "chalk": "^5.2.0", diff --git a/src/questions.js b/src/questions.js index 2e9deb0..89788bd 100644 --- a/src/questions.js +++ b/src/questions.js @@ -58,24 +58,32 @@ export function question ({ model, temperature, maxTokens, enterApiKey }) { return store.set(API_KEY, answer) } - const configuration = new Configuration({ - apiKey: store.get(API_KEY) - }) - - const openai = new OpenAIApi(configuration) - - const { data } = await openai.createCompletion({ - model, - temperature, - prompt: answer, - max_tokens: maxTokens - }) - - data.choices.forEach(choice => { - log(`\n ${chalk.blue(choice.text.trim())} \n`) - }) - - prompts.next(confirm) + try { + + const configuration = new Configuration({ + apiKey: store.get(API_KEY) + }) + + const openai = new OpenAIApi(configuration) + + const { data } = await openai.createCompletion({ + model, + temperature, + prompt: answer, + max_tokens: maxTokens + }) + + data.choices.forEach(choice => { + log(`\n ${chalk.blue(choice.text.trim())} \n`) + }) + + prompts.next(confirm) + + } catch(error) { + log(`[Error: ${error?.message}]`) + prompts.complete() + process.exit(0) + } }, error: (error) => {