ChatGPT.nvim icon indicating copy to clipboard operation
ChatGPT.nvim copied to clipboard

api_key_cmd is ignored if OPENAI_API_KEY is set

Open lukeemhigh opened this issue 1 year ago • 3 comments

I use op as my api_key_cmd, but this only works if the OPENAI_API_KEY env var is not set.

I have exported my OPENAI_API_KEY to "op://Personal/OPENAI_API_KEY/credential" to be able to use the op run command to expand that variable and pass it to selected subprocesses, but this breaks the plugin because it seems that it defaults to get its api_key from env vars even if an api_key_cmd is set.

To me, the opposite behavior should be preferred.

lukeemhigh avatar Jul 01 '24 15:07 lukeemhigh

Ohhhhh Thanks a lot because your issue made me understand why I had issues with launching the app through SSH or not. It was because I was setting the environment viable in just one of the two cases. Thanks a lot.

thiswillbeyourgithub avatar Jul 01 '24 15:07 thiswillbeyourgithub

I'm interested to know if anything has changed. And I don't think we should need to set in two places although I have been needing to do this in the last few weeks.

What I can suggest is getting the api_key locally in lua first via a function, and then wiring it to api_key_cmd simply by echo. api_key_cmd wants a command, so you may as well simply echo the response as a command. Have tried here: https://github.com/jackMort/ChatGPT.nvim/issues/454

MrCee avatar Jul 12 '24 09:07 MrCee

What I can suggest is getting the api_key locally in lua first via a function, and then wiring it to api_key_cmd simply by echo. api_key_cmd wants a command, so you may as well simply echo the response as a command. Have tried here: #454

Sorry for the late reply, but this seems promising. I'll look into it and get back sooner or later!

lukeemhigh avatar Nov 28 '24 11:11 lukeemhigh