Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,29 +33,33 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
-
import
|
| 37 |
-
|
| 38 |
@tool
|
| 39 |
def get_wikipedia_summary(query: str) -> str:
|
| 40 |
-
"""
|
| 41 |
-
A tool that fetches a Wikipedia summary for a given topic.
|
| 42 |
-
|
| 43 |
Args:
|
| 44 |
-
query: The topic to search for in Wikipedia.
|
| 45 |
-
|
| 46 |
Returns:
|
| 47 |
-
A short summary of the topic from Wikipedia.
|
| 48 |
"""
|
| 49 |
-
|
| 50 |
try:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
final_answer = FinalAnswerTool()
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
import wikipediaapi
|
| 37 |
+
|
| 38 |
@tool
|
| 39 |
def get_wikipedia_summary(query: str) -> str:
|
| 40 |
+
""" A tool that fetches a Wikipedia summary for a given topic.
|
|
|
|
|
|
|
| 41 |
Args:
|
| 42 |
+
query (str): The topic to search for in Wikipedia.
|
|
|
|
| 43 |
Returns:
|
| 44 |
+
str: A short summary of the topic from Wikipedia or an error message if the page does not exist.
|
| 45 |
"""
|
|
|
|
| 46 |
try:
|
| 47 |
+
# Initialize the Wikipedia API object
|
| 48 |
+
wiki_wiki = wikipediaapi.Wikipedia('en')
|
| 49 |
+
|
| 50 |
+
# Fetch the page for the given query
|
| 51 |
+
page = wiki_wiki.page(query)
|
| 52 |
+
|
| 53 |
+
# Check if the page exists
|
| 54 |
+
if not page.exists():
|
| 55 |
+
return f"Sorry, no page was found for '{query}' on Wikipedia."
|
| 56 |
+
|
| 57 |
+
# Return a truncated summary (up to 500 characters)
|
| 58 |
+
return f"Here is a short summary of '{query}': {page.summary[:500]}..."
|
| 59 |
+
|
| 60 |
except Exception as e:
|
| 61 |
+
# Catch any unexpected errors and return a user-friendly message
|
| 62 |
+
return f"An error occurred while fetching the Wikipedia summary: {str(e)}"
|
| 63 |
|
| 64 |
|
| 65 |
final_answer = FinalAnswerTool()
|