Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,37 @@ def math_operation(operation: str, num1: float, num2: float) -> str:
|
|
| 56 |
except Exception as e:
|
| 57 |
return f"Error performing math operation: {str(e)}"
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
|
| 61 |
# 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:
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
return f"Error performing math operation: {str(e)}"
|
| 58 |
|
| 59 |
+
@tool
|
| 60 |
+
def get_news_summary(api_key: str, query: str = "technology", num_articles: int = 3) -> str:
|
| 61 |
+
"""A tool that fetches and summarizes the latest news articles.
|
| 62 |
+
Args:
|
| 63 |
+
api_key: '35dd0733c12a4a698bed693e2b85e830'
|
| 64 |
+
query: The topic to search for (e.g., 'technology', 'sports').
|
| 65 |
+
num_articles: The number of articles to summarize.
|
| 66 |
+
"""
|
| 67 |
+
try:
|
| 68 |
+
# Fetch news articles
|
| 69 |
+
url = f"https://newsapi.org/v2/everything?q={query}&apiKey={api_key}&pageSize={num_articles}"
|
| 70 |
+
response = requests.get(url)
|
| 71 |
+
data = response.json()
|
| 72 |
+
|
| 73 |
+
if data["status"] != "ok":
|
| 74 |
+
return f"Error fetching news: {data.get('message', 'Unknown error')}"
|
| 75 |
+
|
| 76 |
+
articles = data["articles"]
|
| 77 |
+
summaries = []
|
| 78 |
+
|
| 79 |
+
# Summarize each article
|
| 80 |
+
for article in articles:
|
| 81 |
+
title = article["title"]
|
| 82 |
+
description = article["description"]
|
| 83 |
+
summaries.append(f"**{title}**: {description}")
|
| 84 |
+
|
| 85 |
+
return "\n\n".join(summaries)
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return f"Error fetching or summarizing news: {str(e)}"
|
| 88 |
+
|
| 89 |
+
|
| 90 |
final_answer = FinalAnswerTool()
|
| 91 |
|
| 92 |
# 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:
|