Skip to main content

An AI-powered git commit message generator.

Project description

gai-commit

AI-powered CLI tool to generate commit messages from your staged Git changes. Works with both local Ollama models and OpenAI's API.

Installation

pip install gai-commit

Usage Options

1. Using Ollama (Local LLMs)

Ollama provides free, locally-running AI models with no API keys required.

Prerequisites:

# 1. Install Ollama (https://ollama.com)
# 2. Pull a model (only needed once):
ollama pull llama3.2
# Ollama daemon should start automatically after installation

Basic Usage:

# Stage your changes first
git add path/to/modified/files

# Generate commit message with default model
gai

# Or specify a different Ollama model
gai deepseek-r1:8b

2. Using OpenAI (Cloud-based LLMs)

For higher quality results, you can use OpenAI's models (requires API key).

Prerequisites:

# Set your OpenAI API key (or add to .env file)
export OPENAI_API_KEY=sk-your-key

Basic Usage:

# Stage your changes first
git add path/to/modified/files

# Generate commit message with default model (gpt-3.5-turbo)
gai --provider openai

# Or specify a different OpenAI model
gai --provider openai gpt-4o

Additional Options

# Generate a concise one-line commit message (subject only)
gai --oneline

# Combine with provider selection
gai --provider openai --oneline

How It Works

  1. Repository Check: Verifies you're in a git repository via gai.utils.is_git_repository
  2. Diff Collection: Gets staged changes with git diff --staged --minimal --unified=5 using gai.utils.get_staged_diff
  3. AI Processing: Sends the cleaned diff to the selected AI provider through gai.cli.generate_commit_message
  4. Output Cleaning: Formats the AI output and removes technical artifacts via gai.utils.clean_commit_message
  5. Interactive Workflow: Presents options to apply, edit, regenerate or quit via gai.cli.handle_user_choice
  6. Commit: Applies your approved message with git commit

Interactive Workflow

After generating a commit message suggestion, you'll see:

Suggested Commit Message:
feat(parser): improve error resilience

- add fallback recovery for malformed input
- reduce panic cases in edge parsing paths
---
[A]pply, [E]dit, [R]-generate, or [Q]uit? (a/e/r/q)

Your options:

  • A: Apply immediately (git commit -m "<message>")
  • E: Open your $EDITOR (defaults to vim) to refine the message
  • R: Ask the AI to generate a new suggestion using the same diff
  • Q: Quit without committing

Troubleshooting

Common Issues

  • "No staged changes found": Use git add to stage your changes first
  • "Not a Git repository": Make sure you're inside a valid git repository
  • "OPENAI_API_KEY environment variable not set": Set your OpenAI API key or use Ollama
  • "Ollama connection refused": Make sure the Ollama daemon is running (ollama serve)

Development

# Clone the repository
git clone https://github.com/muzahid59/gai
cd gai

# Install in development mode
pip install -e .

# Run tests
pytest tests -v

Benchmarking

Compare different models' performance:

# Make sure to stage some changes first
python run_benchmark.py

License

MIT - see LICENSE

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

gai_commit-0.1.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

gai_commit-0.1.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gai_commit-0.1.2.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gai_commit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 24cbae30255e85db6984f6eb27c646886a2e9deec5eabf948f566d21be72233a
MD5 2113f6f646f88432b85f7b896eca6c4f
BLAKE2b-256 37f887ba52afd0c99f50dd9a5ceb808b54ebb1a6123e70eb8d98556367af09f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gai_commit-0.1.2.tar.gz:

Publisher: publish.yml on muzahid59/gai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: gai_commit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gai_commit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a1512e48f96802aca698647239eff5c837a8886736b7853705ead95a16b9c12f
MD5 f1e697f1aab5635860733b0ea482d911
BLAKE2b-256 206c3eec04249d295f8ffc94cf8abcf6d9d334889b92d5de13397da42e721b73

See more details on using hashes here.

Provenance

The following attestation bundles were made for gai_commit-0.1.2-py3-none-any.whl:

Publisher: publish.yml on muzahid59/gai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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