openai 包更新 1.X 版后的代码兼容问题
linzeyang opened this issue · comments
11月7日 OpenAI 举办 OpenAI DevDay 并配套将 Python SDK openai
包更新到了 1.X 版本,包含了若干 breaking changes,例如对话补完API的新的调用方法就变为
openai.OpenAI().chat.completions.create(...)
此类变更并不向后兼容,即在 1.X 版本下,若使用旧版代码调用对话补完
openai.ChatCompletion.create(...)
则会报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 runopenai 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: openai/openai-python#742
即在11月7日后,学习此教程第二课 “调用ChatGPT” 部分,且安装了 1.X 版本openai
包的学习者将遇到代码运行错误的情况。
另外因为 /project/llm/call_llm.py
中也有调用 openai.ChatCompletion.create()
,且此项目似乎并没有固定依赖包的版本,预计此项目也将受影响。
解决方案一:
在 notebook 和 项目 中固定 openai
包的版本为某个 0.X 版本,如最后一个 0.X 版本 0.28.1
。
解决方案二:
参考上文中的迁移指南,手动或尝试使用 openai migarate
命令将现有代码更新为适应 1.X 版本的代码。
收到,感谢意见,已指定 openai 版本号。