Skip to content

Commit

Permalink
Merge pull request #15 from iamshabell/update/rename-env_var
Browse files Browse the repository at this point in the history
Rename environment variable for OpenAI API key
  • Loading branch information
Nutlope authored Feb 14, 2023
2 parents 72fad13 + 4acdba1 commit 8e20232
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 4 additions & 4 deletions aicommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 8e20232

Please sign in to comment.