Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,8 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
@@ -33,9 +34,57 @@ 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 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
-
|
| 39 |
|
| 40 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 41 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -56,7 +105,8 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer,
|
|
|
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_ai_safety_updates(category: str = "general", max_results: int = 5) -> str:
|
| 39 |
+
"""
|
| 40 |
+
A tool that fetches the latest news updates on AI safety developments and categorizes them.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
category: The topic or category for the news updates (e.g., 'research', 'policy', 'industry').
|
| 44 |
+
max_results: The maximum number of news articles to retrieve.
|
| 45 |
+
|
| 46 |
+
Returns:
|
| 47 |
+
A string summarizing the latest AI safety news updates for the specified category.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
api_key = os.getenv("NEWS_API_KEY")
|
| 51 |
+
if not api_key:
|
| 52 |
+
return "Error: NEWS_API_KEY is not set in your environment."
|
| 53 |
+
|
| 54 |
+
# Prepare the query; you can customize it further as needed
|
| 55 |
+
query = f" Latest AI safety research News {category}"
|
| 56 |
+
|
| 57 |
+
# News API endpoint
|
| 58 |
+
url = "https://newsapi.org/v2/everything"
|
| 59 |
+
|
| 60 |
+
params = {
|
| 61 |
+
"q": query,
|
| 62 |
+
"sortBy": "publishedAt",
|
| 63 |
+
"pageSize": max_results,
|
| 64 |
+
"apiKey": api_key
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
response = requests.get(url, params=params)
|
| 68 |
+
|
| 69 |
+
if response.status_code == 200:
|
| 70 |
+
articles = response.json().get("articles", [])
|
| 71 |
+
if not articles:
|
| 72 |
+
return f"No recent updates found for category '{category}'."
|
| 73 |
+
|
| 74 |
+
# Build a summary of the news articles
|
| 75 |
+
summary = f"Latest AI safety updates for category '{category}':\n"
|
| 76 |
+
for article in articles:
|
| 77 |
+
title = article.get("title", "No title")
|
| 78 |
+
source = article.get("source", {}).get("name", "Unknown source")
|
| 79 |
+
published = article.get("publishedAt", "No date")
|
| 80 |
+
summary += f"- {title} (Source: {source}, Date: {published})\n"
|
| 81 |
+
return summary
|
| 82 |
+
else:
|
| 83 |
+
return f"Error fetching news: {response.status_code} - {response.text}"
|
| 84 |
+
|
| 85 |
|
| 86 |
final_answer = FinalAnswerTool()
|
| 87 |
+
|
| 88 |
|
| 89 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 90 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 105 |
|
| 106 |
agent = CodeAgent(
|
| 107 |
model=model,
|
| 108 |
+
tools=[final_answer, get_current_time_in_timezone,
|
| 109 |
+
get_ai_safety_updates], ## add your tools here (don't remove final answer)
|
| 110 |
max_steps=6,
|
| 111 |
verbosity_level=1,
|
| 112 |
grammar=None,
|