ChatGPT-3 验证错误:在< empty message>OpenAPI API中

pftdvrlh  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(176)

我一直在尝试使用langchain库的ChatOpenAI,我pip安装langchain,并导入ChatOpenAI
我在colab上运行我的代码,所以我将openAI的API键设置为:

%env OPENAI_API_KEY= my_api_key

现在,当我尝试如下初始化ChatOpenAI时,它运行没有错误:

chat = ChatOpenAI(temperature=0.0,openai_organization='Personal')
chat

我得到以下结果:

ChatOpenAI(verbose=False, callbacks=None, callback_manager=None, client=<class 'openai.api_resources.chat_completion.ChatCompletion'>, model_name='gpt-3.5-turbo', temperature=0.0, model_kwargs={}, openai_api_key='my_api_key', openai_api_base='', openai_organization='Personal', openai_proxy='', request_timeout=None, max_retries=6, streaming=False, n=1, max_tokens=None)

但是当我试着运行它时:

customer_response = chat(customer_messages)

它会抛出以下错误:

---------------------------------------------------------------------------
AuthenticationError                       Traceback (most recent call last)
<ipython-input-64-a39359b08f39> in <cell line: 1>()
----> 1 customer_response = chat(customer_messages)

17 frames
/usr/local/lib/python3.10/dist-packages/openai/api_requestor.py in _interpret_response_line(self, rbody, rcode, rheaders, stream)
    761         stream_error = stream and "error" in resp.data
    762         if stream_error or not 200 <= rcode < 300:
--> 763             raise self.handle_error_response(
    764                 rbody, rcode, resp.data, rheaders, stream_error=stream_error
    765             )

AuthenticationError: <empty message>
p5fdfcr1

p5fdfcr11#

您的问题是在身份验证中,请确保“API_key”和“openai.organization”字段使用正确的值。
这段代码也可以帮助你:

import os
os.environ["OPENAI_API_KEY"] = "your_api_key"

相关问题