From 4d45e6f56df99b7d4e704947f2766bfec3223b4e Mon Sep 17 00:00:00 2001 From: Yonas G Date: Sun, 15 Jan 2023 14:04:19 -0800 Subject: [PATCH] chore: add command option for enter api key --- src/cli.js | 6 ++++++ src/questions.js | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cli.js b/src/cli.js index 71efadb..af9428d 100644 --- a/src/cli.js +++ b/src/cli.js @@ -37,4 +37,10 @@ yargs(process.argv) desc: 'The maximum number of tokens to generate in the completion.', alias: 's' }) + .option('enterApiKey', { + type: 'boolean', + default: false, + desc: 'Enable to prompt to enter a api key', + alias: 'k' + }) .parse() diff --git a/src/questions.js b/src/questions.js index a82a5e9..2e9deb0 100644 --- a/src/questions.js +++ b/src/questions.js @@ -7,16 +7,17 @@ import { Subject } from 'rxjs'; import { store, API_KEY } from './store.js' const prompts = new Subject() -const apiKeyExist = store.get(API_KEY) +let apiKeyNotExistOrExpire = !!store.get(API_KEY) const log = console.log const questions = [ { type: 'password', name: 'apiKey', - message: `Chatgpt's Api key not found. Please generate and enter your api-key. ${chalk.yellow(hyperlinker('Link'))} https://beta.openai.com/account/api-keys`, + message: `Need Chatgpt's Api key. Please enter your api-key. ${chalk.yellow(hyperlinker('Link to generate'))} https://beta.openai.com/account/api-keys`, + askAnswered: true, when () { - return !apiKeyExist + return !apiKeyNotExistOrExpire } }, { @@ -35,7 +36,11 @@ const confirm = { askAnswered: true, } -export function question ({ model, temperature, maxTokens }) { +export function question ({ model, temperature, maxTokens, enterApiKey }) { + + if (enterApiKey) { + apiKeyNotExistOrExpire = false + } inquirer.prompt(prompts).ui.process.subscribe({ next: async ({ name, answer }) => {