Update app.py
Browse files
app.py
CHANGED
|
@@ -19,19 +19,20 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
-
def get_news_headlines(
|
| 23 |
-
"""
|
|
|
|
| 24 |
Args:
|
| 25 |
-
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
hl = DuckDuckGoSearchTool()
|
| 29 |
-
results = hl.run(f"{
|
| 30 |
-
|
|
|
|
| 31 |
except Exception as e:
|
| 32 |
-
import traceback
|
| 33 |
-
|
| 34 |
-
return f"Error fetching the news headlines: {e}."
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
+
def get_news_headlines(topic: str = "latest") -> str:
|
| 23 |
+
"""Fetches the three most recent news headlines for a given topic.
|
| 24 |
+
|
| 25 |
Args:
|
| 26 |
+
topic: The subject to search headlines for (defaults to "latest").
|
| 27 |
"""
|
| 28 |
try:
|
| 29 |
hl = DuckDuckGoSearchTool()
|
| 30 |
+
results = hl.run(f"{topic} news")
|
| 31 |
+
headlines = results[:3] if isinstance(results, list) else results.split("\n")[:3]
|
| 32 |
+
return "\n".join(f"{i+1}. {h}" for i, h in enumerate(headlines))
|
| 33 |
except Exception as e:
|
| 34 |
+
import traceback; traceback.print_exc()
|
| 35 |
+
return f"Error fetching news headlines: {e}"
|
|
|
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|