链载Ai

标题: Browser Use - 让AI能够控制你的浏览器 [打印本页]

作者: 链载Ai    时间: 1 小时前
标题: Browser Use - 让AI能够控制你的浏览器
1、前言

在科技飞速发展的当下,人工智能(AI)已经渗透到我们生活的方方面面,而AI智能体与浏览器的连接,正逐渐成为互联网发展的全新趋势,引发了大众对上网体验变革的无限期待。这种创新的融合,就像是为传统浏览器插上了智能的翅膀,将为我们带来前所未有的互联网交互感受。


本篇将介绍将你的AI代理与浏览器轻松连接,通过AI智能体访问各类网站的自动化框架 - Browser Use



2、简介

Browser Use是将你的AI智能体与浏览器连接起来的最简单方式。它通过提供一个功能强大且操作简单的浏览器自动化接口,让AI智能体能够访问各类网站。

功能特点:


官网地址:

https://browser-use.com/



3、快速上手

一、安装与智能体设置

1、Browser Use需要Python 3.11或更高版本。

pipinstallbrowser-use

2、安装Playwright。

playwrightinstall

3、创建一个智能体。

然后你可以按如下方式使用该智能体:

fromlangchain_openai importChatOpenAI
frombrowser_use importAgent
importasyncio
fromdotenv importload_dotenv
load_dotenv()

asyncdefmain():
agent = Agent(
task="Compare the price of gpt-4o and DeepSeek-V3",
llm=ChatOpenAI(model="gpt-4o"),
)
awaitagent.run()

asyncio.run(main())

4、设置你的大语言模型(LLM)API密钥。

ChatOpenAI以及其他基于Langchain的聊天模型都需要API密钥。你可以将这些密钥存储在你的.env文件中。

OPENAI_API_KEY=

二、Browser Use + DeepSeek-R1

本篇示例,作者使用DeepSeek-R1模型。

访问DeepSeek的API开放平台,购买流量,并创建API key。

https://platform.deepseek.com/

示例脚本:

将引入的智能体(DeepSeek-R1)与API密钥放在同一个脚本文件里。

操作步骤为打开购物网站,输入账户密码登录,查看商品详情,添加购物车,关闭浏览器。

importasyncio
importos

fromdotenv importload_dotenv
fromlangchain_openai importChatOpenAI
frompydantic importSecretStr

frombrowser_use importAgent

# dotenv
load_dotenv()

api_key = os.getenv('DEEPSEEK_API_KEY', 'sk-……)
if not api_key:
raise ValueError('DEEPSEEK_API_KEY isnotset')

async def run_search():
agent = Agent(
task=(
'1.访问 https://www.saucedemo.com/'
'2.输入用户名 standard_user, 密码 secret_sauce, 进行登录'
'3.点击黑色T-Shirt, 查看详情'
'4.将黑色T-Shirt添加到购物车'
'5.关闭浏览器'
),
llm=ChatOpenAI(
base_url='https://api.deepseek.com/v1',
model='deepseek-chat',
api_key=SecretStr(api_key),
),
use_vision=False,
)

await agent.run()

if __name__ == '__main__':
asyncio.run(run_search())

运行时,AI识别页面元素:

控制台日志信息:

完整运行过程:






欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5