nvim-magic icon indicating copy to clipboard operation
nvim-magic copied to clipboard

OpenAI api key available as vimconfig variables

Open Daniel-Boll opened this issue 4 years ago • 5 comments

I found a possible improvement on your code, but just for context:

I was basicly hand-cloning your repo both to learn a little bit more of lua and try to create my first (neo)vim plugin in the similar branch as nvim-magic called ally.nvim, I have a weak base on lua but got some ideas with a friend on how I wanted ally.nvim to looks like, lacking the skill to do so I found your repo and start to take a look on it, just figured out that I won't have the necessary skill so soon :sweat_smile:.

I don't know if what I have done is following good practices on lua programming neither the indentations and all, as my lua-formatter is configured for a different tab level than yours I tried not to mess with your code.

Best regards,

Daniel Boll.

  • ci: simplify (#20)
  • feat(api-key): add the possibility to set the OPENAI key in the vim config variables

Daniel-Boll avatar Sep 16 '21 20:09 Daniel-Boll

Hey Daniel, thanks for opening a PR! I am learning Lua/Neovim as well and am not entirely sure what good practice would be in terms of passing the API key (or more generally any secret) to Neovim on the desktop. The ideal I think would be to get it from an external secrets manager like Bitwarden or Keychain on macOS. I am unsure even about the current approach of getting it from an environment variable, though it's very convenient.

Wrt. getting the API key from a Vim global, alternatively to adding functionality to env_get_api_key(), we could allow this function to be overridden entirely by the user. When constructing the backend on line 73, we pass in this function that should return the API key as the third argument.

return backend.new(config.api_endpoint, http.new(http_cache), env_get_api_key)

So they could pass in any function in the OpenAI backend config instead, what do you think?

jameshiew avatar Sep 19 '21 15:09 jameshiew

Yeah, it's indeed a better approach following the premise you proposed to this plugin.

Daniel-Boll avatar Sep 19 '21 22:09 Daniel-Boll

Great, if you want to have a go at this feel free, otherwise I can get around to it at some point as it's not a big change

jameshiew avatar Sep 29 '21 14:09 jameshiew

Ow, sorry I though when you had proposed the change you already implemented it, my bad didn't realized :sweat_smile: as soon as I get some free time I'll try to implement this :fist_oncoming:.

Daniel-Boll avatar Sep 29 '21 15:09 Daniel-Boll

Ah if you want to, don't worry about formatting/docs/etc as that can be fixed at the end, I think it'd be good to have the API key configurable in this way and will otherwise do it eventually, but got a few other things to work on :smile:

jameshiew avatar Sep 29 '21 15:09 jameshiew