赞
踩
官网介绍很简单,使用pip即可安装成功
pip install openai
但是,按照官方demo调用时,
import openai
openai.api_key ="your_api_key" # 已申请的apikey
response = openai.Chatcompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role":"user","content":"哈喽,你好吗"}
],
temperature=0
)
报错如下:
提示错误:AttributeError:module 'openai' has no attribute'Chatcompletion'
# 查看版本号0.8.0
pip show openai
# 参考其他成功版本号是0.10.3,于是
pip install openai==0.10.3
# 报错内容大致如下
ERROR: Could not find a version that satisfies the requirement pandas>=1.2.3 (from openai) (from versions:0.1 .......)
ERROR: No matching distribution found for pandas>=1.2.3
# 打包3.8环境
conda create -n ${your_env_name} python=3.8
# 激活打包环境
conda activate ${your_env_name}
# 升级版本
pip install openai==0.10.3
# 安装成功后,调用代码仍然报错:
提示错误:AttributeError:module 'openai' has no attribute'Chatcompletion'
# 将其升级到0.27.7
pip install --upgrade openai
BINGO
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。