Nutlope / aicommits

A CLI that writes your git commit messages for you with AI
https://www.npmjs.com/package/aicommits
MIT License
7.53k stars 360 forks source link

aicommits uses first the envVar instead of the env in .aicommits file #244

Open kud opened 10 months ago

kud commented 10 months ago

Bug description

Imagine you've already defined an envVar called OPENAI_KEY, it will use it instead of the one defined in .aicommits. It's confusing. I would like to use the one in .aicommits.

aicommits version

1.11.0

Environment

OS: macOS 13.5
Shell: zsh 5.9 (arm-apple-darwin21.3.0)
node: v20.5.1

Can you contribute a fix?

ajoliveau commented 7 months ago

I can add some more information, I kept getting a reponse like this :

{
    "error": {
        "message": "Incorrect API key provided: sk-dEQi4***************************************uraT. You can find your API key at https://platform.openai.com/account/api-keys.",
        "type": "invalid_request_error",
        "param": null,
        "code": "invalid_api_key"
    }
}

But the key I had in ~/.aicommits wasn't starting with DEQi, it was an entirely different key. After runnning printenv | grep OPEN I found that I had no env var named "OPENAI_KEY" but I had an OPENAI_API_KEY, and this was what was picked up by aicommits instead of the correct OPENAI_KEY