Final_Assignment_Template / tools /search_tools.py
STARX33's picture
Update tools/search_tools.py
8b0695f verified
Raw History Blame Contribute Delete
882 Bytes
import requests
from smolagents import tool
from tools.simple_text_browser import _BROWSER
@tool
def simple_search(query: str) -> str:
"""
Perform a DuckDuckGo web search and return the top snippets.
Args:
query: The search query to perform.
"""
return _BROWSER.search(query)
@tool
def archive_search(url: str, date: str) -> str:
"""
Given a URL and a date (YYYYMMDD), returns the archived snapshot text via Wayback.
Args:
url: The original URL to look up.
date: The desired snapshot date as YYYYMMDD.
"""
api = f"https://archive.org/wayback/available?url={url}&timestamp={date}"
data = requests.get(api, timeout=10).json()
snap = data.get("archived_snapshots", {}).get("closest", {}).get("url")
if not snap:
return f"No archive found for {url} at {date}."
return _BROWSER.visit_page(snap)