英文:
Why am I getting an authentication error when trying to run a LangChain tutorial on FAISS vector database with OpenAI API?
问题
我遵循了一个YouTube LangChain教程,教你如何在5分钟内使用PDF数据创建自己的ChatGPT,教程名为**Create Your Own ChatGPT with PDF Data in 5 Minutes (LangChain Tutorial)
**,这是Colab笔记本的链接 link,作者在视频描述下方提供了这个工作的链接。我没有修改他的代码很多,只是将OpenAPI密钥更改为我的(不是免费计划)。
当我尝试运行单元格中的代码时,我想知道为什么会出现上图中显示的错误?
我期望能够创建FAISS向量数据库。
英文:
I follow a YouTube LangChain tutorial where it teaches Create Your Own ChatGPT with PDF Data in 5 Minutes (LangChain Tutorial)
and here is the colab notebook link provided by the author for his work below the video description. I didn't modify a lot of his codes where I just changed the OpenAPI key with my one (not free plan).
Can I know why I got this error as shown in the diagram above when I try to run the code in the cell?
I expect the FAISS vector database can be created.
答案1
得分: 2
更新:(2023年5月29日)
为了在Microsoft Azure端点中使用该库,您需要设置OPENAI_API_TYPE
,OPENAI_API_BASE
,OPENAI_API_KEY
,以及可选的API_VERSION
。OPENAI_API_TYPE
必须设置为'azure'
,其他参数对应于您的端点属性。此外,部署名称必须作为模型参数传递。
请参考以下示例:
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_BASE"] = "https://<your-endpoint.openai.azure.com/>"
os.environ["OPENAI_API_KEY"] = "your AzureOpenAI key"
from langchain.embeddings.openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(
deployment="your-embeddings-deployment-name",
model="your-embeddings-model-name",
api_base="https://your-endpoint.openai.azure.com/",
api_type="azure",
)
对于LLM模型也是一样的。参考您提供的笔记本链接,以下是示例:
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2022-12-01"
os.environ["OPENAI_API_BASE"] = "..."
os.environ["OPENAI_API_KEY"] = "..."
# 导入Azure OpenAI
from langchain.llms import AzureOpenAI
# 用您自己的部署名称替换
chain = load_qa_chain(
AzureOpenAI(
deployment_name="td2",
model_name="text-davinci-002",
),
chain_type="stuff",
)
初始怀疑
当出现AuthenticationError
时,可能是由于API密钥或令牌存在问题引起的。这可能是因为它无效。如果问题仍然存在,可能是由于小错误,如拼写错误或格式错误引起的。如果问题仍然存在,请尝试使用不同的/新的API密钥。
英文:
Update: (29th may, 2023)
In order to use the library with Microsoft Azure endpoints, you need to set the OPENAI_API_TYPE
, OPENAI_API_BASE
, OPENAI_API_KEY
, and optionally API_VERSION
. The OPENAI_API_TYPE
must be set to 'azure'
and the others correspond to the properties of your endpoint. In addition, the deployment name must be passed as the model parameter.
See the below example:
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_BASE"] = "https://<your-endpoint.openai.azure.com/"
os.environ["OPENAI_API_KEY"] = "your AzureOpenAI key"
from langchain.embeddings.openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(
deployment="your-embeddings-deployment-name",
model="your-embeddings-model-name",
api_base="https://your-endpoint.openai.azure.com/",
api_type="azure",
)
The same goes for the LLM model. See the below example with reference to your provided notebook link:
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2022-12-01"
os.environ["OPENAI_API_BASE"] = "..."
os.environ["OPENAI_API_KEY"] = "..."
# Import Azure OpenAI
from langchain.llms import AzureOpenAI
# Replace the deployment name with your own
chain = load_qa_chain(
AzureOpenAI(
deployment_name="td2",
model_name="text-davinci-002",
),
chain_type="stuff",
)
Initial suspicion
AuthenticationError
occurs when there's an issue with your API key or token. It could be because it's invalid. This may happen if there's a small mistake, like a typo or a formatting error. Try with a different/new API key if the issue persists.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论