0

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

enter image description here enter image description here 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.

林抿均
  • 33
  • 7
  • `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. Did you try with a different/new API key? – Rijoanul Hasan Shanto May 24 '23 at 12:21
  • @RijoanulHasanShanto This API key is provided by my company. They said this is a subscribed plan API key. – 林抿均 May 29 '23 at 08:29
  • Did you try using the API with your provided API key like on curl? try to see if the API is valid like below: ```curl https://api.openai.com/v1/embeddings \ -H "Content-Type: application/json" \ -H "Authorization: Bearer **************" \ -d '{ "input": "Hello", "model": "text-embedding-ada-002" }' ``` – Rijoanul Hasan Shanto May 29 '23 at 10:33
  • Oh, I haven't done that – 林抿均 May 29 '23 at 11:02
  • please don't share your full API key here, just use `d929*******` or something like that instead when sharing error logs. By looking at your API key, looks like it's not a valid API key. There should be a prefix with the key like `sk-d929*******` or something like that. – Rijoanul Hasan Shanto May 29 '23 at 11:41
  • @RijoanulHasanShanto Further information about how I got the key is from the Azure OpenAI service in Microsoft Azure, which my company creates. So, I clicked on the created OpenAI service in my portal and then clicked on the **Keys and Endpoint** tab in the sidebar under the **Resource Management** section. I then copy the key from there. – 林抿均 May 29 '23 at 12:09
  • @RijoanulHasanShanto Thanks for reminding me, I didn't notice I am sharing the API key publicly Here is the updated curl code: `curl "https://api.openai.com/v1/embeddings" -H "Content-Type: application/json" -H "Authorization: Bearer d92****************" -d "{\"input\": \"Hello, what is your name?\", \"model\": \"text-embedding-ada-002\"}"` – 林抿均 May 29 '23 at 12:11

1 Answers1

2

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.

  • Further information about how I got the key is from the Azure OpenAI service in the Microsoft Azure portal, which my company creates. So, I clicked on the created OpenAI service in my portal and then clicked on the **Keys and Endpoint** tab in the sidebar under the **Resource Management** section. I then copy the key from there. – 林抿均 May 29 '23 at 12:17
  • I see, you are using Azure OpenAI service. In that case, you must pass some extra information while declaring your embedding model. I've updated my answer as it's impossible to show some demos with proper formation here in the comment. See the updated answer and let me know the update from your end. @林抿均 – Rijoanul Hasan Shanto May 29 '23 at 15:15
  • And same goes for the `llm` (I added that too in the updated answer). You need to use `AzureOpenAI` instead of `OpenAI` when loading llm. @林抿均 – Rijoanul Hasan Shanto May 29 '23 at 15:22