Spaces:
Running
Running
Add a tool
Browse files
app.py
CHANGED
@@ -51,7 +51,31 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
51 |
except Exception as e:
|
52 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
|
|
|
|
55 |
|
56 |
|
57 |
final_answer = FinalAnswerTool()
|
@@ -78,7 +102,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
78 |
|
79 |
agent = CodeAgent(
|
80 |
model=model,
|
81 |
-
tools=[final_answer, image_generation_tool, web_search_tool, model_downloads_tool, object_detection_tool], ## add your tools here (don't remove final answer)
|
82 |
max_steps=6,
|
83 |
verbosity_level=1,
|
84 |
grammar=None,
|
|
|
51 |
except Exception as e:
|
52 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
53 |
|
54 |
+
@tool
|
55 |
+
def search_wikipedia(query: str) -> str:
|
56 |
+
"""
|
57 |
+
Fetches a summary of a Wikipedia page for a given query.
|
58 |
+
Args:
|
59 |
+
query: The search term to look up on Wikipedia.
|
60 |
+
Returns:
|
61 |
+
str: A summary of the Wikipedia page if successful, or an error message if the request fails.
|
62 |
+
Raises:
|
63 |
+
requests.exceptions.RequestException: If there is an issue with the HTTP request.
|
64 |
+
"""
|
65 |
+
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{query}"
|
66 |
+
|
67 |
+
try:
|
68 |
+
response = requests.get(url)
|
69 |
+
response.raise_for_status()
|
70 |
+
|
71 |
+
data = response.json()
|
72 |
+
title = data["title"]
|
73 |
+
extract = data["extract"]
|
74 |
+
|
75 |
+
return f"Summary for {title}: {extract}"
|
76 |
|
77 |
+
except requests.exceptions.RequestException as e:
|
78 |
+
return f"Error fetching Wikipedia data: {str(e)}"
|
79 |
|
80 |
|
81 |
final_answer = FinalAnswerTool()
|
|
|
102 |
|
103 |
agent = CodeAgent(
|
104 |
model=model,
|
105 |
+
tools=[final_answer, image_generation_tool, web_search_tool, model_downloads_tool, object_detection_tool, search_wikipedia], ## add your tools here (don't remove final answer)
|
106 |
max_steps=6,
|
107 |
verbosity_level=1,
|
108 |
grammar=None,
|