Why am I getting an authentication error when trying to run a LangChain tutorial on FAISS vector database with OpenAI API?

huangapple go评论75阅读模式
英文:

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).

Why am I getting an authentication error when trying to run a LangChain tutorial on FAISS vector database with OpenAI API?
Why am I getting an authentication error when trying to run a LangChain tutorial on FAISS vector database with OpenAI API?
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_TYPEOPENAI_API_BASEOPENAI_API_KEY,以及可选的API_VERSIONOPENAI_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 &#39;azure&#39; 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[&quot;OPENAI_API_TYPE&quot;] = &quot;azure&quot;
os.environ[&quot;OPENAI_API_BASE&quot;] = &quot;https://&lt;your-endpoint.openai.azure.com/&quot;
os.environ[&quot;OPENAI_API_KEY&quot;] = &quot;your AzureOpenAI key&quot;

from langchain.embeddings.openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(
    deployment=&quot;your-embeddings-deployment-name&quot;,
    model=&quot;your-embeddings-model-name&quot;,
    api_base=&quot;https://your-endpoint.openai.azure.com/&quot;,
    api_type=&quot;azure&quot;,
)

The same goes for the LLM model. See the below example with reference to your provided notebook link:

import os

os.environ[&quot;OPENAI_API_TYPE&quot;] = &quot;azure&quot;
os.environ[&quot;OPENAI_API_VERSION&quot;] = &quot;2022-12-01&quot;
os.environ[&quot;OPENAI_API_BASE&quot;] = &quot;...&quot;
os.environ[&quot;OPENAI_API_KEY&quot;] = &quot;...&quot;

# Import Azure OpenAI
from langchain.llms import AzureOpenAI

# Replace the deployment name with your own
chain = load_qa_chain(
    AzureOpenAI(
        deployment_name=&quot;td2&quot;,
        model_name=&quot;text-davinci-002&quot;,
    ),
    chain_type=&quot;stuff&quot;,
)

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.

huangapple
  • 本文由 发表于 2023年5月24日 17:28:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322025.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定