mgalgs / ChatGPT.el

ChatGPT in Emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChatGPT.el

ChatGPT in Emacs.

Installation

Dependency

pip install sexpdata==0.0.3
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 'chatgpt-python-interpreter)
    (defvaralias 'chatgpt-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 chatgpt-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")))

chatgpt-ensure-pip-install

Whether to automatically install the python chatgpt-wrapper package using pip if not detected in default pip list. You might want to set this to nil if you’re providing a custom chatgpt-python-interpreter (that points to a dedicated Python virtualenv for chatgpt-wrapper, for example).

(setq chatgpt-ensure-pip-install nil)

Misc.

  • Don’t use “custom” as a type. It’s reserved for custom prepend string through minibuffer.
  • See ob-chatgpt which builds on top of ChatGPT.el.
  • Check out Pen.el

About

ChatGPT in Emacs

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 83.9%Language:Python 16.1%