piersolenski / wtf.nvim

Delicious diagnostic debugging in Neovim 🤤
400 stars 9 forks source link

Can you change the Open AI API key setup to read the environment variable instead of writing it in the config? #4

Closed Dakai closed 1 year ago

Dakai commented 1 year ago

People including me backs up their dot file in Github or other cloud platforms may accidentally expose their API key to the public, which I just did.

LSleutsky commented 1 year ago

☝🏻 this!

It says in the documentation that you can set the OPENAI_API_KEY environment variable to make this work, but that is not the case, and you in fact need to set the openai_api_key option in the config, which as @Dakai had pointed out, will be exposed if one's Neovim config is pushed to GitHub (which most people's is)...

Dakai commented 1 year ago

Hey @LSleutsky , actually, I just found out that it works with OPENAI_API_KEY environment variable when I just delete the openai_api_key option in the config.

LSleutsky commented 1 year ago

Hmm, really? That's bizarre, it doesn't work for me. Sometimes it gives me an error message that I've exceeded my API billing usage, even tho I have tons of credits on my OpenAI account, and have tried creating new keys and setting it to the env variable you mention, and still nada!

Will try to dig around and see why. Thanks for the reply...!

b0o commented 1 year ago

Another option if you manage your dotfiles with git is to keep the API keys in a Lua file that's in your .gitignore. Here's how I do it:

https://github.com/b0o/nvim-conf/blob/main/lua/user/private.example.lua

https://github.com/b0o/nvim-conf/blob/fdb2fe5ddefdf0c0edf2bea72757bb893fa9f5d2/lua/user/plugin/wtf.lua#L8

piersolenski commented 1 year ago

Just to clarify, wtf.nvim will respect the OPENAI_API_KEY environment variable. The openai_api_key is an alternative way to set your key, and will override the environment variable if present - which is useful for testing or people who don't want to set it via the environment variable. Hope that helps!

marcelarie commented 9 months ago

Another alternative is to have the key in pass and declare it inside the env var like this:

OPENAI_API_KEY=$(pass show openai-api-key)

on fish shell:

    set -g OPENAI_API_KEY (pass show openai-api-key)