File size: 4,252 Bytes
d2f9513 ddb53d4 d2f9513 ddb53d4 d2f9513 ddb53d4 d2f9513 ddb53d4 d2f9513 ddb53d4 9b702da d2f9513 9b702da d2f9513 ddb53d4 d2f9513 ddb53d4 d2f9513 9b702da d2f9513 |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
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."
|