5 Tasks from Open Source Emacs AI plugins where you can contribute
with a code review, by ChatGPT, of the Emacs plugin gptai
This week, The Generative Review brings 5 tasks from Emacs open source projects that let you use ChatGPT inside the editor. These are GitHub issues that anyone can help with, by sending a pull request (PR) to the repositories linked below, with minimal knowledge required. They are, most of them, beginner’s tasks, meant to make it easy to do a first contribution or get involved with open source.
antonhibl/gptai | Utility functions for gptai-turbo (issue #2)
Allows interacting with various GPT and DALL-E Models directly in emacs.
feature request: provide the utility functions, already present, also for the gpt-4/gpt-3.5-turbo requests , and if possible, do this without duplicating code unnecessarily. The easiest way is possibly to have gptai-send-request dispatch to 3.5-turbo or gpt-4 if the user specifies that.
go to task →
joshcho/ChatGPT.el | chatgpt-repo-path should not be hard-coded (#2)
chatgpt-repo-path
should not be hardcoded to assume straight.el was used to install the package. It would be better to dynamically detect the repository path.
The package will fail to install due to it missing a package header, and without it there's no way for the package manager to know which dependencies are needed or what minimum version of Emacs the package supports.
go to task →
Additionally, the maintainer would be happy to accept any pull requests integrating the newly-released ChatGPT API into the project.
samrawal/gpt-emacs-macro | TODO: rewrite gpt-emacs-macro in elisp
Connect GPT-3 to Emacs and run "semantic" kbd macros.
the project implementation uses the OpenAI Python package and interfaces with a Python script. To use it you add your OpenAI API key and set the Python script path in gpt-macro.el.
A rewrite in elisp-only, via curl to interface with the API, would be most welcome. It is a nice task for those who are learning elisp and want some public feedback and visibility. gpt-emacs-macro is a small and straightforward project, but it already has 37 stars on GitHub, as of March ‘23.
go to project →
rksm/org-ai | Image variation without CLI curl (issue #1)
From the maintainer:
“Currently the image variation implementation requires command-line curl to be installed. Reason for that is that the OpenAI API expects multipart/form-data requests and the emacs built-in url-retrieve does not support that (at least I haven't figured out how). Switching to request.el might be a better alternative. If you're interested in contributing, PRs are very welcome!”
go to task →
stuhlmueller/gpt.el | GPT-3.5 (issue #5)
Simple Emacs package for calling instruction-following language models.
make the package use GPT-3.5. The API format for the chat engines is different and setting gpt-openai-engine
to "gpt-3.5-turbo"
does not work. Instead, a code update is needed.
go to task →
Thanks for reading The Generative Review this far! Each installment of TGR will come with more open source projects that you can contribute to, over many languages, such as Python, Rust, Go and others.
A code review by ChatGPT: gptai
(Emacs plugin by Anton Hibl, Software Engineer and ethical hacker)
This Emacs Lisp implementation of a package called gptai
uses the OpenAI API to generate natural language text. Here is my review of the code:
The
defgroup
form is used to create a customization group for thegptai
package.The
require
forms load the necessary libraries (url
andjson
).The
gptai-request
function sends a request to the OpenAI API and returns the response as JSON.
gptai-request uses url-retrieve-synchronously
to send an HTTP POST request to the OpenAI API with the specified parameters. It sets the request method to "POST" and adds the necessary headers, including the API key. It then retrieves the response as a buffer, searches for the beginning of the response body, and parses the JSON string using json-read
.
The
gptai-send-query
function sends a query to the OpenAI API and inserts the response text at the current point.
gptai-send-query first extracts the prefix and suffix parameters from the input, along with other optional parameters like temperature and max-tokens. It then constructs the prompt by concatenating the prefix, prompt, and suffix. It creates a data structure containing the prompt and other parameters, encodes it as a JSON string using `
gptai-send-query-region
sends a query using the selected region, replacing the region with the response text.gptai-send-query-buffer
sends a query using the contents of the specified buffer as the prompt.gptai-spellcheck-region
sends a query to spellcheck the selected region.The
gptai-elaborate-on-region
function sends a query to elaborate on the selected region.
Overall, the code looks well-organized and documented, with clear and concise function names and comments.
GPT-suggested improvements
According to the authority on all GPT API matters, it might be useful to include features such as the ability to generate multiple responses, and extra error checking and handling, especially around the API request and response. And who’s to say otherwise? Thanks for reading The Generative Review!