Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from tools.visit_webpage import VisitWebpageTool
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
@@ -20,14 +21,20 @@ from Gradio_UI import GradioUI
|
|
| 20 |
# return "What magic will you build ?"
|
| 21 |
|
| 22 |
@tool
|
| 23 |
-
def todays_useless_fact() -> str:
|
| 24 |
"""Fetches today's useless fact from an external public API.
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
response = requests.get("https://uselessfacts.jsph.pl/api/v2/facts/today")
|
| 28 |
if response.status_code == 200:
|
| 29 |
data = response.json()
|
| 30 |
-
return data.get(
|
| 31 |
else:
|
| 32 |
return f"Failed to fetch fact: {response.status_code}"
|
| 33 |
except Exception as e:
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from tools.visit_webpage import VisitWebpageTool
|
| 8 |
+
from datetime import datetime
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
| 21 |
# return "What magic will you build ?"
|
| 22 |
|
| 23 |
@tool
|
| 24 |
+
def todays_useless_fact(date: datetime) -> str:
|
| 25 |
"""Fetches today's useless fact from an external public API.
|
| 26 |
+
Args:
|
| 27 |
+
date: the datetime value for the specified time zone retrieved from get_current_time_in_timezone.
|
| 28 |
"""
|
| 29 |
try:
|
| 30 |
+
# Format date as YYYY-MM-DD (API only supports "today" or "random")
|
| 31 |
+
formatted_date = date.strftime("%Y-%m-%d")
|
| 32 |
+
|
| 33 |
+
# API doesn't actually support querying by date, so we just show today's
|
| 34 |
response = requests.get("https://uselessfacts.jsph.pl/api/v2/facts/today")
|
| 35 |
if response.status_code == 200:
|
| 36 |
data = response.json()
|
| 37 |
+
return f"On {formatted_date}, here's a useless fact: {data.get('text', 'No fact found.')}"
|
| 38 |
else:
|
| 39 |
return f"Failed to fetch fact: {response.status_code}"
|
| 40 |
except Exception as e:
|