kpalatel's picture
Upload 5 files
f7b6bbe verified
Raw
History Blame
882 Bytes
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]