vim-ai icon indicating copy to clipboard operation
vim-ai copied to clipboard

Allow OpenAI API key to be loaded via shell command

Open meownix opened this issue 1 year ago • 6 comments

  • Updated README.md with instructions for using GPG-encrypted token files.
  • Added g:vim_gpg_ai_token_file_path to Vim configuration in autoload/vim_ai_config.vim.
  • Modified load_api_key in py/utils.py to handle GPG-encrypted token files.

meownix avatar Sep 27 '24 06:09 meownix

I suspect this hard GPG dependency is a bit of a bummer. Instead, allow for a command instead of a file, so that, say pass can be called, reading the GPG encrypted file. That's how, for example, isync and msmtp solve it.

Konfekt avatar Oct 02 '24 09:10 Konfekt

I suspect this hard GPG dependency is a bit of a bummer. Instead, allow for a command instead of a file, so that, say pass can be called, reading the GPG encrypted file. That's how, for example, isync and msmtp solve it.

You're right. I'll modify the method of passing the secret key to vim-ai from a hard dependency to a more flexible one, allowing users to pass a command instead. Thanks for your input.

meownix avatar Oct 02 '24 12:10 meownix

Good points! I can imagine a new config to allow passing a function that loads the key, e.g.: let g:vim_ai_load_api_token = ...

madox2 avatar Oct 02 '24 12:10 madox2

Even more flexible as this function could just return systemlist('cmd')[0].

Konfekt avatar Oct 02 '24 12:10 Konfekt

I would prefer to do it in a vim-way

madox2 avatar Oct 02 '24 13:10 madox2

Looking at the PR and the last comment, I wonder if there's a misunderstanding? If we agree that passing the token by a Vim function

function fn()
...
return token
endfunction

is doing it a vim-way, then this function could in particular, there are many (vim-)ways, set token = systemlist(cmd)[0] where cmd could be, say, pass my_ai_token

Konfekt avatar Oct 03 '24 05:10 Konfekt

You can now load token with a vim function, e.g.:

function! g:GetAIToken()
  return system("pass path/to/your/openai.key | head -1")
endfunction

let g:vim_ai_token_load_fn = "g:GetAIToken()"

madox2 avatar Mar 25 '25 22:03 madox2