Spaces:
Sleeping
Sleeping
test api
Browse files
app.py
CHANGED
|
@@ -9,14 +9,35 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +76,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer,
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_local_news_headlines(location: str) -> str:
|
| 13 |
+
"""
|
| 14 |
+
A tool that fetches top local news headlines for a given location using Currents API.
|
| 15 |
Args:
|
| 16 |
+
location: The name of the location or a keyword for the news.
|
| 17 |
+
Returns:
|
| 18 |
+
A string with the top headlines or an error message.
|
| 19 |
"""
|
| 20 |
+
import requests
|
| 21 |
+
try:
|
| 22 |
+
url = "https://api.currentsapi.services/v1/search"
|
| 23 |
+
params = {
|
| 24 |
+
"keywords": location,
|
| 25 |
+
"language": "en",
|
| 26 |
+
"apiKey": "9kgcb14yVbcFQULH9tMpF-ZS0bDx9ISbP7oJEk_lcN7pbpWu",
|
| 27 |
+
"limit": 5 # Limit to 5 headlines
|
| 28 |
+
}
|
| 29 |
+
response = requests.get(url, params=params)
|
| 30 |
+
data = response.json()
|
| 31 |
+
if data.get("status") == "ok":
|
| 32 |
+
headlines = [article["title"] for article in data.get("news", [])]
|
| 33 |
+
if headlines:
|
| 34 |
+
return f"Top headlines in {location}:\n" + "\n".join(headlines)
|
| 35 |
+
else:
|
| 36 |
+
return f"No news found for {location}."
|
| 37 |
+
else:
|
| 38 |
+
return "Error fetching news: " + data.get("message", "Unknown error")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error fetching news: {str(e)}"
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
+
tools=[final_answer, get_local_news_headlines], ## add your tools here (don't remove final answer)
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|