ai-codebase-intelligence / tools /web_search_tool.py
pkraman06's picture
Update tools/web_search_tool.py
eb4c6e5 verified
raw
history blame contribute delete
612 Bytes
from langchain.tools import BaseTool
import requests
from bs4 import BeautifulSoup
class WebSearchTool(BaseTool):
name = "Web Search Tool"
description = "Searches web content"
def _run(self, query: str):
url = f"https://duckduckgo.com/html/?q={query}"
response = requests.get(url)
soup = BeautifulSoup(
response.text,
"html.parser"
)
results = soup.find_all(
"a",
class_="result__a",
limit=5
)
return "\n".join(
[result.get_text() for result in results]
)