1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Google Colab】OpenAI APIの「TypeError: Client.init() got an unexpected keyword argument 'proxies'」エラー解消法

Posted at

エラー内容

LangChainとLangGraphによるRAG・AIエージェント[実践]入門」のハンズオンを参考に、Google Colab上でOpen AI のPythonライブラリを使おうとした際に、下記エラーが発生しました。

from openai import OpenAI

client = OpenAI() # エラー発生

# 以下省略
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'

原因

Google ColabやJupyter Notebookの環境では、pip install でパッケージを上書きしただけでは古いバージョンのファイルやキャッシュが残ることが多く、「新しいSDK構文+古い内部モジュール」で競合が起きているようでした。

解決方法

以下の手順でセッションの再起動+ライブラリの再インストールをしたところエラーが解消しました。

1.全ての OpenAI 関連パッケージをアンインストール

依存パッケージも含めて全てアンインストールします。

!pip uninstall -y openai openai-secret-manager openai-whisper

2.ランタイムの再起動

上部のメニューから「ランタイム」→「セッションを再起動する」を選択して、ランタイムを再起動します。
image.png

※右上の「再起動中」という表示が消えたら再起動完了。
image.png

3.OpenAI パッケージを再インストール

再度openaiパッケージをインストールします。(バージョンは書籍指定のもの)

!pip install openai==1.40.6

インストール後に、再度コードを実行したところ正常に動作しました。

まとめ

Google Colabはあまり使ったことがなかったので少し戸惑いましたが、今後同様の事象が発生した場合は「すべて消す→再起動→再インストール」を試してみようと思います。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?