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

huangapple go评论92阅读模式
英文:

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

问题

我遇到了以下错误:模块'openai'没有'ChatCompletion'属性

我检查了其他帖子。它们都说要升级OpenAI Python包或升级Python。我两者都做了,但问题没有解决。

Python版本:3.11.3

OpenAI Python包版本:0.27.7

import openai
import os
openai.api_key = ""
prompt = """
写一个关于一个人去参加派对的短故事。
"""

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "你是一个乐于助人的助手"},
        {"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
英文:

I am getting the following error: module 'openai' has no attribute 'ChatCompletion'

I checked the other posts. They are all saying to upgrade the OpenAI Python package or upgrade Python. I did both but didn't fix it.

Python: 3.11.3

OpenAI Python package: 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

答案1

得分: 1

不要将文件命名为openai.py
你说你升级了OpenAI的Python包和Python,但错误仍然存在。
人们常犯的一个错误是将文件命名为openai.py。即使你升级了所有内容,它也会导致module 'openai' has no attribute 'ChatCompletion'错误。

英文:

Don't name the file openai.py.

You said you upgraded both the OpenAI Python package and Python, but the error persists.

One common mistake people make is naming the file openai.py. It'll cause the module 'openai' has no attribute 'ChatCompletion' error even though you upgraded everything.

huangapple
  • 本文由 发表于 2023年6月2日 03:33:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385146.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定