Skip to main content

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:

  1. Verify that Ollama is installed.
  2. Create a folder at \~/.config/commenter/ (this path works for Linux, macOS, and Windows).
  3. Copy default format.txt and syntax.txt files 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.
  • Resetting Configuration:
    • If your configuration files get corrupted, you can safely delete the \~/.config/commenter directory. The next time you run commenter config, the folder and default files will be recreated.

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.

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

ai_code_commenter_vraj0703-0.0.5.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

ai_code_commenter_vraj0703-0.0.5-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file ai_code_commenter_vraj0703-0.0.5.tar.gz.

File metadata

File hashes

Hashes for ai_code_commenter_vraj0703-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e08a08a9d90d5978150763cd8ace3b7b827ab1e16c13f5783bf729a4ac3e2a84
MD5 9f1b82623d54fe4f632978f53421d048
BLAKE2b-256 965b220a6beb883dcc154ce1b0f2b8750d8169b3e3ef389ee8272f21d8631b16

See more details on using hashes here.

File details

Details for the file ai_code_commenter_vraj0703-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_code_commenter_vraj0703-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c7be825dcdca8c393aaebda755bab2d08d7f2bf726af3088cf167e7bf3665872
MD5 6620b309962f9c9579f6cd56f9bffa95
BLAKE2b-256 235a20b514d1fed7cddc9fba76821eaf52b517e370eb6c3494f26fdc7ceb6204

See more details on using hashes here.

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