/ChatGPT.el

ChatGPT in Emacs

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

ChatGPT.el

ChatGPT in Emacs.

News

OpenAI is releasing its ChatGPT API soon. Sign up here. ChatGPT.el will support the official API once released. Browser-based API will remain supported.

Installation

Dependency

pip install epc
pip install git+https://github.com/mmabrouk/chatgpt-wrapper
chatgpt install

This will prompt you to log in with your browser.

NOTE: If you encounter any problems, please submit an issue or see chatgpt-wrapper.

(use-package chatgpt
  :straight (:host github :repo "joshcho/ChatGPT.el" :files ("dist" "*.el"))
  :init
  (require 'python)
  (setq chatgpt-repo-path "~/.emacs.d/straight/repos/ChatGPT.el/")
  :bind ("C-c q" . chatgpt-query))
(require 'quelpa-use-package)
(use-package chatgpt
  :quelpa ((chatgpt :fetcher git :url "https://github.com/joshcho/ChatGPT.el.git") :upgrade t)
  :init
  (require 'python)
  (setq chatgpt-repo-path (expand-file-name "chatgpt/" quelpa-build-dir))
  :bind ("C-c q" . chatgpt-query))

In dotspacemacs/user-config function,

(require 'python)
(setq chatgpt-repo-path (expand-file-name "chatgpt/" quelpa-build-dir))
(global-set-key (kbd "C-c q") #'chatgpt-query)

In dotspacemacs/layers function for setq-default,

dotspacemacs-additional-packages
'(
  (chatgpt :location (recipe
                      :fetcher github
                      :repo "joshcho/ChatGPT.el"))
  ;; other additional packages...
  )

NOTE: Assumes Quelpa installation.

In packages.el ,

(package! chatgpt
  :recipe (:host github :repo "joshcho/ChatGPT.el" :files ("dist" "*.el")))

In config.el ,

(use-package! chatgpt
  :defer t
  :config
  (unless (boundp 'python-interpreter)
    (defvaralias 'python-interpreter 'python-shell-interpreter))
  (setq chatgpt-repo-path (expand-file-name "straight/repos/ChatGPT.el/" doom-local-dir))
  (set-popup-rule! (regexp-quote "*ChatGPT*")
    :side 'bottom :size .5 :ttl nil :quit t :modeline nil)
  :bind ("C-c q" . chatgpt-query))

Usage

  • Press C-c q to query ChatGPT.
  • Select region, then C-c q will prompt you to select a type: doc, bug, understand, or improve. Select a type to query ChatGPT with that prompt.
  • Try making queries in quick succession.
  • If your login is expired, try
pkill ms-playwright/firefox && chatgpt install

in the shell.

  • To reset your conversation, try M-x chatgpt-reset.

Troubleshooting

  • For most scenarios, the reliable method is pkill ms-playwright/firefox && chatgpt install to reauthenticate yourself.
  • Also try M-x chatgpt-reset.
  • If for some reason the ellipses keep blinking, try M-x chatgpt-stop.
  • Make sure you have python installed, and python-interpreter is set (most likely set it to “python” or “python3”).
  • If none of these methods work, please submit an issue.

Customization

Customize chatgpt-query-format-string-map for your own types.

(setq chatgpt-query-format-string-map '(
                                        ;; ChatGPT.el defaults
                                        ("doc" . "Please write the documentation for the following function.\n\n%s")
                                        ("bug" . "There is a bug in the following function, please help me fix it.\n\n%s")
                                        ("understand" . "What does the following function do?\n\n%s")
                                        ("improve" . "Please improve the following code.\n\n%s")
                                        ;; your new prompt
                                        ("my-custom-type" . "My custom prompt.\n\n%s")))

Misc.

  • Don’t use “custom” as a type. It’s reserved for custom prepend string through minibuffer.
  • Check out Pen.el