Over my decorated 10-year career in development, I have seen some of the worst commit messages. I don't blame the developer on this either, because it is hard to remember what you just did at the time of the git commit.
image was generated using midjourney
In this 9 days of OpenAI series, I am looking at AI projects and their code to help demystify how any dev can build AI-generated projects.
Find more AI projects using OpenSauced
The last thing I want to do is traverse a git diff and figure it out after a productive day of coding. I love the Nutlope/aicommits.
What is Nutlope/aicommits?
Aicommits is a CLI that writes your git commit messages for you with AI. During my 9 days of OpenAI, you will see projects from @nutlope frequently. He has been shipping cool projects and sharing them on Twitter.
How does it work?
This post is meant to focus on the AI part of the code, but as soon as I looked at the GitHub, I was surprised to see the use of TABS, jk. I was impressed by this CLI tool that caught my eye, cleye (cleverly named). I built a few CLIs back in my day, and this cleye is the chosen tool for building the aicommits interactions on the command line. I will take a deeper look at cleye in the future and perhaps make something with it.
If you'd like to see the CLI implementation, it is a quick read in the src/cli.ts.
// src/cli.ts
const request = https.request({
port: 443,
hostname: 'api.openai.com',
path: '/v1/completions',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postContent.length,
Authorization: `Bearer ${apiKey}`,
},
...
I have not built anything with OpenAI as of yet, but this is a clean example of how someone could approach it.
Now looking at the code src/utils/openai.ts, I can see OpenAI being invoked and using the /v1/completions path. Per the README, this is not the ChatGPT completions but regular GTP-3 text completions.
After the REST call, there is some clean-up of the response and this clever error checker. This is required because of the frequent OpenAI downtime and server loads.
// src/utils/openai.ts
if (response.statusCode === 500) {
errorMessage += '; Check the API status: https://status.openai.com';
}
Finally, taking a looking at the createCompletion function, this is the actual place the magic is made. I found this more understandable than reading the OpenAI documentation, which I found a little overwhelming. I wish it had the ability to search (why does it not have search?).
I left comments below on what each line is doing.
// src/utils/openai.ts
const completion = await createCompletion(apiKey, {
model, // text-davinci-003 - made for longer output, and consistent instruction
prompt, // promptTemplate provided by nutlope
temperature: 0.7, // higher the number, the more random the output
top_p: 1, // like temperature but different results
frequency_penalty: 0, // decreasing the model's likelihood of repeating the same line
presence_penalty: 0, // increasing the model's likelihood of talking about new topics
max_tokens: 200, // how much will this cost you?
stream: false, // partial message sending is off
n: completions, // How many chat completion choices to generate for each input message
});
There is a lot more I'd love to dig into, but I will leave the rest for you to take look. I do recommend installing aicommits locally to try it out. Just be sure to sign up for OpenAI to add your token.
If I need to correct something, or if you have some insight into the code, please comment. I enjoyed walking through the code and learning how this works. Thanks to Nutlope for sharing this with us, and be sure to contribute back upstream. Open Source FTW!
Also, if you have a project leveraging OpenAI, leave a link in the comments. I'd love to take a look and include it in my 9 days of OpenAI series.
Stay saucy.
Top comments (19)
git commit -v
really helps here. Since I started enforcing it on myself (through use of a shell function that intercepts all my attempts to rungit
) my commit messages have got much better.git add --patch|-p
has helped a lot in this also, both tools we all should be using, actuallyI have to walk a fine line, in this response, because...
First, if you don't remember what work you did, then you probably put too much into your commits. While I realize that nobody's perfect and things slip through the cracks, each commit should do a specific thing, and someone can ideally add a specific feature (and nothing else) by cherry-picking other otherwise moving a defined set of commits.
Then, changes (in a professional environment) should all be connected to a ticket, so that people can track the work happening without analyzing the repository. Commits should call out the relevant ticket numbers and probably echo the language used in the ticket. I'm never going to search a repository for "the time that Zemzem removed a text box." I want "the work done on ticket #4586, ideally seeing the individual tasks involved in finishing that ticket."
Finally, you're allowed to use a graphical interface, when you commit, and look at the changes that you're committing. Again, if you did a bunch of things at once, you should probably use such a tool, so that you can commit specific lines that go together, instead of full files.
Again, that doesn't take away from the technical achievement or the entertainment value. And (like anything with generative AI) if you use the results as a springboard to what you'll really write, that'll probably serve you better. But I definitely worry about trying to "outsource" communication with your closest colleagues...
Look like developers have the sam idea, I also did the same thing with you. But i named it ai-commit instead. Use conversation form to ajust the message
Please drop a link if its open source. Also to be clear this isn't my project, but a project open sourced by @nutlope
If you use VS Code the latest pre-release version of GitLens also provides the ability to use ChatGPT to generate commit messages (and probably soon to explain commits). There is even a setting so the user can control the commit message style as part of the prompt.
Adopted here ;-p
It's very nice, but sometimes I'm too lazy to think about the commit message after the long hour code.
the too many requests are killing my vibe tho :<
It's nice, I tested it yesterday, but please note that too many commits (requests) in a short period of time will result in an error 400 - bad request. 👏🔝🎉
Good call out. There are some obvious areas of improvements and I think this project is set up well for some one to take what is already there and make something useful for a lot of people.
Nice one
Very simple and inspiring implementation. I'll probably do a couple of experiments too =)