-
Notifications
You must be signed in to change notification settings - Fork 4
/
GPT3-outlook.py
40 lines (33 loc) · 1.3 KB
/
GPT3-outlook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import win32com.client
import bs4
import openai
import time
openai.api_key = "" # obtained via https://platform.openai.com/account/api-keys
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
signature = "" # your signature, use \n for newline
while True:
messages = inbox.Items
found_unread = False
for message in messages:
if message.UnRead:
soup = bs4.BeautifulSoup(message.Body, "html.parser")
content = soup.get_text().split("From:")[0]
response = openai.Completion.create(
engine="text-davinci-003",
prompt="Respond to this email with a positive attitude, absolutely NEVER use any names. End with kind regards without a name: " + content,
max_tokens=2000,
n=1,
stop=None,
temperature=0.55,
).get("choices")[0].get("text")
reply = message.Reply()
reply.Body = response + "\n\n\n" + signature
reply.Subject = "Sv: " + message.Subject
reply.Send()
message.UnRead = False
found_unread = True
if not found_unread:
print("Waiting for incoming emails..")
time.sleep(1200)