0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

browser-useの0.1.21が正常に動かなくて困っている方へ

Last updated at Posted at 2025-01-13

現象

以下のようなコマンドでbrowser-useをインストール後に、

>py -m pip install browser-use==0.1.21
Collecting browser-use==0.1.21
  Using cached browser_use-0.1.21-py3-none-any.whl.metadata (5.1 kB)
...

そしてその後に例えば次のようなスクリプトを実行したときに、

agent_test.py
...
import os
import sys
import asyncio
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from browser_use import Agent

load_dotenv()
api_key = os.getenv('OPENAI_API_KEY')

llm = ChatOpenAI(model='gpt-4o', openai_api_key=api_key)

agent = Agent(
    task='...',
    llm=llm,
)

async def main():
    await agent.run(max_steps=3)
    agent.create_history_gif()
asyncio.run(main())
...

以下のようなエラーとなる、そんな悩めるあなたへ。

AppData\Local\Programs\Python\Python313\Lib\site-packages\langchain_openai\chat_models\base.py:407: UserWarning: Th
is model does not support OpenAI's structured output feature, which is the default method for `with_structured_output` as of langchain-open
ai==0.3. To use `with_structured_output` with this model, specify `method="function_calling"`.

対処法

以下のようにして、langchain_openaiのバージョンを下げるとうまくいきました。

(2025/1/18 追記)
…と記事の新規投稿時点では書きましたが、最近のリリース 0.1.23にてこの問題は修正された ようです。特にやむを得ない事情がない限りは0.1.23以降を代わりにインストールしましょう。

ご参考: https://github.com/browser-use/browser-use/releases
image.png

langchain_openaiのバージョンを確認

listコマンドを実行したときに、、、

> py -m pip list
...
langchain                    0.3.14
langchain-anthropic          0.3.1
langchain-aws                0.2.10
langchain-core               0.3.29
langchain-fireworks          0.2.6
langchain-google-genai       2.0.8
langchain-openai             0.3.0
langchain-text-splitters     0.3.5
langsmith                    0.2.10
...

上記のようにlangchain-openai Ver. 0.3.0が入っている場合。

langchain-openaiのバージョンを下げる

langchain-openaiのバージョンを以下のコマンドで0.2.0に下げます。

> py -m pip install langchain_openai==0.2.0
Collecting langchain_openai==0.2.0
  Downloading langchain_openai-0.2.0-py3-none-any.whl.metadata (2.6 kB)
...
Successfully installed langchain_openai-0.2.0

念のため再度バージョンを確認

langchain-openaiのバージョンが0.2.0に下がっているか確認します。

> py -m pip list
...
langchain                    0.3.14
langchain-anthropic          0.3.1
langchain-aws                0.2.10
langchain-core               0.3.29
langchain-fireworks          0.2.6
langchain-google-genai       2.0.8
langchain-openai             0.2.0
langchain-text-splitters     0.3.5
langsmith                    0.2.10
...

この状態で再度スクリプトが動くか試してみてください。

もしこれで動いた場合

今後同様の問題で頭を悩ませないように、requirements.txtやsetup.pyなどにバージョンを明示しておくとよいかもです。

…と、Cursor先生からアドバイス頂きました↓。
image.png
(笑)

(2025/1/18 追記)
…と書きましたが、そう単純ではなさそうですね↓。新たな問題を引き起こしそうです。失礼しました…。やはり素直に最新版を入れるのがベストですね。
image.png

参考文献

LangChain v0.3 Documentation

上記のドキュメントのこんな↓表の真ん中付近に、
image.png

↓のように推奨バージョンが書いてありました。
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?