yooke commited on
Commit
e3e1920
·
verified ·
1 Parent(s): 1fb1374

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +15 -1
agent.py CHANGED
@@ -75,6 +75,19 @@ def duckduckgo_search(query: str) -> str:
75
  return f"An error occurred during DuckDuckGo search: {e}"
76
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  # load the system prompt from the file
79
  # Ensure this file exists and has the content from Step 2
80
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
@@ -84,7 +97,8 @@ sys_msg = SystemMessage(content=system_prompt)
84
  tools = [
85
  wiki_search,
86
  duckduckgo_search,
87
- web_search, # *** ADDED TAVILY WEB SEARCH ***
 
88
  ]
89
 
90
 
 
75
  return f"An error occurred during DuckDuckGo search: {e}"
76
 
77
 
78
+ @tool
79
+ def arithmetic(expression: str) -> str:
80
+ """执行数学计算并返回结果。支持基本的算术运算如加减乘除、幂运算等。"""
81
+ try:
82
+ # 使用Python的eval函数安全地计算表达式
83
+ # 限制只能使用基本算术运算,不允许导入模块或执行其他危险操作
84
+ allowed_names = {"__builtins__": {}}
85
+ allowed_symbols = {}
86
+ result = eval(expression, allowed_names, allowed_symbols)
87
+ return str(result)
88
+ except Exception as e:
89
+ return f"计算表达式时出错: {e}"
90
+
91
  # load the system prompt from the file
92
  # Ensure this file exists and has the content from Step 2
93
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
 
97
  tools = [
98
  wiki_search,
99
  duckduckgo_search,
100
+ web_search,
101
+ arithmetic,
102
  ]
103
 
104