Spaces:
Build error
Build error
Enhance agent functionality in main_v2.py by adding WikipediaSearchTool and updating DuckDuckGoSearchTool and VisitWebpageTool parameters. Modify agent initialization to accommodate new tools and increase max results and output length. Update requirements.txt to include Wikipedia-API dependency. Refactor imports for better organization across agent modules.
e4c7240
unverified
import wikipediaapi | |
from smolagents import tool | |
def wiki(query: str) -> str: | |
""" | |
Search and retrieve information from Wikipedia using the Wikipedia-API library. | |
Args: | |
query: The search query to look up on Wikipedia | |
Returns: | |
A string containing the Wikipedia page summary and relevant sections | |
""" | |
# Initialize Wikipedia API with a user agent | |
wiki_wiki = wikipediaapi.Wikipedia( | |
user_agent="HF-Agents-Course (https://huggingface.co/courses/agents-course)", | |
language="en", | |
) | |
# Search for the page | |
page = wiki_wiki.page(query) | |
if not page.exists(): | |
return f"No Wikipedia page found for query: {query}" | |
# Get the page summary | |
result = f"Title: {page.title}\n\n" | |
result += f"Summary: {page.summary}\n\n" | |
# Add the first few sections if they exist | |
if page.sections: | |
result += "Sections:\n" | |
for section in page.sections[ | |
:3 | |
]: # Limit to first 3 sections to avoid too much text | |
result += f"\n{section.title}:\n{section.text[:500]}...\n" | |
return result | |