GPT Commit Message Generator
This program is a commit message generator that leverages GPT-4 or GPT-3.5-turbo to create detailed and informative commit messages for your source control.
Requirements
- Python 3
- openai
- tiktoken
- An OpenAI API key
Installation
- Install the required Python packages:
pip install openai tiktoken
- Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY="your_openai_api_key"
Usage
The program can be run in two ways:
- Piping a diff into the script:
diff -u old_file new_file | python3 gpt_commit_msg.py
- Using the --git flag to automatically use staged git changes:
python3 gpt_commit_msg.py --git
By default, the script uses GPT-3.5-turbo, which is faster and costs less. To use GPT-4 instead, add the -4 flag:
python3 gpt_commit_msg.py -4
How It Works
The script reads a diff from either stdin or staged git changes, and then creates a commit message using OpenAI's GPT. It handles large diffs by splitting and summarizing the input until it fits within the model's token limit.
The generated commit message will start with a one-line summary of 60 characters, followed by a blank line, and then a longer but concise description of the changes.
Notes
Note that the entirety of this README until this section was generated by GPT4 based on the contents of the script. Every change description in this project's history also came courtesy of this script.
Editor Integration
Vim
I use the following two macros in my .vimrc to easily invoke this command when writing a commit message.
command! CommitMsg :r !gpt_commit_msg.py --git
command! CommitMsg4 :r !gpt_commit_msg.py --git -4
Metadata
Release files for gpt-commit-msg 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gpt_commit_msg-0.1.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gpt_commit_msg-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / gpt_commit_msg-0.1.2.tar.gz
| Download URL | gpt_commit_msg-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56cd2f6e01836eea11805c3a95335cbfc7538468baee5bba163dd204b4872a6b
|
|
BLAKE2b-256 checksum How to use checksums |
206dd6cd5156eedda6f68d0252e36ddf60900794ab41e7d5991002fd9e589f38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.7
|
Release files / gpt_commit_msg-0.1.2-py3-none-any.whl
| Download URL | gpt_commit_msg-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c3e011ac218acb788ba8bcadf90b370c34322994f585e648b0fb9ce0dd996342
|
|
BLAKE2b-256 checksum How to use checksums |
aeb8ae40eeb6a4ffaa49f5c36f69c41156927cb0278e1f2081fd260091f9e417
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.7
|