Skip to main content

A package for generating commit messages using GPT

Project description

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

  1. Install the required Python packages:
pip install openai tiktoken
  1. 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:

  1. Piping a diff into the script:
diff -u old_file new_file | python3 gpt_commit_msg.py
  1. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt_commit_msg-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpt_commit_msg-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file gpt_commit_msg-0.1.2.tar.gz.

File metadata

  • Download URL: gpt_commit_msg-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for gpt_commit_msg-0.1.2.tar.gz
Algorithm Hash digest
SHA256 56cd2f6e01836eea11805c3a95335cbfc7538468baee5bba163dd204b4872a6b
MD5 0877fe8c3075829034c675b2b6b40f49
BLAKE2b-256 206dd6cd5156eedda6f68d0252e36ddf60900794ab41e7d5991002fd9e589f38

See more details on using hashes here.

File details

Details for the file gpt_commit_msg-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gpt_commit_msg-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for gpt_commit_msg-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c3e011ac218acb788ba8bcadf90b370c34322994f585e648b0fb9ce0dd996342
MD5 7ea42b6e8ed6171f1dc0f85a170e4f33
BLAKE2b-256 aeb8ae40eeb6a4ffaa49f5c36f69c41156927cb0278e1f2081fd260091f9e417

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page