Merge pull request #15 from iamshabell/update/rename-env_var
Rename environment variable for OpenAI API key
This commit is contained in:
@@ -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.
|
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`
|
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.
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ import { execSync } from "child_process";
|
|||||||
import inquirer from "inquirer";
|
import inquirer from "inquirer";
|
||||||
import fetch from "node-fetch";
|
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() {
|
export async function main() {
|
||||||
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommits!"));
|
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommits!"));
|
||||||
|
|
||||||
if (!OPENAI_API_KEY) {
|
if (!OPENAI_KEY) {
|
||||||
console.error(
|
console.error(
|
||||||
chalk.white("▲ ") +
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ async function generateCommitMessage(prompt: string) {
|
|||||||
const response = await fetch("https://api.openai.com/v1/completions", {
|
const response = await fetch("https://api.openai.com/v1/completions", {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${OPENAI_API_KEY ?? ""}`,
|
Authorization: `Bearer ${OPENAI_KEY ?? ""}`,
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
|
|||||||
Reference in New Issue
Block a user