Skip to main content

A tool to generate commit messages using AI

Project description

lazym

lazym is an AI-powered tool that automatically generates meaningful commit messages for your Git repositories.

lazym is inspired by jen-Ya/commitgpt

Features

  • Generates commit messages based on staged changes
  • Without the risk of leaking code snippets to external LLM services
  • Integrates seamlessly with your Git workflow
  • Uses advanced language models for intelligent message generation

Requirements

Command to pull Llama 3.1:8b model for Ollama:

$ ollama run llama3.1:8b

Installation

To install lazym, follow these steps:

  1. Ensure you have Python 3.7+ and pip installed on your system.

  2. Install lazym using pip:

    pip install lazym
    
  3. After installation, navigate to any Git repository and run the following command to set up the Git hook:

    lazym install
    

    This will install the necessary Git hook to enable automatic commit message generation.

Usage

Once installed and set up, lazym works in two ways:

  1. Automatically when you make a commit: Simply stage your changes as usual and run git commit. lazym will generate a commit message based on your staged changes.

  2. Manually by running lazym ci "<hints for LLM>": This command allows you to generate a commit message with additional context provided to the LLM.

After generating the commit message, you'll be presented with four options:

  1. Accept and commit: Use the generated message as-is and commit.
  2. Edit message: Modify the generated message before committing.
  3. Regenerate message: Generate a new message using the same diff.
  4. Cancel commit: Abort the commit process.

This allows you to benefit from the AI-generated suggestions while maintaining full control over your commit messages. If you're not satisfied with the generated message, you can either edit it or request a new one.

Commands

  • lazym install: Install the prepare-commit-msg hook in the current Git repository.
  • lazym uninstall: Uninstall the prepare-commit-msg hook from the current Git repository.
  • lazym ci "<optional hints>": Generate a commit message with optional additional context.
  • lazym tag: Manage tags for your repository. This command allows you to list, create, and push tags to your remote repository.
  • lazym release: Create a release.

Configuration

lazym can be configured using a config.ini file located at ~/.config/lazym/config.ini. The following options are available:

[DEFAULT]

  • model: The AI model to use for generating commit messages.
    • Default: "llama3.1:8b"
    • Options:
      • Ollama models: Use the model name directly (e.g., "llama3.1:8b", "codellama:7b")
      • Groq models: Prefix with "groq:" (e.g., "groq:mixtral-8x7b-32768", "groq:llama2-70b-4096")

[!NOTE] To use Groq models, you need to:

  1. Sign up at groq.com to get an API key
  2. Set the GROQ_API_KEY environment variable with your API key
  • temperature: Controls the randomness of the AI's responses.

    • Default: 0.8
    • Range: 0.0 to 1.0
    • Lower values make responses more focused and deterministic
    • Higher values make responses more creative and varied
  • message_format: The format to apply to the generated commit message.

    • Default: "lowercase"
    • Options:
      • "lowercase": Converts the first character of the message to lowercase.
      • "sentence case": Capitalizes the first character of each sentence.
      • Any other value will keep the original format as generated by the AI.
  • prompt: The prompt template used to generate commit messages.

    • Must include the {diff} placeholder where the code changes should be inserted
    • Default: empty (uses built-in prompt)
    • You can customize this to match your team's commit message style
  • rstrip_period: Controls whether to remove trailing periods from commit messages.

    • Default: "true"
    • Options:
      • "true": Remove trailing periods from commit messages
      • "false": Keep trailing periods if present in the generated message

GitHub Release Configuration

  • service: The service to use for releases.

    • Default: github
    • Set to "github" to enable GitHub releases
  • token: GitHub personal access token for creating releases.

    • Default: empty
    • Required when service is set to "github"
    • Token must have repo scope permissions
  • prefix_v_for_tag_name: Whether to prefix version numbers with 'v' in release tags.

    • Default: true
    • Options:
      • true: Tags will be like v1.2.3
      • false: Tags will be like 1.2.3

Example configuration for GitHub releases:

[DEFAULT]
service = github
token = ghp_your_personal_access_token
prefix_v_for_tag_name = true

[!NOTE] To use GitHub releases, you need to:

  1. Create a personal access token with repo scope at GitHub Settings
  2. Configure the service and token in your config.ini

Customizing Prompts

You can customize how lazym generates commit messages by providing your own prompt template. There are two ways to do this:

  1. Using config.ini: Suitable for simple, one-line prompts. Specify the prompt option in your config.ini file. This method is ideal for straightforward prompts that don't require complex formatting or multiple lines.

    Example:

    [DEFAULT]
    prompt = "Generate a concise commit message for the following changes: {diff}"
    
  2. Using prompt.txt: Suitable for more complex, multi-line prompts. Create a prompt.txt file in the ~/.config/lazym/ directory. If this file exists, its contents will override the prompt setting in config.ini. This method is ideal for detailed prompts that require specific formatting or guidelines.

    Example prompt.txt:

    Generate a conventional commit message for these changes.
    Format: <type>(<scope>): <description>
    Types: feat, fix, docs, style, refactor, test, chore
    Keep the message under 72 chars.
    
    Changes:
    {diff}
    

If no prompt is specified in either config.ini or prompt.txt, lazym will use its built-in prompt template that follows general Git best practices.

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

lazym-0.20.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

lazym-0.20.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file lazym-0.20.0.tar.gz.

File metadata

  • Download URL: lazym-0.20.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for lazym-0.20.0.tar.gz
Algorithm Hash digest
SHA256 b51f9b98fea41f30185682f70b6cf09be08b4d10fdc4127d346020a3696973ab
MD5 8c75e4971959e9f9e17f744b889d5d82
BLAKE2b-256 002ce1ca440225eb524bf4dfa37b5c6b7c99c31a2956ce01f9a466c3b184527f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazym-0.20.0.tar.gz:

Publisher: publish-to-test-pypi.yml on spitfire-sidra/lazym

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

File details

Details for the file lazym-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: lazym-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for lazym-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e4257b24d0483c7b1412004b8a44884544e0e6fb050b06c3ffaab59af05dc53
MD5 dc9f2e7242da75a0c3156ea474720625
BLAKE2b-256 763c3ee1201861b712f91a433785af1916d06721c7a9869330c665d350d0d52b

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazym-0.20.0-py3-none-any.whl:

Publisher: publish-to-test-pypi.yml on spitfire-sidra/lazym

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