Now Reading
A ChatGPT Emacs shell

A ChatGPT Emacs shell

2023-03-21 18:35:31

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 😉

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top