csponchiado commited on
Commit
9276a9f
·
verified ·
1 Parent(s): 50f9a7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -46,6 +46,31 @@ def do_search_usint_search_term(query: str) -> str:
46
  except Exception as e:
47
  return f"Error fetching results '{query}': {str(e)}"
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  final_answer = FinalAnswerTool()
51
  model = HfApiModel(
@@ -64,7 +89,7 @@ with open("prompts.yaml", 'r') as stream:
64
 
65
  agent = CodeAgent(
66
  model=model,
67
- tools=[do_search_usint_search_term, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,
 
46
  except Exception as e:
47
  return f"Error fetching results '{query}': {str(e)}"
48
 
49
+ @tool
50
+ def search_wikipedia(query: str) -> str:
51
+ """
52
+ Fetches a summary of a Wikipedia page for a given query.
53
+ Args:
54
+ query: The search term to look up on Wikipedia.
55
+ Returns:
56
+ str: A summary of the Wikipedia page if successful, or an error message if the request fails.
57
+ Raises:
58
+ requests.exceptions.RequestException: If there is an issue with the HTTP request.
59
+ """
60
+ url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{query}"
61
+
62
+ try:
63
+ response = requests.get(url)
64
+ response.raise_for_status()
65
+
66
+ data = response.json()
67
+ title = data["title"]
68
+ extract = data["extract"]
69
+
70
+ return f"Summary for {title}: {extract}"
71
+
72
+ except requests.exceptions.RequestException as e:
73
+ return f"Error fetching Wikipedia data: {str(e)}"
74
 
75
  final_answer = FinalAnswerTool()
76
  model = HfApiModel(
 
89
 
90
  agent = CodeAgent(
91
  model=model,
92
+ tools=[search_wikipedia, do_search_usint_search_term, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
93
  max_steps=6,
94
  verbosity_level=1,
95
  grammar=None,