CommentRescueAI automatically adds meaningful comments and docstrings to your Python code using AI, making your code more readable and maintainable.
- AI-powered comment generation for Python code
- Automatic docstring creation for functions and classes
- Intelligent inline comments for complex code sections
- Local processing using Ollama
- Fully offline operation - no data leaves your system
- Lightweight model (Llama 3.2) that runs well on low-end devices
- Customizable settings through constants.ts
class Product(models.Model):
name = models.CharField(max_length=200)
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="products")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def clean(self):
if self.price <= 0:
raise ValidationError("Price must be greater than zero.")
class Product(models.Model):
"""
Represents a product in the catalog.
Attributes:
name (str): The name of the product.
description (str): A brief description of the product.
price (float): The price of the product.
category (Category): The category this product belongs to.
created_at (datetime): The timestamp when the product was created.
updated_at (datetime): The timestamp when the product was last updated.
Raises:
ValidationError: If the price is not greater than zero.
"""
name = models.CharField(max_length=200)
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="products")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def clean(self):
"""
Validates the product's price.
Raises:
ValidationError: If the price is not greater than zero.
"""
# Check if the price is less than or equal to zero
if self.price <= 0:
raise ValidationError("Price must be greater than zero.")
- Processing time: ~50-60 seconds for 100 lines of code on mid-range hardware (tested on AMD Ryzen 5600H with NVIDIA RTX 1650 4GB GPU)
- Runs in background: Feel free to switch to other windows while processing - the extension works asynchronously without blocking your workflow
- Resource-friendly: Uses Llama 3.2, optimized for running on consumer-grade hardware
- VS Code 1.96.0 or higher
- Ollama installed on your system
- Install Ollama from ollama.ai
- Install this extension from VS Code Marketplace
- Run the command
CommentRescueAI: Install Required Model
(This will download the necessary AI model)
- Open a Python file
- Press
Ctrl+Shift+P
(Windows/Linux) orCmd+Shift+P
(macOS) - Type "Add AI comments" and select
CommentRescueAI: Add AI comments
- Continue working in other windows while the extension processes your code
- You'll receive a notification when comments have been added
The extension will analyze your code and add appropriate comments and docstrings.
"Here is the enhanced code with suitable inline comments and docstring added:"
[Your enhanced code]
"Let me know if you need any clarification..."
Simply remove these extra lines manually if they appear. We're working on fixing this rare issue in future updates.
You can customize the extension's behavior by modifying constants.ts
:
BASE_URL
: Configure the Ollama API endpointMODEL_NAME
: Change the AI model being usedSYSTEM_PROMPT
: Customize the prompt that guides comment generationMODEL_SIZE
: Specify the model size configurationOLLAMA_GPU_OPTIONS
: Adjust GPU-related settings for Ollama
To modify settings:
- Locate
constants.ts
in the extension's source code - Update the desired constants
- Rebuild the extension
Example constants.ts
configuration:
export const BASE_URL = "http://localhost:11434";
export const MODEL_NAME = "llama3.2";
export const SYSTEM_PROMPT = "You are an expert programmer...";
- Model installation might take several minutes depending on your internet connection
- Requires Ollama to be running in the background
- Comment generation takes ~1 minute per 100 lines of code - this is expected behavior due to local processing
- The model might occasionally include extra header/footer text around the enhanced code (manual removal required - fix in progress)
Initial release of CommentRescueAI:
- Basic comment generation
- Docstring support
- Ollama integration
- Offline processing capability
- Background operation support
- Configurable settings through constants.ts
Fixed issue with Axios
- node_modules not getting published
Fixed issue with Output Channel
- changes:
exec
method tospawn
Enjoy!