A ChatGPT Emacs shell

submited by
Style Pass
2023-03-22 00:00:08

I had been meaning to give ChatGPT a go. Preferably from Emacs. As an eshell fan, ChatGPT just seemed like the perfect fit for a shell interface sorts. With that in mind, I set out to wire ChatGPT out with Emacs's general command interpreter (comint).

I had no previous experience building anything comint-related, so I figured I could just take a peak at an existing comint-derived mode to achieve a similar purpose. inferior-emacs-lisp-mode (ielm) seemed to fit the bill just fine, so I borrowed quite a bit to assemble a basic shell experience.

From then on, it was mostly about sending each request over to the ChatGPT API to get a response. For now, I'm relying on curl to make each request. The invocation is fairly straightforward:

There are two bits of information needed in each request. The API key, which you must get from OpenAI, and the prompt text itself (i.e. whatever you want ChatGPT to help you with). The results are not too shabby.

Leave a Comment