我一直在尝试使用langchain库的
ChatOpenAI
,I 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>