berkempeker commited on
Commit
0da9e7c
·
verified ·
1 Parent(s): 4372297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -8,26 +8,29 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
11
  @tool
12
- def solve_math_expression(expression: str) -> str:
13
- """A tool that evaluates a simple math expression.
14
 
15
  Args:
16
- expression: A string containing a basic math expression (e.g., '2 + 2', '5 * 3').
17
 
18
  Returns:
19
- The result of the evaluated expression.
20
  """
21
  try:
22
- # Using eval safely by limiting to numbers and basic operators
23
- allowed_chars = "0123456789+-*/(). "
24
- if all(char in allowed_chars for char in expression):
25
- result = eval(expression)
26
- return f"The result of '{expression}' is: {result}"
 
27
  else:
28
- return "Invalid expression. Use only numbers and basic operators (+, -, *, /)."
29
  except Exception as e:
30
- return f"Error evaluating expression: {str(e)}"
31
 
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+ import requests
12
+
13
  @tool
14
+ def get_wikipedia_summary(topic: str) -> str:
15
+ """A tool that fetches a short summary of a Wikipedia topic.
16
 
17
  Args:
18
+ topic: The topic to search for on Wikipedia.
19
 
20
  Returns:
21
+ A brief summary of the topic from Wikipedia.
22
  """
23
  try:
24
+ url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{topic}"
25
+ response = requests.get(url)
26
+
27
+ if response.status_code == 200:
28
+ data = response.json()
29
+ return data.get("extract", "No summary available.")
30
  else:
31
+ return f"Error: Could not retrieve information for '{topic}'."
32
  except Exception as e:
33
+ return f"An error occurred: {str(e)}"
34
 
35
  @tool
36
  def get_current_time_in_timezone(timezone: str) -> str: