This PR adds a feature to the plugin that introduces an alternative method of providing the OpenAI API key. In addition to providing the key via an OPENAI_API_KEY environment variable, the plugin also supports getting the API key from the output of arbitrary commands, configured via the api_key_cmd configuration parameter.
This allows users to securely provide the API key, without having to write it in clear-text to disk. It also prevents the API key from being readable by processes with access to the initial environment variables of neovim.
The default behaviour is to use the OPENAI_API_KEY environment variable, so as to not break backwards compatibility.
The README includes a couple of examples of how to use op or gpg to inject the secret into neovim.
Disclaimer: This is my first lua code since... 2005 or something, so I'm sure there's a prettier way of doing what I did here. Critique is welcome ;)
Since configuration wasn't initialized when the the api.lua file was being run, I had to introduce a setup() function to the api.lua file.
This PR adds a feature to the plugin that introduces an alternative method of providing the OpenAI API key. In addition to providing the key via an
OPENAI_API_KEY
environment variable, the plugin also supports getting the API key from the output of arbitrary commands, configured via theapi_key_cmd
configuration parameter.This allows users to securely provide the API key, without having to write it in clear-text to disk. It also prevents the API key from being readable by processes with access to the initial environment variables of neovim.
The default behaviour is to use the
OPENAI_API_KEY
environment variable, so as to not break backwards compatibility.The README includes a couple of examples of how to use
op
orgpg
to inject the secret into neovim.Disclaimer: This is my first lua code since... 2005 or something, so I'm sure there's a prettier way of doing what I did here. Critique is welcome ;)
Since configuration wasn't initialized when the the
api.lua
file was being run, I had to introduce asetup()
function to theapi.lua
file.