Mini_Python_Projects icon indicating copy to clipboard operation
Mini_Python_Projects copied to clipboard

AI-Powered Commit Message Generator (Flan-T5)

Open DarshanCode2005 opened this issue 2 months ago β€’ 0 comments

πŸ“‹ Overview

Writing meaningful Git commit messages is often skipped or done poorly. This project automates commit message generation by summarizing code changes with a small, offline LLM the Flan-T5 model ensuring it works on any machine without a GPU.


🎯 Objectives

  • Automatically generate descriptive commit messages from Git diffs.
  • Maintain a lightweight, offline workflow suitable for developers with CPU-only machines.
  • Provide an easy-to-use CLI or pre-commit hook integration.

βš™οΈ Features

  1. Diff Analysis: Extracts staged Git changes.
  2. AI Commit Generation: Uses Flan-T5 to generate human-readable messages.
  3. Commit Type Support: Optionally categorize messages as feat, fix, docs, etc.
  4. CLI Interface: Quick command-line usage:
python commitgen.py --type feat
  1. Offline & CPU-Friendly: No GPU required; runs on small laptops or cloud servers.

🧩 Tech Stack

  • Python 3.12+
  • Libraries: transformers, torch, argparse, subprocess

πŸ“‚ Project Structure

ai-commit-gen/
β”œβ”€β”€ commitgen.py          # CLI tool
β”œβ”€β”€ utils.py              # Git diff extraction and helpers
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── examples/
    └── sample_diff.txt

πŸ§ͺ Example Workflow

# Stage changes
git add .

# Generate AI commit message
python commitgen.py --type feat

# Output:
# ✨ Suggested Commit:
# "feat(auth): refactored login validation and added password length checks"

πŸš€ Advantages

  • Fully offline, CPU-compatible, no API keys required.
  • Lightweight (Flan-T5 small model ~240 MB).
  • Improves commit quality and project maintainability.

DarshanCode2005 avatar Oct 26 '25 01:10 DarshanCode2005