赞
踩
由于科研需求
步骤:
1 申请API
https://platform.openai.com/docs/api-reference/introduction
2 得到一个密钥
3 放到上面的python 代码
# -*- coding:utf-8 -*-f import requests import openai openai.api_key = "sk-( 放自己的!!!!!!!)m6C" prompt = "how are you?" response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": prompt}, ] ) answer = response.choices[0].message.content.strip() print("答:", answer)
4代码报错
openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool
5 debug ,只需要更改版本即可,原理点击这个
如果有人出现了和我同样的问题,解决方案是卸载urllib3然后重装至1.25.11版本再重新运行一遍就可以。
在终端或命令提示符中卸载urllib3
pip uninstall urllib3
然后,您可以通过使用指定版本号的pip install命令来安装所需的版本:
pip install urllib3==1.25.11
成功返回结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。