需要注意的是:这里claude操纵的是docker的虚拟服务器,不能访问本地url,需要进行端口转发
export ANTHROPIC_API_KEY=%your_api_key%
docker run \
-e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
-v $HOME/.anthropic:/home/computeruse/.anthropic \
-p 5900:5900 \
-p 8501:8501 \
-p 6080:6080 \
-p 8080:8080 \
-it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest
也可以用browser use 操纵自己的本地浏览器,步骤如下
conda create -n browse python=3.11
conda activate browse
git clone https://github.com/browser-use/web-ui.git
cd web-ui
pip install -r requirements.txt
python webui.py --ip 127.0.0.1 --port 7788
记得填写.env对应的key
调用qwen模型
import os
from langchain_openai import ChatOpenAI
from langchain_openai.chat_models.base import BaseChatOpenAI
from browser_use import Agent, Browser, BrowserConfig
import asyncio
# 无头模式
browser = Browser(
config=BrowserConfig(
headless=False,
disable_security=True
)
)
os.environ['OPENAI_API_KEY'] = "your_openai_api_key"
async def main():
agent = Agent(
task="Visit URL: http://localhost:3000 And test the form submission function of this website to see if the successful submission prompt pop-up window is displayed. Finally, it is essential to provide an accurate conclusion on whether the function is effective or ineffective",
llm=BaseChatOpenAI(model="qwen-max-2025-01-25",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"),
browser=browser
)
result = await agent.run()
print(result)
asyncio.run(main())
阿里云调用vl模型
如何使用Qwen-VL模型_大模型服务平台百炼(Model Studio)-阿里云帮助中心
browse use 的一些输出
history = await agent.run()
if history.has_errors():
print("执行过程中的错误:", history.errors())
result = history.final_result()
if result:
with open('results.txt', 'a') as f:
f.write(f"第{i}次测试结果:\n")
f.write(result + '\n')
history.number_of_steps() # 获取总步数
# history.total_duration_seconds() # 获取总执行时间
# history.total_input_tokens() # 获取总token使用量
# history.is_done() # 检查任务是否完成
# history.is_successful() # 检查任务是否成功完成
# history.has_errors() # 检查是否有错误发生
# history.urls() # 获取访问过的所有URL
# history.screenshots() # 获取所有截图路径
# history.action_names() # 获取执行的所有动作名称
# history.model_actions() # 获取所有动作及其参数
# history.final_result() # 获取最终结果
# history.extracted_content() # 获取提取的内容
# history.errors() # 获取所有错误信息
# history.model_thoughts() # 获取代理的推理过程