diff --git a/README.md b/README.md index f6bade1..e3c96ae 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Install the CLI then grab your [OpenAI key](https://openai.com/api/) and add it as an env variable with the two commands below. 1. `npm install -g aicommits` -2. `export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxx` +2. `export OPENAI_KEY=sk-xxxxxxxxxxxxxxxx` It's recommended to add the line in #2 to your `.zshrc` or `.bashrc` so it persists instead of having to define it in each terminal session. diff --git a/aicommits.ts b/aicommits.ts index c57dc83..5fb8639 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -5,15 +5,15 @@ import { execSync } from "child_process"; import inquirer from "inquirer"; import fetch from "node-fetch"; -let OPENAI_API_KEY = process.env.OPENAI_API_KEY; +let OPENAI_KEY = process.env.OPENAI_KEY ?? process.env.OPENAI_API_KEY; export async function main() { console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommits!")); - if (!OPENAI_API_KEY) { + if (!OPENAI_KEY) { console.error( chalk.white("▲ ") + - "Please save your OpenAI API key as an env variable by doing 'export OPENAI_API_KEY=YOUR_API_KEY'" + "Please save your OpenAI API key as an env variable by doing 'export OPENAI_KEY=YOUR_API_KEY'" ); process.exit(1); } @@ -102,7 +102,7 @@ async function generateCommitMessage(prompt: string) { const response = await fetch("https://api.openai.com/v1/completions", { headers: { "Content-Type": "application/json", - Authorization: `Bearer ${OPENAI_API_KEY ?? ""}`, + Authorization: `Bearer ${OPENAI_KEY ?? ""}`, }, method: "POST", body: JSON.stringify(payload),