This script leverages OpenAI's ChatGPT to provide assistance in fixing or suggesting solutions for errors in a Python file. It supports two modes of operation: processing the Python code directly or analyzing the output of a Python file via pipe. By interacting with ChatGPT, the script generates suggestions or explanations tailored to the provided Python code or output.
python GPTPythonFixer.py <file_path> [-p | --pipe]
Arguments:
- file_path: The path to the Python file to be fixed or analyzed.
- -p, --pipe: Optional argument. If provided, the script will use the output of the Python file via pipe instead of directly processing the file.
- Reads the specified Python file or captures the output of a Python file via pipe.
- Interacts with ChatGPT to generate suggestions or explanations based on the provided Python code or output.
- If operating on the file directly:
- Prints the suggested code or error explanation.
- Prompts the user to confirm replacing the code in the file.
- Replaces the code in the file if the user confirms.
- Prints the suggested code or error explanation.
- If using the output via pipe:
- Prints the suggested output based on the ChatGPT response.
- Prints the suggested output based on the ChatGPT response.
-
Process Python file directly:
python fix_python_file.py path/to/your/python/file.py
-
Process Python file output via pipe:
python error.py | python fix_python_file.py -p
- The script requires the OpenAI Python package (
openai
) to be installed. - Replace 'YOUR_API_KEY' with your actual OpenAI API key in the script.
- Exercise caution when replacing code in a file and perform adequate testing.
- The script provides a basic example and may not handle all complex code or errors.
- The changes are suggested by ChatGPT and might contain errors.
This project is licensed under the MIT-LICENSE