👉 Support this work via GitHub Sponsors
Minimal ChatGPT and DALL-E Emacs shells.
A short intro in a blog post.
This is very much an experimental proof of concept, possibly incomplete, or maybe with some rough edges. Pull requests with improvements or fixes totally welcome.
Load (require 'chatgpt-shell)
You’ll first need to get a key from OpenAI.
;; if you are using the "pass" password manager
(setq chatgpt-shell-openai-key
(lambda ()
(nth 0 (process-lines "pass" "show" "openai-key"))))
;; or if using auth-sources, e.g., so the file ~/.authinfo has this line:
;; machine openai.com password OPENAI_KEY
(setq chatgpt-shell-openai-key
(auth-source-pick-first-password :host "api.openai.com"))
;; or same as previous but lazy loaded (prevents unexpected passphrase prompt)
(setq chatgpt-shell-openai-key
(lambda ()
(auth-source-pick-first-password :host "api.openai.com")))
M-x set-variable chatgpt-shell-openai-key
(setq chatgpt-shell-openai-key "my key")
Launch with M-x chatgpt-shell
or dall-e-shell
.
Type clear
as a prompt.
ChatGPT> clear
Alternatively, use either M-x chatgpt-shell-clear-buffer
or M-x comint-clear-buffer
.
Save with M-x chatgpt-shell-save-session-transcript
and restore with M-x chatgpt-shell-restore-session-from-transcript
.
(setq chatgpt-shell-chatgpt-streaming t)
enables streaming.
M-x chatgpt-shell-explain-code
Load (require 'ob-chatgpt-shell)
and invoke (ob-chatgpt-shell-setup)
.
#+begin_src chatgpt-shell
Hello
#+end_src
#+RESULTS:
: Hi there! How can I assist you today?
Load (require 'ob-dall-e-shell)
and invoke (ob-dall-e-shell-setup)
.
#+begin_src dall-e-shell
Pretty clouds
#+end_src
#+RESULTS:
[[file:/var/folders/m7/ky091cp56d5g68nyhl4y7frc0000gn/T/1680644778.png]]