File size: 1,911 Bytes
17378bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import time

from pydantic import Field

from agency_swarm.tools import BaseTool
from .util.selenium import get_web_driver, set_web_driver


class ReadURL(BaseTool):
    """
This tool reads a single URL and opens it in your current browser window. For each new source, go to a direct URL
that you think might contain the answer to the user's question or perform a google search like
'https://google.com/search?q=search' if applicable. Otherwise, don't try to guess the direct url, use ClickElement tool
to click on the link that you think might contain the desired information on the current web page.
Remember, this tool only supports opening 1 URL at a time. Previous URL will be closed when you open a new one.
    """
    chain_of_thought: str = Field(
        ..., description="Think step-by-step about where you need to navigate next to find the necessary information.",
        exclude=True
    )
    url: str = Field(
        ..., description="URL of the webpage.", examples=["https://google.com/search?q=search"]
    )
    one_call_at_a_time: bool = True


    def run(self):
        wd = get_web_driver()

        wd.get(self.url)

        time.sleep(2)

        # remove all popups
        js_script = """
        var popUpSelectors = ['modal', 'popup', 'overlay', 'dialog']; // Add more selectors that are commonly used for pop-ups
        popUpSelectors.forEach(function(selector) {
            var elements = document.querySelectorAll(selector);
            elements.forEach(function(element) {
                // You can choose to hide or remove; here we're removing the element
                element.parentNode.removeChild(element);
            });
        });
        """

        wd.execute_script(js_script)

        set_web_driver(wd)

        return "Current URL is: " + wd.current_url + "\n"


if __name__ == "__main__":
    tool = ReadURL(url="https://google.com")
    print(tool.run())