A ChatGPT Emacs shell
I had been which means to offer ChatGPT a go. Ideally from Emacs. As an eshell fan, ChatGPT simply appeared like the right match for a shell interface kinds. With that in thoughts, I got down to wire ChatGPT out with Emacs’s common command interpreter (comint).
I had no earlier expertise constructing something comint-related, so I figured I might simply take a peak at an current comint-derived mode to realize the same goal. inferior-emacs-lisp-mode
(ielm) appeared to suit the invoice simply tremendous, so I borrowed fairly a bit to assemble a fundamental shell expertise.
From then on, it was principally about sending every request over to the ChatGPT API to get a response. For now, I am counting on curl to make every request. The invocation is pretty simple:
curl "https://api.openai.com/v1/chat/completions" -H "Authorization: Bearer YOUR_OPENAI_KEY" -H "Content material-Sort: utility/json" -d "{ "mannequin": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "YOUR PROMPT"}] }"
There are two bits of data wanted in every request. The API key, which you will need to get from OpenAI, and the immediate textual content itself (i.e. no matter you need ChatGPT that will help you with). The outcomes should not too shabby.
I’ve uploaded the code to github as a tiny chatgpt-shell bundle. It is a bit experimental and tough nonetheless, however hey it does the job for now. Head over to github to have a look. The newest iteration handles multiline prompts and fundamental code highlighting.
Let’s examine the place all of it goes. Pull requests for enhancements completely welcome 😉