FR: Custom location of file with OpenAI API Key #19
Replies: 7 comments 3 replies
-
I have something like this in my
That way, I can add secret/machine specific config to my Edit: Or you could just not source track your |
Beta Was this translation helpful? Give feedback.
-
For anyone reading this using fish, I have a I then have this simple function to load the env file: function load_env_vars -d "Load variables in a .env file"
for i in (cat $argv)
set arr (echo $i |tr = \n)
set -gx $arr[1] $arr[2]
end
end
load_env_vars ~/.env with the env file looking like:
|
Beta Was this translation helpful? Give feedback.
-
I like the idea of keeping it as an environment variable, but we can consider storing it in a different way |
Beta Was this translation helpful? Give feedback.
-
while all methods suggested here work, I think the solution suggested by the dev of ai.vim seems the most user-friendly to me:
|
Beta Was this translation helpful? Give feedback.
-
I hope my solution inspires someone: source ~/.config/.open_ai |
Beta Was this translation helpful? Give feedback.
-
Here my solution ChatGPT.lua local env = vim.fn.expand('$HOME') .. '/.config/nvim/env.lua'
dofile(env)
if vim.env.OPENAI_API_KEY == nil then
print('Please set the OPENAI_API_KEY environment variable')
return
end
local status_ok, chatgpt = pcall(require, 'chatgpt')
if not status_ok then
return
end
chatgpt.setup({}) env.lua ( use gitignore on this file ) vim.cmd("let $OPENAI_API_KEY='<PUT-YOUR-KEY_HERE>'") |
Beta Was this translation helpful? Give feedback.
-
I've put up a PR that lets you configure the secret on setup: #147 This is my preference and how I currently use this plugin in a declarative way, may not be for everyone. |
Beta Was this translation helpful? Give feedback.
-
Basically the same issue I also reported for
ai.vim
: Some of us have their dotfiles public, so that putting the API key into files like.zshenv
is not ideal.The workaround right now is to set it via vim.env outside of the dotfiles repo, and symlink that file into the nvim config, which is unnecessarily many hoops to jump through just to get it set up.
Beta Was this translation helpful? Give feedback.
All reactions