Skip to content

Commit

Permalink
add working parsing, openai broken
Browse files Browse the repository at this point in the history
- getting error about missing attribute "ChatCompletion"
- not sure what has changed, the same code worked last week
  • Loading branch information
davidenders11 committed Oct 17, 2023
1 parent 441396e commit 865e625
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
39 changes: 21 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
2 changes: 1 addition & 1 deletion openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down
2 changes: 1 addition & 1 deletion pyvenv.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 865e625

Please sign in to comment.