Skip to content

Commit

Permalink
chore: add command option for enter api key
Browse files Browse the repository at this point in the history
  • Loading branch information
yonashailug committed Jan 15, 2023
1 parent cea7a91 commit 4d45e6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 9 additions & 4 deletions src/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
{
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 4d45e6f

Please sign in to comment.