xhcoding / emacs-aichat

AI Chat in Emacs, including OpenAI and Bing Chat
62 stars 8 forks source link

auth-source stops emacs daemon from starting #10

Closed MunsterPlop closed 1 year ago

MunsterPlop commented 1 year ago

When using a gpg encrypted authinfo file, due to this code:

(defun aichat-openai-api-key ()
  "Get openai api key from `auth-sources'."
  (auth-source-pick-first-password :host "platform.openai.com" :user "aichat-openai"))

The user will be prompted for their gpg passphrase, which is fine when starting Emacs in the foreground.

However, if Emacs is started in the background, for example using Emacs Daemon, it will just keep it from fully loading, as the user will never have access to the gpg prompt.

I'm suggesting wrapping auth-source-pick-first-password in a lambda like this:

(defun aichat-openai-api-key ()
  "Get openai api key from `auth-sources'."
  (lambda () (auth-source-pick-first-password :host "platform.openai.com" :user "aichat-openai")))

This will return a closure and defer the auth-source-pick-first-password call, allowing proper load of Emacs in the background.