Skip to content

Commit

Permalink
refactor: handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
yonashailug committed Jan 26, 2023
1 parent fbb0cf9 commit 8a8e48a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 26 additions & 18 deletions src/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 8a8e48a

Please sign in to comment.