Python OpenAI API 类型错误

标签 python typeerror urllib3 openai-api chatgpt-api

我正在尝试使用 OpenAI API 并遇到问题。 我使用了文档中的标准示例代码:

import openai

API_KEY = 'MY_API_KEY'
openai.api_key = API_KEY

response = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
        {"role": "user", "content": "Where was it played?"}
    ]
)

print(response)

输出为:

TypeError: Queue.init() takes 1 positional argument but 2 were given'

问题是什么?

我尝试更新需求(urrlib3Requestsopenai)和 Python。 但它们都有实际版本。

最佳答案

我也遇到过类似的情况。您使用的 OpenAI API 库的版本可能存在问题。尝试将库更新到最新版本,看看是否可以解决问题。

pip install openai --upgradelibaray

关于Python OpenAI API 类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75985331/

相关文章:

python - 升级 Django 版本 : Best Practice

python - 使用 Elsevier Scopus API 获取论文引用

jquery - 类型错误:无法使用 $http 读取未定义的属性 'success'

python-2.7 - 模块 chembl_webresource_client.new_client 失败,因为 python 2.7.9 下的 urllib3 中的 ssl 损坏

python - 如何在 HTTPConnectionPool urllib3 中进行几次重定向后获取响应历史记录

python - 在 wxPython 应用程序中嵌入 3D 编辑器(例如 Blender)

python - 返回工作日列表,从给定的工作日开始

javascript - 未捕获的类型错误 : Undefined is not a function Issue in MVC C# using fullcalendar

python - 数据库表不是 JSON 可序列化的

python - 轻松升级 Requests 的 urllib3 版本?