-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathexample_browser_use.py
More file actions
78 lines (71 loc) · 2.81 KB
/
example_browser_use.py
File metadata and controls
78 lines (71 loc) · 2.81 KB
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
import os
import asyncio
import browser_use
from dotenv import load_dotenv
from minion_agent.config import AgentConfig, MCPStdio
from minion_agent.frameworks.minion_agent import MinionAgent
from minion_agent import MinionAgent, AgentConfig, AgentFramework
from smolagents import CodeAgent, AzureOpenAIServerModel
import minion_agent
# Load environment variables from .env file
load_dotenv()
async def main():
# Get Azure configuration from environment variables
azure_deployment = os.getenv('AZURE_DEPLOYMENT_NAME')
api_version = os.getenv('OPENAI_API_VERSION')
if not azure_deployment:
raise ValueError("AZURE_DEPLOYMENT_NAME environment variable is not set")
if not api_version:
raise ValueError("OPENAI_API_VERSION environment variable is not set")
from browser_use import Agent, Browser
# Create agent configuration
config = AgentConfig(
name="browser-agent",
model_type=browser_use.ChatAzureOpenAI,
model_id=azure_deployment,
agent_args={
# "browser":Browser(
# executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
# user_data_dir='~/Library/Application Support/Google/Chrome',
# profile_directory='Profile for browser-use',
# )
},
model_args={
# "azure_deployment": azure_deployment,
# "api_version": api_version,
},
tools=[
],
instructions="Compare the price of gpt-4o and DeepSeek-V3",
)
# Create and initialize the agent using MinionAgent.create_async
agent = await MinionAgent.create_async(AgentFramework.BROWSER_USE, config)
# Run the agent with a specific task
result = await agent.run_async("Compare the price of gpt-4o and DeepSeek-V3 and create a detailed comparison table")
print("Task Result:", result)
#
# # Run another task
# result = await agent.run_async("Go to baidu.com, search for '人工智能最新进展', and summarize the top 3 results")
# print("Task Result:", result)
#result = await agent.run_async("打开微信公众号,发表一篇hello world")
#print("Task Result:", result)
if __name__ == "__main__":
# Verify environment variables
required_vars = [
'AZURE_OPENAI_ENDPOINT',
'AZURE_OPENAI_API_KEY',
'AZURE_DEPLOYMENT_NAME',
'OPENAI_API_VERSION'
]
missing_vars = [var for var in required_vars if not os.getenv(var)]
if missing_vars:
print("Error: Missing required environment variables:", missing_vars)
print("Please set these variables in your .env file:")
print("""
AZURE_OPENAI_ENDPOINT=your_endpoint_here
AZURE_OPENAI_API_KEY=your_key_here
AZURE_DEPLOYMENT_NAME=your_deployment_name_here
OPENAI_API_VERSION=your_api_version_here # e.g. 2024-02-15
""")
else:
asyncio.run(main())