-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathllmme_bot.py
53 lines (42 loc) · 2.39 KB
/
llmme_bot.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
46
47
48
49
50
51
52
53
import config
import gmail_api as email_api
import llm_reply
import argparse
import time
def main():
try:
# Call the Gmail API
service = email_api.get_service()
botlabel_id = email_api.get_label_id_for_botlabel(service, botname=config.botname)
messages = email_api.gmail_get_unread(service, botname=config.botname)
# call model and respond
for m in messages:
f_from, f_to, f_cc, f_subject = m.get('To', config.my_email), m['From'], m.get('Cc',''), m['Subject']
f_in_reply_to = m.get('Message-ID')
f_references = m.get('References', f_in_reply_to)
f_thread_id = m.get('threadId')
f_message_id = m.get('id')
f_answer = llm_reply.respond(f_from=f_from, f_to=f_to, f_cc=f_cc, f_subject=f_subject, f_context=m['Body'])
if f_answer != "*[DO NOT REPLY]*":
created_message = email_api.gmail_create_message(f_from=f_from, f_to=f_to, f_subject=f_subject,
f_in_reply_to=f_in_reply_to, f_references=f_references,
f_thread_id=f_thread_id, f_answer=f_answer)
email_api.post_draft_or_reply_message(service=service,
created_message=created_message,
reply_automatically=config.reply_automatically)
email_api.mark_as_read_by_bot(service=service, f_message_id=f_message_id, botlabel_id=botlabel_id)
except email_api.HttpError as error:
print(F'An error occurred: {error}')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Run LLMMe Bot")
# parser.add_argument("-c", "--config", type=str, required=True, help="Config file (.py)")
# parser.add_argument("-a", "--credentials", type=str, required=True, help="Google API Credentials")
# parser.add_argument("-t", "--token", required=True, nargs='+', help="Google API Token")
parser.add_argument("-m", "--check_minutes", type=int, required=False, default=0, help="Check every M minutes. Defaults to 0 which means check only once.")
args, unknown = parser.parse_known_args()
while True:
print("Checking emails")
main()
time.sleep(60*args.check_minutes)
if args.check_minutes == 0:
break