mjschock's picture
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
raw
history blame
802 Bytes
import re
from typing import Any, Dict, List
from smolagents import tool
@tool
def find_in_page(page_content: Dict[str, Any], query: str) -> List[str]:
"""
Find occurrences of a query string in page content.
Args:
page_content: Page content returned by browse_webpage
query: String to search for in the page
Returns:
List of sentences or sections containing the query
"""
results = []
if "content" in page_content:
content = page_content["content"]
# Split content into sentences
sentences = re.split(r"(?<=[.!?])\s+", content)
# Find sentences containing the query
for sentence in sentences:
if query.lower() in sentence.lower():
results.append(sentence)
return results