File size: 636 Bytes
9cb9227 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from smolagents import tool
import requests
@tool
def wiki_summarize(topic: str) -> str:
"""Get the first paragraph summary for a Wikipedia topic.
rgs:
topic: The Wikipedia page title to summarize.
Returns:
A short summary of the page.
"""
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{topic}"
resp = requests.get(url)
if resp.status_code == 200:
data = resp.json()
return data.get("extract", "No summary available.")
else:
return f"Error fetching Wikipedia summary (status {resp.status_code})."
# wiki_summarize_tool = wiki_summarize.push_to_hub() |