This repository contains a Python application that uses GPT-3.5, an AI language model by OpenAI, to automatically refactor code in a given repository. The application processes code files in various languages, refactors them using the GPT-3.5 API, and saves the refactored code along with a summary of the changes.
- Docker
- Docker Compose
- An OpenAI API key
- Clone the repository:
git clone https://github.com/TortoiseWolfe/AutoFactor
cd AutoFactor
- Create a
.env
file in the root directory of the project and add your OpenAI API key:
OPENAI_API_KEY=your_actual_api_key_here
Replace your_actual_api_key_here
with your actual API key.
-
Copy the code you want to refactor into the
your_repo
directory. -
Build the Docker container:
docker-compose build
- Run the container:
docker-compose up -d
-
The refactored code will replace the original code in the
your_repo
directory. The original code will be backed up in theoriginal_code
directory. -
Check the logs for the summary of changes:
cat your_repo/logs/output.log
To add support for more languages, update the extension_to_language function in the main.py file with the desired file extension and language name.
def extension_to_language(extension):
languages_map = {
"cs": "C#",
"js": "JavaScript",
"py": "Python",
# Add more file extensions and languages as needed
}
return languages_map.get(extension.lower())
This project is open source under the MIT License. See the LICENSE file for details.