Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,31 +7,47 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
-
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
@tool
|
| 22 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
-
"""A tool that fetches the current local time in a specified timezone.
|
| 24 |
Args:
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
@@ -46,16 +62,14 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
# Import tool from Hub
|
| 51 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
-
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
-
|
|
|
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Below is my news aggregator tool!
|
| 11 |
@tool
|
| 12 |
+
def news_aggregator(keyword: str, max_results: int = 5) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
+
A tool that fetches the latest news articles related to a specific keyword.
|
| 15 |
+
|
|
|
|
|
|
|
|
|
|
| 16 |
Args:
|
| 17 |
+
keyword: The topic or keyword to search for (e.g., "AI", "technology").
|
| 18 |
+
max_results: The maximum number of articles to return (default is 5).
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
A string containing the titles and URLs of the latest news articles.
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
+
# I am using the NewsAPI key
|
| 25 |
+
api_key = "d43565ac0e674145a22c5f0de4dcd69c"
|
| 26 |
+
url = f"https://newsapi.org/v2/everything?q={keyword}&pageSize={max_results}&apiKey={api_key}"
|
| 27 |
+
|
| 28 |
+
# Make the API request
|
| 29 |
+
response = requests.get(url)
|
| 30 |
+
response.raise_for_status() # Raise an error for bad status codes
|
| 31 |
+
|
| 32 |
+
# Parse the JSON response
|
| 33 |
+
data = response.json()
|
| 34 |
+
|
| 35 |
+
# Extract relevant information (titles and URLs)
|
| 36 |
+
articles = data.get("articles", [])
|
| 37 |
+
if not articles:
|
| 38 |
+
return "No news articles found for the given keyword."
|
| 39 |
+
|
| 40 |
+
# Format the results
|
| 41 |
+
result = "Here are the latest news articles:\n"
|
| 42 |
+
for i, article in enumerate(articles, 1):
|
| 43 |
+
title = article.get("title", "No title")
|
| 44 |
+
url = article.get("url", "#")
|
| 45 |
+
result += f"{i}. {title}\n {url}\n"
|
| 46 |
+
|
| 47 |
+
return result
|
| 48 |
+
|
| 49 |
+
except requests.exceptions.RequestException as e:
|
| 50 |
+
return f"Error fetching news articles: {str(e)}"
|
| 51 |
|
| 52 |
|
| 53 |
final_answer = FinalAnswerTool()
|
|
|
|
| 62 |
custom_role_conversions=None,
|
| 63 |
)
|
| 64 |
|
| 65 |
+
# prompt templates
|
|
|
|
|
|
|
|
|
|
| 66 |
with open("prompts.yaml", 'r') as stream:
|
| 67 |
prompt_templates = yaml.safe_load(stream)
|
| 68 |
+
|
| 69 |
+
# Agent and tools
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[final_answer, news_aggregator], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|