E:\pythonProject\venv\Scripts\python.exe E:\pythonProject\venv\1.py Traceback (most recent call last): File "E:\pythonProject\venv\1.py", line 8, in <module> response = openai.Completion.create( File "E:\pythonProject\venv\lib\site-packages\openai\api_resources\completion.py", line 25, in create return super().create(*args, **kwargs) File "E:\pythonProject\venv\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 149, in create ) = cls.__prepare_create_request( File "E:\pythonProject\venv\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 106, in __prepare_create_request requestor = api_requestor.APIRequestor( File "E:\pythonProject\venv\lib\site-packages\openai\api_requestor.py", line 138, in __init__ self.api_key = key or util.default_api_key() File "E:\pythonProject\venv\lib\site-packages\openai\util.py", line 186, in default_api_key raise openai.error.AuthenticationError( openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details. 进程已结束,退出代码1
时间: 2023-07-21 17:03:41 浏览: 218
PyCharm-错误-找不到指定文件python.exe的解决方法
5星 · 资源好评率100%
这个错误提示显示你在代码中没有提供OpenAI的API密钥。你需要在代码中设置你的API密钥,才能成功调用OpenAI的服务。你可以按照错误提示中的建议,使用`openai.api_key`来设置API密钥,或者将你的API密钥存储在一个文件中,并使用`openai.api_key_path`来指定密钥文件的路径。你可以在OpenAI的网站上生成API密钥,并且可以参考链接 https://platform.openai.com/account/api-keys 来获取详细说明。
阅读全文