Skip to content

gfgkmn/ChatGPT.el

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatGPT.el

ChatGPT in Emacs.

News

Compared to joshcho/ChatGPT.el, this repository offers support for stream replies and presents the output in a more visually appealing manner. It drew inspiration from carlos-wong/ChatGPT.el. I added two new functions, chatgpt-query-stream and chatgpt-query-by-type-stream, and also changed the default Python dependency to revChatGPT in order to use the official API.

Installation

Dependency

pip install sexpdata==0.0.3
pip install epc
pip install revChatGPT=4.0.8

OpenAI key

To store your OpenAI key, you should follow this format and save it in the ~/.authinfo.gpg file.

machine openai.com login chatgpt password sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(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-stream))

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

About

ChatGPT in Emacs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 85.9%
  • Python 14.1%