gpt4 book ai didi

openai-api - OpenAI API错误: Why do I still get the "module ' openai' has no attribute 'ChatCompletion' "error after I upgraded the OpenAI package and Python?

转载 作者:行者123 更新时间:2023-12-02 22:48:17 25 4
gpt4 key购买 nike

我收到以下错误:模块“openai”没有属性“ChatCompletion”

我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。

Python:3.11.3

OpenAI Python 包:0.27.7

import openai
import os
openai.api_key = ""
prompt = f"""
write a short story about a person who is going to a party.
"""

response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": prompt},
],
temperature=0,
max_tokens=2024,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)

print(response["choices"][0]["message"]["content"]) # type: ignore

最佳答案

不要将文件命名为 openai.py

您说您升级了 OpenAI Python 包和 Python,但错误仍然存​​在。

人们常犯的一个错误是将文件命名为 openai.py。即使您升级了所有内容,也会导致模块“openai”没有属性“ChatCompletion”错误。

关于openai-api - OpenAI API错误: Why do I still get the "module ' openai' has no attribute 'ChatCompletion' "error after I upgraded the OpenAI package and Python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76385146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com