我正在按照Langchain的快速入门指南来调用Open AI进行大语言模型的测试。
https://python.langchain.com/docs/get_started/quickstart
在运行下面的Python代码时,我遇到了错误。
from langchain_openai import ChatOpenAIfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_core.output_parsers import StrOutputParserllm = ChatOpenAI(openai_api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")prompt = ChatPromptTemplate.from_messages([ ("system", "You are world class technical documentation writer."), ("user", "{input}")])chain = prompt | llm chain.invoke({"input": "how can langsmith help with testing?"})output_parser = StrOutputParser()chain = prompt | llm | output_parserchain.invoke({"input": "how can langsmith help with testing?"})
我收到了以下错误:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Python\Sysint_NPL2SQL\.venv\Lib\site-packages\openai\_base_client.py", line 902, in request ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Python\Sysint_NPL2SQL\.venv\Lib\site-packages\openai\_base_client.py", line 902, in request return self._request( ^^^^^^^^^^^^^^ File "c:\Python\Sysint_NPL2SQL\.venv\Lib\site-packages\openai\_base_client.py", line 993, in _request raise self._make_status_error_from_response(err.response) from Noneopenai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}PS C:\Python\Sysint_NPL2SQL> c:; cd 'c:\Python\Sysint_NPL2SQL'; & 'c:\Python\Sysint_NPL2SQL\.venv\Scripts\python.exe' 'c:\Users\yatanveer.singh\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '64396' '--' 'C:\Python\Sysint_NPL2SQL\langchaindemo.py'PS C:\Python\Sysint_NPL2SQL> c:; cd 'c:\Python\Sysint_NPL2SQL'; & 'c:\Python\Sysint_NPL2SQL\.venv\Scripts\python.exe' 'c:\Users\yatanveer.singh\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '64413' '--' 'C:\Python\Sysint_NPL2SQL\langchaindemo.py'
任何建议都会有所帮助。
谢谢Yatan
回答:
你的代码在我的环境中可以正常运行。你收到的错误
openai.NotFoundError: Error code: 404
表明你的端点无法连接到OpenAI的API