An AI-powered tool to automatically comment code using local Ollama models.
Project description
AI Code Commenter
An intelligent command-line tool that uses local Ollama models to automatically generate high-quality, structured comments for your code.
The AI Code Commenter is designed for developers who value security, customization, and efficiency. By leveraging the power of local Large Language Models (LLMs), it offers several key advantages:
- 🔒 Code Security & Privacy: Your code is never sent to a third-party API. All processing happens entirely on your local machine, ensuring your intellectual property remains private and secure.
- ⚙️ Exhaustive Customization: The tool is not hardcoded for any specific language or style. Through simple text files (format.txt for content and syntax.txt for style), you can adapt it to any programming language, codebase, or team's coding standards.
- 🚀 Workflow Automation: Quickly document a single file or an entire project with a single command, saving you time and improving the maintainability of your code.
Features
- Local First: Operates entirely offline using your own Ollama instance.
- Highly Configurable: Define comment content and syntax using simple text files.
- CLI-Based: Easy to integrate into scripts and automated workflows.
- Batch Processing: Run on a single file or recursively through an entire folder.
- Intelligent Setup: Automatically checks for Ollama, manages models, and sets up user-friendly configuration files on the first run.
Installation & Setup
Follow these steps to get the commenter tool up and running.
Step 1: Install Ollama
The commenter tool requires Ollama to be running on your system.
-
Linux & macOS: Run the following command in your terminal.
curl \-fsSL https://ollama.com/install.sh | sh -
Windows: Download and run the installer from the Ollama website.
After installing, you need to pull a model. llama3 is a great choice for quality. For faster performance on less powerful hardware, phi3:mini is an excellent alternative.
Pull a high-quality model (recommended)
ollama pull llama3
# Or pull a smaller, faster model
ollama pull phi3:mini
Important: Make sure the Ollama application is running before you use the commenter tool.
Step 2: Install the Commenter Tool
Install the tool directly from PyPI using pip.
pip install ai-code-commenter-vraj0703
Step 3: First-Time Configuration
The first time you run the config command, the tool will automatically create a configuration directory and default templates on your system.
commenter config
This command will:
- Verify that Ollama is installed.
- Create a folder at
\~/.config/commenter/(this path works for Linux, macOS, and Windows). - Copy default
format.txtandsyntax.txtfiles into it, which you can then customize.
Configuration
You can easily configure the tool to fit your needs using the config command.
Setting the Ollama Model
You can tell the commenter which Ollama model to use. If the model isn't downloaded, the tool will pull it for you.
commenter config --model phi3:mini
Customizing Comment Templates
The real power of this tool comes from its configurable templates. The config command allows you to point the tool to your own custom template files.
Example for a project using custom Java templates
commenter config --format-path "/path/to/my/java\_format.txt" --syntax-path "/path/to/my/java\_syntax.txt"
If you don't set custom paths, the tool will use the default files located in \~/.config/commenter/.
format.txt - The Content and Structure
This file controls what goes inside your comments. You can define placeholders for the AI to fill in.
Example format.txt:
Author: AI Assistant
Date: <CURRENT_DATE>
Description: <A high-level summary of the file's purpose.>Functions:- <function_name_1>: <Brief description of what this function does.>
syntax.txt - The Comment Style
This file tells the AI how to write the comment for a specific language.
Example syntax.txt for Java/JavaScript:
The entire comment block must be a valid documentation comment. It must start with `/**` on its own line, each line must begin with a ` * `, and it must end with ` */` on its own line.
Example syntax.txt for Python:
Every single line of the comment block must start with a `#` character followed by a space.
Usage
Once configured, using the tool is simple. Use the run command followed by the path to your code.
Commenting a Single File
commenter run /path/to/your/file.py
Commenting an Entire Folder
The tool will find and comment on all supported source files within the folder and its subdirectories.
commenter run /path/to/your/project/
Troubleshooting
- "Ollama is not installed" Error:
- Ensure the Ollama desktop application is running.
- Make sure you have run the Ollama installation script, and the ollama command is available in your system's PATH.
- Timeout Errors:
- The first time you use a model, Ollama needs to load it into memory, which can be slow. Try "warming up" the model by running
ollama run \<your\_model\_name\> "Hello\!"in your terminal first. - Consider using a smaller model (phi3:mini) for faster processing by running
commenter config --model phi3:mini.
- The first time you use a model, Ollama needs to load it into memory, which can be slow. Try "warming up" the model by running
- Resetting Configuration:
- If your configuration files get corrupted, you can safely delete the
\~/.config/commenterdirectory. The next time you run commenter config, the folder and default files will be recreated.
- If your configuration files get corrupted, you can safely delete the
Contributing & Support
This project is open source. If you find a bug or have a feature request, please open an issue on our GitHub repository.
- GitHub Repository: vraj0703/commenter
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_code_commenter_vraj0703-0.0.6.tar.gz.
File metadata
- Download URL: ai_code_commenter_vraj0703-0.0.6.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf8e94f496e021844523adfab1b2a6c45a8544b685b02c12d98d511b30e3b622
|
|
| MD5 |
3e548439ad407e1237c16c2c8a59e176
|
|
| BLAKE2b-256 |
ab101489f8ee4268fd00897bb2551b5126da0235d6aa25ef8206062269c2b4fe
|
File details
Details for the file ai_code_commenter_vraj0703-0.0.6-py3-none-any.whl.
File metadata
- Download URL: ai_code_commenter_vraj0703-0.0.6-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e081c900c81b9c8ec3d09c972ab5d631a2d1cbb158b8e1284ab4873f8a122179
|
|
| MD5 |
6df529f6c6f4c7a266d41feea2bdfa85
|
|
| BLAKE2b-256 |
dacce9d4cfbe083fd6fae3f34374611deb003349e96f15843293742c5370cb57
|