Browser Use
browser-use/browser-use: Make websites accessible for AI agents
AIにpromptを投げてBrowserを操作してもらえるツール
miseでpython入れて環境を作りOPEN_API_KEYをセットする。
code:sh
$ mise install python@3.13.1
$ pip install browser-use
$ playwright install
$ vim mise.toml
env
OPENAI_API_KEY = 'xxxxxxxx'
サンプルコードを実行する
code:py
from langchain_openai import ChatOpenAI
from browser_use import Agent
import asyncio
llm = ChatOpenAI(model="gpt-4o-mini")
async def main():
agent = Agent(
task="Find a one-way flight from Bali to Oman on 12 January 2025 on Google Flights. Return me the cheapest option.",
llm=llm,
)
result = await agent.run()
print(result)
asyncio.run(main())
下記のエラーが出た。
code:txt
INFO backoff Backing off send_request(...) for 0.3s (requests.exceptions.SSLError: HTTPSConnectionPool(host='eu.i.posthog.com', port=443): Max retries exceeded with url: /batch/ (Caused by SSLError(SSLCertVerificationError(1, 'SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1018)'))))
【Python】【requests】プロキシ環境下でSSLErrorになる原因と対処法 #Requests - Qiitaを見るとPythonのrequestsライブラリで出してるエラーらしい。ということでPCに搭載されてたプロキシツールが原因だった。これを切ると普通に動いた模様。
ただしフライトのstartとdestinationを入力し、候補の航路を取得するところまでで止まった。OPEN_API_KEYにcredit card指定なしで作成したkeyをセットして試したが、一撃でrate limitに到達して終わったっぽい。API Usageを見ると380k tokenくらい使ってた。ヒエェ...
https://scrapbox.io/files/678c70493f75f4adf68f2ef7.png
gpt-4o-miniだと$0.150/1M tokensだから0.150 * 150 * (380K/1M)で9円くらい?
browser use python