-
Notifications
You must be signed in to change notification settings - Fork 4
/
ChatGPT3.5-Turbo-Outlook.py
45 lines (38 loc) · 1.38 KB
/
ChatGPT3.5-Turbo-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
41
42
43
44
45
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.ChatCompletion.create(
model="gpt-3.5-turbo",
max_tokens=2000,
n=1,
stop=None,
temperature=0.55,
messages=[
{"role": "user", "content": content},
]
)
result = ''
for choice in response.choices:
result += choice.message.content
reply = message.Reply()
reply.Body = result + "\n\n\n" + signature
reply.Subject = "Sv: " + message.Subject # 'Sv: ' for swedish mails, other countries use 'Re: '
reply.Send()
message.UnRead = False
found_unread = True
if not found_unread:
print("Waiting for incoming emails..")
time.sleep(1200)