OPEN AI APIについて教えて下さい
解決したいこと
openai API を実装したいのですが、以下のエラーが出てしまいます。
発生している問題・エラー
TypeError: 'ChatCompletion' object is not subscriptable
自分で試したこと
新しい書き方で調べてみて、以下のコードを書いたときに上記のエラーが出ました。
import openai
openai.api_key = "OPENAI_API_KEY" # 実際は個人のAPIキー
response = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Pythonについて教えてください"},
],
)
print(response['choices'][0]['message']['content'])
自分で試してみたこと2
最近ライブラリが一新されたので、書籍などに掲載されている古い関数'ChatCompletion'を使うと以下のエラーが出ます。
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
OPENAI API初学者なので、是非ご教授お願い致します。
0 likes