An automated Python script fixer powered by Google's Gemini AI model. This tool automatically detects, analyzes, and fixes errors in Python scripts using AI-powered suggestions.
- Automatic error detection and stack trace analysis
- AI-powered error fixing suggestions
- Handles multiple file dependencies
- Iterative fixing attempts with maximum retry limit
- Detailed execution logging
- Support for common Python libraries (pandas, matplotlib, numpy)
- Python 3.7+
- Google Cloud Project
- Required Python packages (see requirements.txt)
- Clone the repository:
git clone https://github.com/cnemri/gemini-code-fixer.git
cd gemini-code-fixer
- Install required packages:
pip install -r requirements.txt
- Set up your Google Cloud Project ID in
main.py
:
project_id = "your-project-id" # Replace with your GCP project ID
-
Place your Python script to be fixed in the same directory as
main.py
and name itscript.py
-
Run the fixer:
python main.py
The tool will:
- Execute your script
- If errors occur, analyze the stack trace
- Generate and apply fixes
- Repeat until the script runs successfully or reaches maximum iterations
- Log all actions in
full_execution_log.json
main.py
- Main execution scriptscript_executor.py
- Handles Python script executiontraceback_parser.py
- Parses error stack traces using Gemini AIfile_handler.py
- Manages file operationsfix_suggester.py
- Generates fix suggestions using Gemini AIexamples/
- Example Python scripts demonstrating common errorsrequirements.txt
- Required Python packages
The repository includes example scripts demonstrating common Python errors:
01-pandas.py
- Pandas DataFrame operations with typos02-matplotlib.py
- Matplotlib plotting with incorrect method names03-numpy.py
- NumPy array operations with dimension mismatches04-combined.py
- Combined usage of multiple libraries with syntax errors
- Script Execution: Runs the target Python script and captures any errors
- Error Analysis: Uses Gemini AI to parse stack traces and identify relevant files
- Context Collection: Gathers contents of all related Python files
- Fix Generation: Sends error context to Gemini AI for fix suggestions
- Fix Application: Applies suggested fixes to the original script
- Verification: Re-runs the script to verify the fix
- Logging: Records all actions and responses in a JSON log file
- Maximum fix attempts: 10 (configurable in
main.py
) - Default Gemini model: "gemini-1.5-flash-002" (configurable)
- Log file:
full_execution_log.json
- Relies on Gemini knowledge. Google search grounding to be implemented.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and feature requests, please use the GitHub Issues section of the repository.