gpt4 book ai didi

python - ChatCompletion 功能从 openai 模块中消失

转载 作者:行者123 更新时间:2023-12-02 05:49:33 25 4
gpt4 key购买 nike

当我运行使用 openai.ChatCompletion 的代码时:

import openai
openai.api_key = "removed for obvious reasons"

completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world!"}])
print(completion.choices[0].message.content)

它给了我这个错误:

Traceback (most recent call last):
File "c:\Users\genos' ai\Documents\Code\openai-quickstart-python\text3.py", line 4, in <module>
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world!"}])
AttributeError: module 'openai' has no attribute 'ChatCompletion'. Did you mean: 'Completion'?

所以我运行 print(str(openai.__all__)) 来检查模块,它给了我

['APIError', 'Answer', 'Classification', 'Completion', 'Customer', 'Edit', 'Deployment', 'Embedding', 'Engine', 'ErrorObject', 'File', 'FineTune', 'InvalidRequestError', 'Model', 'OpenAIError', 'Search', 'api_base', 'api_key', 'api_type', 'api_key_path', 'api_version', 'app_info', 'ca_bundle_path', 'debug', 'enable_elemetry', 'log', 'organization', 'proxy', 'verify_ssl_certs']

看不到 ChatCompletion。

我正在使用最新版本的 openai 模块,0.27.4。我通过pip卸载并重新安装了该模块,但ChatCompletion仍然不存在。

最佳答案

运行 pip --versionpython --version 并验证您正在使用与运行代码相同的 Python 引擎安装软件包。

您还可以将 pip 安装的软件包版本与您的环境正在运行的版本进行比较:

pip show openai

python -c“导入 openai; print(openai.__version__)”

希望这能为您提供足够的信息来解决您的环境问题。祝你好运!

关于python - ChatCompletion 功能从 openai 模块中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76112949/

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