jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.56k stars 307 forks source link

feat: handle limited time key, Lua function for obtaining keys #407

Open rameshsanth opened 3 months ago

rameshsanth commented 3 months ago

This PR addresses 3 items.

  1. Allow users to use Lua functions to provide keys (in addition to current methods)
  2. Allow timeouts to be specified for keys. Automatically request new keys when it expires
  3. A bug fix in handling stream

Lua function is self explanatory. The README has been updated to reflect it and also with an example that I'm using personally. The change is simple also. It is a 2 line change in loadConfigFromCommand()

The timeout handling is bit complicated. Every time the ChatGPT API's is used, the key is validated before executing the command. To achieve this, some code had to be refactored.

The third one is shown by below two screen shots with and without the fix.

Without the fix. Screenshot 2024-03-18 at 7 45 03 PM

With the fix. Screenshot 2024-03-18 at 7 42 49 PM