Note: this is a proof on concept and may not work as expected. Use at your own risk.
This script uses OpenAI's GPT-3 to classify the importance of unread emails in Gmail and labels them accordingly. The labels used are:
- gptJunk
- gptLow
- gptNormal
- gptImportant
- gptUrgent
To run this script, you need:
- Python 3
- A Google Cloud Platform project with the Gmail API enabled
- Credentials for the Gmail API
- An OpenAI API key
- ==Add the labels listed above to your gmail account before running the script==
- Clone this repository
- Install the required Python packages by running
pip install -r requirements.txt
- Set up the Google Cloud Platform project and the Gmail API credentials by following the instructions here and saving the credentials file as
credentials.json
in the project directory - Obtain an OpenAI API key by following the instructions here
- Save the OpenAI API key to a text file named
openaikey.txt
in the project directory
- (optional) Customize the
prompt.txt
file as desired. - (optional) Modify the model used in openai_api.py (line 25) - text-davinci-0003 by default.
- Run the script by running
python gmail_assist.py
- The script will connect to the Gmail API and find unread emails not already labeled by the script. They will be labeled based on their importance.
What you do with them from there is up to you. The emails will not be modified in any other way. The tags can be used for bulk processing or creating other rules.
To process another account, delete the token.pickle file that was created when you first authenticated and run the script again.
This started as a Thunderbird plugin which had the benefit of running on every new email that comes in. I may try to implement that.
I will accept pull requests from anyone who wants to help build this out more.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- OpenAI for providing the GPT-3 API
- Google for providing the Gmail API