ai commit generate toolkit
npm install commit-generate-ollamallama3.1:8b, llama3.2-vision:90b)
bash
npm install -g commit-generate-ollama
`
$3
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) :
`bash
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.
`bash
ollama run
`
$3
Make sure you have initialized a Git repository in your project directory. You can check this by running:
`bash
git status
`
If your project isn't initialized with Git, you can do so by running:
`bash
git init
`
Usage
To run the script, use the following command:
`bash
commit-generate-ollama [--model_name]
`
$3
- --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
$3
To generate a commit message using the default model (llama3.1:8b), simply run:
`bash
commit-generate-ollama
`
$3
To use a different Ollama model, such as llama3.2-vision:90b, run:
`bash
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
$3
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.
$3
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.
$3
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\\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\\.ollama\models\blobs
``