Spaces:
Sleeping
Sleeping
gera
commited on
Commit
•
2cc6fd0
1
Parent(s):
354e8e7
send emails on new thread
Browse files
app.py
CHANGED
@@ -3,12 +3,24 @@ from time import sleep
|
|
3 |
from json import loads as json_loads
|
4 |
import gradio as gr
|
5 |
import openai
|
|
|
6 |
|
7 |
client = openai.OpenAI()
|
8 |
|
9 |
assistant_id = "asst_NHnYFIdpvioacAJqWYMchJHI"
|
10 |
vector_id = "vs_sqT4VRRTwkH7JPr3AT8CpoXV"
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def chat(user_message, history, state):
|
13 |
if (state is None) or (not state['user']):
|
14 |
gr.Warning("You need to authenticate first")
|
@@ -24,6 +36,7 @@ def chat(user_message, history, state):
|
|
24 |
}
|
25 |
)
|
26 |
state['thread'] = thread
|
|
|
27 |
|
28 |
client.beta.threads.messages.create(
|
29 |
thread_id=thread.id,
|
|
|
3 |
from json import loads as json_loads
|
4 |
import gradio as gr
|
5 |
import openai
|
6 |
+
import yagmail
|
7 |
|
8 |
client = openai.OpenAI()
|
9 |
|
10 |
assistant_id = "asst_NHnYFIdpvioacAJqWYMchJHI"
|
11 |
vector_id = "vs_sqT4VRRTwkH7JPr3AT8CpoXV"
|
12 |
|
13 |
+
def send_email(thread):
|
14 |
+
mail_from = os_getenv("MAIL_FROM")
|
15 |
+
mail=yagmail.SMTP(
|
16 |
+
mail_from,
|
17 |
+
os_getenv("MAIL_PASS"),
|
18 |
+
host=os_getenv("MAIL_HOST"),
|
19 |
+
port=int(os_getenv("MAIL_PORT"))
|
20 |
+
)
|
21 |
+
mail.send(mail_from,f"New thread {thread.id}")
|
22 |
+
|
23 |
+
|
24 |
def chat(user_message, history, state):
|
25 |
if (state is None) or (not state['user']):
|
26 |
gr.Warning("You need to authenticate first")
|
|
|
36 |
}
|
37 |
)
|
38 |
state['thread'] = thread
|
39 |
+
send_email(thread)
|
40 |
|
41 |
client.beta.threads.messages.create(
|
42 |
thread_id=thread.id,
|