我目前正在开发一个聊天机器人,由于我使用的是 Windows 11,它不允许我迁移到较新的 OpenAI 库或降级它。ChatCompletion我可以用其他功能替换该功能以在我的版本上使用吗?
这是代码:
import openai
openai.api_key = "private"
def chat_gpt(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message['content'].strip()
if __name__ == "__main__":
while True:
user_input = input("You: ")
if user_input.lower() in ["quit", "exit", "bye"]:
break
response = chat_gpt(user_input)
print("Bot:", response)
Run Code Online (Sandbox Code Playgroud)
这是完整的错误:
...您尝试访问 openai.ChatCompletion,但 openai>=1.0.0 不再支持此功能 - 请参阅https://github.com/openai/openai-python上的API 了解自述文件。
您可以运行
openai migrate自动升级您的代码库以使用 1.0.0 界面。或者,您可以将安装固定到旧版本,例如 <pip install openai==0.28>
此处提供了详细的迁移指南:https ://github.com/openai/openai-python/discussions/742
我尝试通过 pip 进行升级和降级。