add-comments.py
is a Python script that uses OpenAI's GPT-3 API to automatically generate concise comments and annotations for a Python script. The script inserts comments only where there are no existing comments, and it adds a summary at the top of the script before the import statements.
Before using this script, make sure you have the following:
-
OpenAI API Key: You must have an OpenAI API key set as the
OPENAI_API_KEY
environment variable. You can obtain your API key from OpenAI's platform. -
Python Environment: Ensure you have Python 3 installed on your system.
To use the add-comments.py
script, follow these steps:
-
Save the script with the name
add-comments.py
in your desired directory. -
Open a terminal and navigate to the directory containing
add-comments.py
. -
Run the script by providing the path to the Python script you want to annotate as an argument. For example:
python add-comments.py your_script.py
-
The script will generate concise comments for your Python script and insert them where they make sense. It will also add a summary at the top of the script.
-
The annotated script will be saved in the same directory with the filename prefixed by "annotated_". For example, if your input script is
your_script.py
, the annotated script will be saved asannotated_your_script.py
. -
You can now review and run the annotated script with the added comments.
Here's an example of how to use the script:
python add-comments.py my_script.py
This will analyze my_script.py
, add comments, and save the annotated script as annotated_my_script.py
.
This script is provided under the MIT License. You are free to use, modify, and distribute it as needed.
This script is for educational and convenience purposes. It generates comments based on AI predictions and may not always provide perfect results. It's recommended to review and adjust the generated comments as needed for accuracy and clarity.