Bryley / neoai.nvim

Neovim plugin for intracting with GPT models from OpenAI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

when opening nvim through a script that spawns a term with nvim with a set working dir, it cannot use the OPENAI_API_KEY envir variable.

emilBeBri opened this issue · comments

Hi, so I have a script that opens nvim in different working dirs based on keyboard shortcuts.

This would be the command that gets executed:


alacritty --working-directory /home/emil/test --title 'nv-configtest' -e $EDITOR

However, when doing this, I get this very clear message telling me the API key is not present as an environmental variable:

OPENAI_API_KEY environment variable is not set, and open_api_key.value is empty
E5108: Error executing lua ...l/.local/share/nvim/lazy/neoai.nvim/lua/neoai/config.lua:72: OPENAI_API_KEY environment variable is not set, and open_api_key.valu
e is empty

WHat I don't get is that this variable has been set - and I know this, because when I spawn a terminal, fx with a keyboard shortcut in i3:


bindsym $mod+Shift+l exec alacritty; mode "default"


I can see that the variable is there with echo $OPENAI_API_KEY. if I open nvim manually, from such a spawned terminal, NeoAI works fine because the envir var is there. But when doing it through my script, there is nothing.

I have tried putting the



export OPENAI_API_KEY=xxxxxxxxxxxxxxxx

in both ~/.profile and ~/.bashrc, to no avail.

I suspect this is a problem not of neoAI but of my lack of knowledge about how launching a terminal from within a script does not trigger the use of the bash profile, but I'm not sure.