| 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})." |
|
|
| |