-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbrowser.py
More file actions
39 lines (30 loc) · 992 Bytes
/
browser.py
File metadata and controls
39 lines (30 loc) · 992 Bytes
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
from typing import Awaitable, Callable
from browser_use import Agent, Browser, BrowserConfig
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
import warnings
load_dotenv()
warnings.filterwarnings("ignore")
browser = Browser(
config=BrowserConfig(
chrome_instance_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', # macOS path
)
)
llm = ChatAnthropic(model_name="claude-3-5-sonnet-latest")
task_template = """
perform the following task
{task}
"""
async def run_browser_agent(task: str, on_step: Callable[[], Awaitable[None]]):
"""Run the browser-use agent with the specified task."""
agent = Agent(
task=task_template.format(task=task),
browser=browser,
llm=llm,
register_new_step_callback=on_step,
register_done_callback=on_step,
)
result = await agent.run()
await browser.close()
return result.final_result()