from langchain.tools import tool from bs4 import BeautifulSoup import requests from langchain.tools import tool from duckduckgo_search import DDGS class WebSearchTools: #################################### - DDG SEARCH ENGINE TOOL - #################################### @tool("internet_search") def internet_search(query: str) -> str: """ Performs an internet search using a DuckDuckGo-like service and returns the results. Parameters: query (str): The search query. Returns: str: The search results or a message indicating no results were found. """ # Assuming `ddgs` is initialized and ready to use here, with a context manager support with DDGS() as ddgs: results = [r for r in ddgs.text(query, max_results=3)] return results if results else "No results found." #################################### - DDG SEARCH ENGINE TOOL - #################################### ####################$################ - BS4 URL SCRAPER TOOL - ############$######################## @staticmethod @tool("process_search_results", return_direct=False) def process_search_results(url: str) -> str: """ Processes the content from webpages given a URL using BeautifulSoup. Parameters: url (str): The URL to fetch and process. Returns: str: The text content of the webpage. """ response = requests.get(url=url) if response.status_code == 200: soup = BeautifulSoup(response.content, "html.parser") return soup.get_text() else: return "Failed to fetch content." ####################$################ - BS4 URL SCRAPER TOOL - ############$######################## @tool("forecast search", return_direct=False) def forecast_search(query: str) -> str: """ Performs an internet search and returns the results. **** Note: only pass the cryptocurrency name or symbol into the search query**** Parameters: query (str): The search query. Returns: str: The search results or a message indicating no results were found. """ # Assuming `ddgs` is initialized and ready to use here, with a context manager support with DDGS() as ddgs: results = [r for r in ddgs.text(f"site:digitalcoinprice.com/forecast 2024 {query}", max_results=5)] return results if results else "No results found." @tool("technical signal search", return_direct=False) def technicalsignals_search(query: str) -> str: """ Performs an internet search and returns the results. **** Note: only pass the cryptocurrency name or symbol into the search query like BTC or LINK - DO NOT PASS ANY OTHER QUERY**** Parameters: query (str): The search query. Returns: str: The search results or a message indicating no results were found. """ # Assuming `ddgs` is initialized and ready to use here, with a context manager support with DDGS() as ddgs: results = [r for r in ddgs.text(f"site:centralcharts.com signals {query}", max_results=10)] return results if results else "No results found." @tool("price target search", return_direct=False) def pricetargets_search(query: str) -> str: """ Performs an internet search and returns the results. **** Note: only pass the cryptocurrency name or symbol into the search query**** Parameters: query (str): The search query. Returns: str: The search results or a message indicating no results were found. """ # Assuming `ddgs` is initialized and ready to use here, with a context manager support with DDGS() as ddgs: results = [r for r in ddgs.text(f"site:coincodex.com prediction {query}", max_results=4)] return results if results else "No results found."