( "The api_key client option must be set either by passing api_key to the client...

2025年10月08日 15:36 响应: 60.00秒 状态: error

🚨 错误信息

Traceback (most recent call last): File "D:\新建文件夹\langchain-base\构建聊天机器人.py", line 8, in <module> model = ChatOpenAI(model="gpt-3.5-turbo") File "C:\Users\27717\AppData\Roaming\Python\Python313\site-packages\langchain_core\load\serializable.py", line 115, in __init__ super().__init__(*args, **kwargs) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "D:\software\Python\Lib\site-packages\pydantic\main.py", line 253, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) File "C:\Users\27717\AppData\Roaming\Python\Python313\site-packages\langchain_openai\chat_models\base.py", line 825, in validate_environment self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type] ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\software\Python\Lib\site-packages\openai\_client.py", line 135, in __init__ raise OpenAIError( "The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable" ) openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

🤖 AI解决方案