npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

commit-generate-ollama

v1.0.8

Published

ai commit generate toolkit

Downloads

419

Readme

Git Commit Message Generator with Ollama

Github

commit-generate-ollama

Overview

This Node.js script automatically generates concise and meaningful Git commit messages using AI models from Ollama. It fetches changes in your Git repository, creates a summary of the changes, and generates an appropriate commit message based on those changes. The script also supports model customization, allowing you to choose which Ollama model to use for generating the commit messages.

Features

  • Automatic Git Staging: Automatically stages files in the working directory before generating the Git diff, ensuring that the commit message reflects all changes.
  • AI-Powered Commit Message Generation: Uses Ollama's AI models to generate concise commit messages based on the detected changes in your repository.
  • Customizable Model Selection: Supports specifying different AI models via a command-line argument, allowing you to choose the model that best suits your needs.

Prerequisites

Before using the script, make sure you have the following installed:

  • Node.js (v16 or above)
  • npm (Node Package Manager)
  • Git (Git version control system) installed and initialized in your project
  • Ollama CLI with access to the required AI models (e.g., llama3.1:8b, llama3.2-vision:90b)

You can download Ollama from here.

Preview

My GIF

Installation

Step 1: Install Dependencies

Make sure you have Node.js and npm installed. Then, install the necessary dependencies by running the following command:

npm install -g commit-generate-ollama

Step 2: Install Ollama

Follow the instructions on the Ollama website to install the Ollama CLI and set up the required models.

Recommend

if you install ollama I recommend that if you want to use any ai for the first time, run (optional if you want to use default model) :

ollama run llama3.1:8b

first so that you don't have to wait long while commit-generate-ollama is running and you can track the download status.

You can find more available models on the Ollama Library.

ollama run <Your ai model you want to use>

Step 3: Ensure Git is Initialized

Make sure you have initialized a Git repository in your project directory. You can check this by running:

git status

If your project isn't initialized with Git, you can do so by running:

git init

Usage

To run the script, use the following command:

commit-generate-ollama [--model_name]

Command Options:

  • --model_name: Optional. This argument specifies the AI model from Ollama that will be used for generating the commit message. You can use models like llama3.1:8b or llama3.2-vision:90b. If this argument is not provided, the default model llama3.1:8b will be used.

Examples

1. Using the Default Model (llama3.1:8b)

To generate a commit message using the default model (llama3.1:8b), simply run:

commit-generate-ollama

2. Using a Specific Model

To use a different Ollama model, such as llama3.2-vision:90b, run:

commit-generate-ollama --llama3.2-vision:90b

You can find more available models on the Ollama Library.

How It Works

The script operates in the following sequence:

  1. Stage All Changes: It runs git add . to stage all the changes in your working directory, ensuring that the changes are tracked.
  2. Fetch Git Diff: It retrieves the Git diff for all staged changes using git diff --cached, which gives a summary of all changes.
  3. Generate Commit Message: It sends the Git diff to an AI model (from Ollama) via a temporary file to generate a concise and meaningful commit message. The AI model is instructed not to include any code, comments, or suggestions, and only return the commit message.
  4. Display the Commit Message: After receiving the response from Ollama, the commit message is displayed in the terminal.
  5. Stop the Model: After generating the commit message, the Ollama model is stopped to free up resources.

Key Functions

getGitDiff

This function stages all changes and fetches the Git diff for those changes. It ensures that the script works with the most recent changes, whether they are in the staging area or the working directory.

callOllamaFromFile

This function sends the Git diff to Ollama using a temporary file, which serves as input to the AI model. The AI model generates a concise commit message in response.

generateCommitMessage

This is the main function of the script. It coordinates the staging of changes, fetching the diff, and calling the AI model to generate the commit message.

Troubleshooting

If you encounter issues while running the script, try the following steps:

  1. Ensure Git is Initialized: Make sure your project is a Git repository by running git status.
  2. Check Ollama Model Availability: Verify that the AI model you specified is available and can be accessed by Ollama.
  3. Ensure Changes Exist: The script requires there to be changes to commit. If no changes are present in the repository, it will not be able to generate a commit message.
  4. Model Issues: If you experience issues with the Ollama model, check for any model-specific limitations or errors in the Ollama documentation.

Modifying the Script

If you'd like to modify the default AI model or change the prompt used to generate commit messages, you can do so by editing the script file located at:

C:\Users\<Your Username>\AppData\Roaming\npm\node_modules\commit-generate-ollama\index.js

You can update the default model name or customize the prompt according to your preferences.

How to delete ollama ai-model

You can go to

C:\Users\<Your Username>\.ollama\models\blobs

you can delete the model as you wish.

Contributing

Feel free to fork the repository, submit issues, and create pull requests. Contributions are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.