diff --git a/main.py b/main.py index 35bccac..77c91d0 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,26 @@ def main(): else: args.recipients = [args.recipients] - + # get user input + update = input(f"What new information would you like to tell your recipients?\n") + subject = input(f"\nWhat would you like the subject of the email to be?\n") + + # loop through recipients and create a draft for each + for address in args.recipients: + # get the most recent email thread from the specified recipient + query = f"from:{address}" + last_thread_id = gmail.get_most_recent_message(query) + thread = gmail.get_thread(last_thread_id) + logger.info("Retrieved last thread with target recipients") + + # generate the draft and create it on gmail + content = openai.write_draft(thread, update, gmail.me, address) + logger.info("Draft has been generated, OpenAI call complete") + gmail.gmail_create_draft(subject, content, address) + logger.info( + f"\nYour draft has been created!\nRecipient: {address}"+ + "\nSubject: {subject}\nContent: {content}\n" + ) # if batch, for loop through dict # if reply, get most recent email thread from recipient, read and generate reply @@ -46,28 +65,12 @@ def main(): # get_all_threads(query) which takes a from:email_address query and returns a string containing all threads # might need to implement tiktoken for this so we don't run over openai limit # modify openai prompt wording to be neutral for reply/new + # modify gmail_create_draft to take a reply? boolean - # get the most recent email thread from the specified recipient - query = f"from:{args.recipients}" - last_thread_id = gmail.get_most_recent_message(query) - thread = gmail.get_thread(last_thread_id) - logger.info("Retrieved last thread with target recipients") - - # get user input - update = input(f"What would you like to tell {args.recipients}?\n") - subject = input(f"\nWhat would you like the subject of the email to be?\n") - # generate the draft and create it on gmail - content = openai.write_draft(thread, update, gmail.me, args.recipients) - logger.info("Draft has been generated, OpenAI call complete") - gmail.gmail_create_draft(subject, content, args.recipients) - print( - f"\nYour draft has been created!\nRecipient: {args.recipients}"+ - "\nSubject: {subject}\nContent: {content}\n" - ) if __name__ == "__main__": main() diff --git a/openai.py b/openai.py index 26c4027..9f4013f 100644 --- a/openai.py +++ b/openai.py @@ -18,7 +18,7 @@ def auth(self): def write_draft(self, thread, update, myself, other): user_content = f"Below is a chain of messages between myself, {myself}, and {other}. I would like to draft a response to {other} based on this interaction and the following update. Please incorporate this new information and formulate a response to {other} that I can send. Only write the body of the response, do not include a subject. Make sure you use the previous thread as context for your response. \n\nPAST MESSAGES: \n###\n{thread}\n###\n\n NEW INFORMATION TO RELAY:\n###\n{update}\n###" self.logger.info(f'Chat Completion prompt is: "{user_content}"') - model = "gpt-3.5-turbo-16k" # Use gpt-4 if you have access + model = "gpt-3.5-turbo" # Use gpt-4 if you have access self.logger.info(f'Chat Completion model is: {model}') gpt_response = openai.ChatCompletion.create( model=model, messages=[{"role": "user", "content": user_content}] diff --git a/pyvenv.cfg b/pyvenv.cfg index 7d02e24..5fa78d9 100644 --- a/pyvenv.cfg +++ b/pyvenv.cfg @@ -2,4 +2,4 @@ home = /Library/Frameworks/Python.framework/Versions/3.11/bin include-system-site-packages = false version = 3.11.5 executable = /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 -command = /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -m venv /Users/davidenders/Desktop/gmail-automate +command = /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -m venv /Users/davidenders/Desktop/gmail-automation diff --git a/requirements.txt b/requirements.txt index 7d3856f..c961f04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ beautifulsoup4==4.12.2 cachetools==5.3.1 certifi==2023.7.22 charset-normalizer==3.2.0 +et-xmlfile==1.1.0 frozenlist==1.4.0 google-api-core==2.11.1 google-api-python-client==2.97.0 @@ -16,18 +17,24 @@ googleapis-common-protos==1.60.0 httplib2==0.22.0 idna==3.4 multidict==6.0.4 +numpy==1.26.1 oauthlib==3.2.2 openai==0.28.0 +openpyxl==3.1.2 +pandas==2.1.1 protobuf==4.24.2 pyasn1==0.5.0 pyasn1-modules==0.3.0 pyparsing==3.1.1 +python-dateutil==2.8.2 +pytz==2023.3.post1 requests==2.31.0 requests-oauthlib==1.3.1 rsa==4.9 six==1.16.0 soupsieve==2.4.1 tqdm==4.66.1 +tzdata==2023.3 uritemplate==4.1.1 urllib3==1.26.16 yarl==1.9.2