Langchain, 调用Open AI

我正在按照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

Related Posts

Keras Dense层输入未被展平

这是我的测试代码: from keras import…

无法将分类变量输入随机森林

我有10个分类变量和3个数值变量。我在分割后直接将它们…

如何在Keras中对每个输出应用Sigmoid函数?

这是我代码的一部分。 model = Sequenti…

如何选择类概率的最佳阈值?

我的神经网络输出是一个用于多标签分类的预测类概率表: …

在Keras中使用深度学习得到不同的结果

我按照一个教程使用Keras中的深度神经网络进行文本分…

‘MatMul’操作的输入’b’类型为float32,与参数’a’的类型float64不匹配

我写了一个简单的TensorFlow代码,但不断遇到T…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注