jinysun commited on
Commit
113eebc
·
verified ·
1 Parent(s): 680ede6

Update tool/browsersearch.py

Browse files
Files changed (1) hide show
  1. tool/browsersearch.py +43 -35
tool/browsersearch.py CHANGED
@@ -1,36 +1,44 @@
1
- from langchain_openai import ChatOpenAI
2
- from browser_use import Agent
3
- import asyncio
4
- from dotenv import load_dotenv
5
- load_dotenv()
6
- from langchain.tools import BaseTool
7
-
8
- async def main(task):
9
- agent = Agent(
10
- task=task,
11
- llm=ChatOpenAI(model="gpt-4o-2024-11-20",api_key='sk-itPrztYm9F6XZZpsBMJB9O7Vq0pYUABVVBSoThuBxEGTnDik',
12
- base_url="https://www.dmxapi.com/v1"),
13
- )
14
- result = await agent.run()
15
- return result
16
-
17
- class browseruse(BaseTool):
18
- name: str = "browseruse"
19
- description: str = ("Calling the browser to search for information in specific website"
20
- "input query, return the searching results")
21
-
22
- def __init__(
23
- self,
24
- ):
25
- super().__init__()
26
-
27
- def _run(self, task: str) -> str:
28
- result = asyncio.run(main(task))
29
- return result
30
-
31
- async def _arun(self, smiles: str) -> str:
32
- """Use the tool asynchronously."""
33
- raise NotImplementedError()
34
-
35
-
 
 
 
 
 
 
 
 
36
 
 
1
+ from langchain_openai import ChatOpenAI
2
+ from browser_use import Agent
3
+ import asyncio
4
+ from dotenv import load_dotenv
5
+ load_dotenv()
6
+ import os
7
+ from langchain.tools import BaseTool
8
+ from browser_use.browser.browser import Browser, BrowserConfig
9
+ from browser_use.controller.service import Controller
10
+ browser = Browser(config=BrowserConfig())
11
+ controller = Controller()
12
+ if os.name == 'nt':
13
+ asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
14
+ async def main(task):
15
+ agent = Agent(
16
+ task=task,
17
+ llm=ChatOpenAI(model="gpt-4o-2024-11-20",api_key='sk-itPrztYm9F6XZZpsBMJB9O7Vq0pYUABVVBSoThuBxEGTnDik',
18
+ base_url="https://www.dmxapi.com/v1"), controller=controller,
19
+ browser=browser,
20
+ use_vision=True,
21
+ )
22
+ result = await agent.run()
23
+ return result
24
+
25
+ class browseruse(BaseTool):
26
+ name: str = "browseruse"
27
+ description: str = ("Calling the browser to search for information in specific website"
28
+ "input query, return the searching results")
29
+
30
+ def __init__(
31
+ self,
32
+ ):
33
+ super().__init__()
34
+
35
+ def _run(self, task: str) -> str:
36
+ result = asyncio.run(main(task))
37
+ return result
38
+
39
+ async def _arun(self, smiles: str) -> str:
40
+ """Use the tool asynchronously."""
41
+ raise NotImplementedError()
42
+
43
+
44