Takagi3咩 2024-03-08 00:51 采纳率: 0%
浏览 959
已结题

为什么引入了openai包后还是报这个错

openai.lib._old_api.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

请问有没有人能帮忙解答一下

  • 写回答

5条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2024-03-08 00:51
    关注

    引自免费微信小程序:皆我百晓生

    根据错误信息,您在尝试使用 openai.ChatCompletion,但该功能在 openai 库版本1.0.0及更高版本中已被移除。为解决这个问题,请按照以下步骤操作:

    1. 自动升级代码:您可以运行 openai migrate 命令来自动将您的代码库更新到1.0.0接口。这个命令会尽可能地调整你的代码以适应新的API。

    2. 手动迁移指南:如果自动迁移无法满足需求或出现问题,可以参考官方提供的迁移指南进行手动更新。链接如下: https://github.com/openai/openai-python/discussions/742

    3. 降级安装旧版 openai 库:如果您希望暂时维持原有功能,可以选择安装旧版本的 openai 库。在命令行输入以下命令:

      pip install openai==0.28
      

    请根据您的实际需求和项目情况选择合适的解决方案。若需要使用OpenAI的新版本,并且之前使用的是ChatCompletion相关功能,请查阅新版本的文档了解如何替换为相应的新API调用方法。

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月22日
  • 创建了问题 3月8日