File size: 882 Bytes
f7b6bbe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | from smolagents import tool
from duckduckgo_search import DDGS
from PyPDF2 import PdfReader
@tool
def web_search(query: str) -> str:
"""
Search the web for information.
Args:
query: The search query to look up.
Returns:
Search results as text.
"""
results = DDGS().text(query, max_results=5)
output = []
for r in results:
output.append(
f"{r['title']}\n{r['body']}\n{r['href']}"
)
return "\n\n".join(output)
@tool
def read_pdf(path: str) -> str:
"""
Read text content from a PDF file.
Args:
path: Path to the PDF file.
Returns:
Extracted text from the PDF.
"""
reader = PdfReader(path)
text = ""
for page in reader.pages:
extracted = page.extract_text()
if extracted:
text += extracted
return text[:12000] |