Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.5章 P.55でエラー発生 #4

Open
yusukeoi opened this issue Nov 15, 2023 · 2 comments
Open

3.5章 P.55でエラー発生 #4

yusukeoi opened this issue Nov 15, 2023 · 2 comments

Comments

@yusukeoi
Copy link

yusukeoi commented Nov 15, 2023

エラーの説明

以下サンプルコードの実行でエラーが発生

import openai

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content":"You are a helpful assistant."},
        {"role": "user", "content": "Hello! I'm John."}
    ]
)

print(response)

エラーメッセージは以下。

---------------------------------------------------------------------------
APIRemovedInV1                            Traceback (most recent call last)
[<ipython-input-7-36f4c2dde96f>](https://localhost:8080/#) in <cell line: 3>()
      1 import openai
      2 
----> 3 response = openai.ChatCompletion.create(
      4     model="gpt-3.5-turbo",
      5     messages=[

2 frames
[/usr/local/lib/python3.10/dist-packages/openai/lib/_old_api.py](https://localhost:8080/#) in __load__(self)
     31     @override
     32     def __load__(self) -> None:
---> 33         raise APIRemovedInV1(symbol=self._symbol)
     34 
     35 

APIRemovedInV1: 

You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. 

Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`

A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742

スクリーンショット

スクリーンショット 2023-11-15 15 10 21

書籍の該当箇所

3.5章 「Chat Completion APIをさわってみる」P.55のサンプルコード

環境

Google Colab

その他

Google Colabのランタイムを再起動したうえで、書籍では
!pip install openai
となっている箇所を、エラーメッセージに記載されているとおり
!pip install openai==0.28
としたところ、正常に実行ができました。

@yoshidashingo
Copy link
Owner

ご報告ありがとうございます。書籍では openai 1.x.x 系に対応していないため、Colab内でバージョン固定するとともに、必要に応じて1..x.x系のサンプルを記載しておくことといたします。

@os1ma
Copy link
Collaborator

os1ma commented Nov 20, 2023

ご報告ありがとうございます。同様のエラーが発生しないよう、Google Colab内でバージョンを固定するようにしました。
最新版のGoogle Colabのコードを参考にしていただければと思います。

Open In Colab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants