tiantian-paris commited on
Commit
6970b71
·
1 Parent(s): 4482d39

add send mail tools

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -10,12 +10,15 @@ import requests
10
  import pytz
11
  import yaml
12
  import numpy as np
 
 
13
 
14
  from tools.final_answer import FinalAnswerTool
15
  from tools.visit_webpage import VisitWebpageTool
16
  from tools.web_search import DuckDuckGoSearchTool
17
  from typing import Optional, Tuple
18
-
 
19
  model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
20
  model = HfApiModel(
21
  max_tokens=2096,
@@ -36,6 +39,31 @@ model = HfApiModel(
36
  visit_webpage = VisitWebpageTool()
37
  web_search = DuckDuckGoSearchTool()
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  @tool
40
  def provide_my_information(query: str) -> str:
41
  """
@@ -92,12 +120,14 @@ agent = CodeAgent(
92
  )
93
 
94
 
 
95
  def chatbot_response_json(user_input):
96
  my_info = None
97
  user_input = user_input.lower()
98
  with open("info/info.json", 'r') as file:
99
  my_info = json.load(file)
100
-
 
101
  if "who" in user_input or "about" in user_input or "introduce" in user_input or "presentation" in user_input:
102
  return f" {my_info['introduction']}."
103
  elif "name" in user_input:
 
10
  import pytz
11
  import yaml
12
  import numpy as np
13
+ import smtplib
14
+ import os
15
 
16
  from tools.final_answer import FinalAnswerTool
17
  from tools.visit_webpage import VisitWebpageTool
18
  from tools.web_search import DuckDuckGoSearchTool
19
  from typing import Optional, Tuple
20
+ MY_EMAIL="[email protected]"
21
+ MY_PASSWORD = os.getenv('gmail')
22
  model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
23
  model = HfApiModel(
24
  max_tokens=2096,
 
39
  visit_webpage = VisitWebpageTool()
40
  web_search = DuckDuckGoSearchTool()
41
 
42
+ @tool
43
+ def send_message(query: str) -> str:
44
+ """
45
+ send a message to me directly
46
+
47
+ Args:
48
+ query: The user's question or request for information.
49
+
50
+ Returns:
51
+ str: A response containing the requested information.
52
+ """
53
+ try:
54
+ # Create the email message
55
+ with smtplib.SMTP("smtp.gmail.com") as connection:
56
+ connection.starttls()
57
+ connection.login(MY_EMAIL, MY_PASSWORD)
58
+ connection.sendmail(from_addr=MY_EMAIL,
59
+ to_addrs=MY_EMAIL,
60
+ msg=f"Subject: message from chatbot \n\n{query}")
61
+
62
+ return f"Message sent to tianqing successfully!"
63
+ except Exception as e:
64
+ return f"Failed to send email: {e}"
65
+
66
+
67
  @tool
68
  def provide_my_information(query: str) -> str:
69
  """
 
120
  )
121
 
122
 
123
+
124
  def chatbot_response_json(user_input):
125
  my_info = None
126
  user_input = user_input.lower()
127
  with open("info/info.json", 'r') as file:
128
  my_info = json.load(file)
129
+ if "send message" in user_input:
130
+ return send_message(user_input)
131
  if "who" in user_input or "about" in user_input or "introduce" in user_input or "presentation" in user_input:
132
  return f" {my_info['introduction']}."
133
  elif "name" in user_input: