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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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