piersolenski/wtf.nvim

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

Dakai opened this issue · 6 comments

Dakai commented

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.

☝🏻 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

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.

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

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

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!

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)