forked from browser-use/browser-use
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry.py
68 lines (47 loc) · 1.53 KB
/
try.py
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
"""
Simple try of the agent.
@dev You need to add ANTHROPIC_API_KEY to your environment variables.
"""
import os
import sys
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import argparse
import asyncio
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig
from browser_use.controller.service import Controller
def get_llm(provider: str):
if provider == 'anthropic':
return ChatAnthropic(
model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.0
)
elif provider == 'openai':
return ChatOpenAI(model='gpt-4o', temperature=0.0)
else:
raise ValueError(f'Unsupported provider: {provider}')
task = 'Show the solution of y"(z) + sin(y(z)) = 0 from wolframalpha https://www.wolframalpha.com/'
parser = argparse.ArgumentParser()
parser.add_argument('--query', type=str, help='The query to process', default=task)
parser.add_argument(
'--provider',
type=str,
choices=['openai', 'anthropic'],
default='openai',
help='The model provider to use (default: openai)',
)
args = parser.parse_args()
llm = get_llm(args.provider)
browser = Browser(
config=BrowserConfig(
# chrome_instance_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
)
)
agent = Agent(
task=args.query, llm=llm, controller=Controller(), browser=browser, validate_output=True
)
async def main():
await agent.run(max_steps=25)
await browser.close()
asyncio.run(main())