File size: 4,324 Bytes
25d7a7f
 
 
 
 
 
 
 
 
5659dfe
25d7a7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5659dfe
25d7a7f
 
 
2d83294
25d7a7f
 
 
 
2d83294
25d7a7f
 
 
 
 
 
 
 
5659dfe
25d7a7f
 
 
2d83294
25d7a7f
 
 
 
 
 
 
 
 
 
 
 
 
5659dfe
25d7a7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
101
102
103
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", return_direct=False)
    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 - ############$########################


# ddgs.text(query,maxresults=4,timelimit="d,w,y", keywords="2024")

    @tool("forecast search", return_direct=False)
    def forecast_search(query: str) -> str:
        """
            **** Note: only pass the cryptocurrency name or symbol into the search query****
            **** Note: Use the process_search_results to scrape 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
            
        maxresults = 5
        with DDGS() as ddgs:
            results = [r for r in ddgs.text(f"site:digitalcoinprice.com/forecast {query}", max_results=maxresults)]
            return results if results else "No results found."

    @tool("technical signal search", return_direct=False)
    def technicalsignals_search(query: str) -> str:
        """
           *** Note - Pass only the cryptocurrency name or symbol in this tool and query*****
            **** Note: Use the process_search_results to scrape 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(f"site:centralcharts.com trade signals {query}", max_results=5)]
            return results if results else "No results found."
        
        
    @tool("price target search", return_direct=False)
    def pricetargets_search(query: str) -> str:
        """
           *** Note - Pass only the cryptocurrency name or symbol in this tool and 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 2024 {query}", max_results=3)]
            return results if results else "No results found."