Skip to content

gunlinux/ollama_commit_generator

Repository files navigation

OpenCoder

A Python script that runs git diff --staged, and if there are changes, sends a request to a local Ollama chat to generate a commit name and message.

Features

  • Automatically generates commit messages based on your staged changes
  • Supports multiple AI providers (Ollama, Web UI)
  • Follows conventional commit formatting
  • User-friendly CLI with helpful error messages
  • Configurable through JSON configuration

Requirements

  • Python 3.12
  • Git
  • Ollama or a compatible local AI service

Installation

  1. Clone this repository:

    git clone <repository-url>
    cd opencode
  2. Create a virtual environment (recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows, use venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt

    Or run the installation script:

    ./install.sh

Configuration

The tool uses opencode.json for configuration. An example configuration file is provided as opencode.json.example. Copy this file to opencode.json and modify it according to your setup:

cp opencode.json.example opencode.json

Then edit opencode.json to match your AI provider configuration.

An example configuration is:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:IQ2_M": {
          "name": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:IQ2_M",
          "tools": true,
          "thinking": true
        }
      }
    }
  }
}

Usage

# Basic usage
python opencode.py

# Show help
python opencode.py --help

# Use a specific provider
python opencode.py --provider ollama

# Show the diff without generating a commit message
python opencode.py --dry-run

# Enable verbose output
python opencode.py --verbose

# Open editor with generated commit message
python opencode.py --edit

# Automatically commit without prompting
python opencode.py --auto-commit

How It Works

  1. The tool checks if you're in a Git repository
  2. It verifies you have staged changes
  3. It runs git diff --staged to get the changes
  4. It sends the diff to your configured AI provider
  5. The AI generates a commit message following conventional commit formatting
  6. The tool displays the suggested commit message

Troubleshooting

  • Make sure your AI service (Ollama/Web UI) is running
  • Verify your configuration in opencode.json
  • Ensure the specified model is available
  • Check your network connection if using a remote service

About

lmao project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published