langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.75k stars 15.34k forks source link

NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}} when using openai==1.2.3 and langchain==0.0.335 #13284

Open glejdis opened 1 year ago

glejdis commented 1 year ago

System Info

from langchain.chat_models import AzureChatOpenAI

llm_chat = AzureChatOpenAI(deployment_name="gpt-4_32k", model_name = 'gpt-4-32k', openai_api_version=openai.api_version, temperature=0)

from langchain.chains import LLMChain from langchain.prompts import PromptTemplate

prompt = PromptTemplate( input_variables = ["text"], template="{text}" )

llmchain = LLMChain(llm=llm_chat, prompt=prompt) llmchain.run(text)

NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

Who can help?

No response

Information

Related Components

Reproduction

openai==1.2.3 and langchain==0.0.335

from langchain.chat_models import AzureChatOpenAI text = "Where is Germany located?" llm_chat = AzureChatOpenAI(deployment_name="gpt-4_32k", model_name = 'gpt-4-32k', openai_api_version=openai.api_version, temperature=0)

from langchain.chains import LLMChain from langchain.prompts import PromptTemplate

prompt = PromptTemplate( input_variables = ["text"], template="{text}" )

llmchain = LLMChain(llm=llm_chat, prompt=prompt) llmchain.run(text)

Expected behavior

In europe

dosubot[bot] commented 1 year ago

🤖

Hello @glejdis,

Nice to meet you! I'm a bot here to assist you while we wait for a human maintainer. I'm designed to help solve bugs, answer questions, and guide you on becoming a contributor. Now, let's dive into your issue. I'll be back with a full answer shortly.

dosubot[bot] commented 1 year ago

🤖

The NotFoundError with error code 404 usually indicates that the requested resource could not be found on the server. In the context of LangChain and OpenAI, this could mean that the model you're trying to access does not exist or is not available.

Based on the information provided, it seems like the AzureChatOpenAI class is being used, which is a wrapper for the Azure OpenAI Chat Completion API. This class requires certain parameters to be set, such as the openai_api_base, openai_api_version, deployment_name, and openai_api_key.

The error message suggests that the deployment_name you're trying to access might not exist or is not available. Please ensure that the deployment_name matches exactly with the one set up in Azure. If the deployment was just created, it might take a few minutes for it to be ready, so waiting a few minutes before trying again is advised.

Here's the corrected code snippet:

from langchain.chat_models import AzureChatOpenAI
from langchain.schema import HumanMessage

BASE_URL = "https://<your-resource-name>.openai.azure.com"
API_KEY = "<your-api-key>"
DEPLOYMENT_NAME = "<your-deployment-name>"

model = AzureChatOpenAI(
    openai_api_base=BASE_URL,
    openai_api_version="2023-03-15-preview",
    deployment_name=DEPLOYMENT_NAME,
    openai_api_key=API_KEY,
    openai_api_type="azure",
)

print(model(
    [
        HumanMessage(
            content="Translate this sentence from English to French. I love programming."
        )
    ]
))

Replace <your-resource-name>, <your-api-key>, and <your-deployment-name> with the actual Azure resource name, API key, and deployment name respectively.

If this solution doesn't work, consider upgrading to the latest version of LangChain. If this is a bug that could impact other users, a pull request with the necessary changes can be made.

For more information, you can refer to these similar solved issues:

I hope this helps! If you have any other questions, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

glejdis commented 1 year ago

@dosubot NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

dosubot[bot] commented 1 year ago

🤖

Based on the information you've provided and the similar issues I found in the LangChain repository, the NotFoundError with code 404 indicating 'Resource not found' could be due to a few reasons:

  1. Incorrect Azure Endpoint: The Azure endpoint you're using might be incorrect. The endpoint should be in the format https://example-resource.azure.openai.com/. Make sure you're using the correct endpoint.

  2. Incorrect Deployment Name: The deployment name you're using might be incorrect. The deployment name should be the same as the "Model deployment name" in the Azure portal. Make sure you're using the correct deployment name.

  3. Incorrect API Version: The API version you're using might be incorrect. The API version should be in the format 2023-05-15. Make sure you're using the correct API version.

  4. Incorrect API Key: The API key you're using might be incorrect. The API key should be the same as the "AZURE_OPENAI_API_KEY" in the Azure portal. Make sure you're using the correct API key.

  5. Incorrect Model Version: The model version you're using might be incorrect. The model version should be the same as the "model_version" in the Azure portal. Make sure you're using the correct model version.

If all the above parameters are correct, then the issue might be with the OpenAI Python package version. Make sure you're using the correct version of the OpenAI Python package.

In the code, the AzureChatOpenAI class is trying to create a client for the Azure OpenAI API using the provided parameters. If any of these parameters are incorrect, it will not be able to create the client and will throw a NotFoundError.

In the context shared, it's also important to note that the AzureChatOpenAI class requires the openai_api_version and azure_deployment parameters. If these are not provided or incorrect, it could also lead to a NotFoundError. Additionally, the model_version parameter can be provided to the AzureChatOpenAI class to distinguish between different versions of the model. If the model_version is incorrect, it could potentially lead to a NotFoundError.

Here are the links to the similar issues I found in the LangChain repository:

  1. Azure OpenAI with deployment_id is not working.
  2. openai.error.InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.
  3. Azure OpenAI - Exception has occurred: InvalidRequestError Resource not found

I hope this helps! If you have any other questions, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

alkhawli commented 1 year ago

also having the same error with OpenAI()

kottofy commented 12 months ago

Seems like it has to do with the api_base. I added /openai on to the end of my endpoint and it worked.

from langchain.chat_models import AzureChatOpenAI
from langchain.schema import HumanMessage

OPENAI_API_BASE="https://MY_AOAI.openai.azure.com" + "/openai"
OPENAI_API_KEY=""
OPENAI_API_VERSION="2023-05-15"
OPENAI_API_TYPE="azure"
DEPLOYMENT_NAME_GPT_4="gpt-4-32k"

llm = AzureChatOpenAI(
    openai_api_base= OPENAI_API_BASE,
    openai_api_key=OPENAI_API_KEY,
    openai_api_version=OPENAI_API_VERSION,
    openai_api_type= OPENAI_API_TYPE,
    model_name=DEPLOYMENT_NAME_GPT_4,
    temperature=0.0
)

message = HumanMessage(
    content="Translate this sentence from English to French. I love programming."
)
llm([message])
as-km commented 12 months ago

I have the same issue, which has to do with API VERSION 2023-11-01 vs 2023-07-01-Preview (which worked beforehand...)

Swain0114 commented 11 months ago

I'm currently using LangChain version 0.0.336 and OpenAI version 1.3.4. Instead of using the openai_api_base, I've opted for azure_endpoint, which seems to be functioning well. It's important to note that if your OpenAI version is 1.0.0 or higher, the AzureChatOpenAI class will automatically reformat your OpenAI API base. I believe this reformatting is the root of the issue.

            azure_llm = AzureChatOpenAI(
                deployment_name=deploy_name,
                openai_api_type=os.getenv("AZURE_OPENAI_TYPE"),
                openai_api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
                openai_api_key=self.openai_api_key,
                azure_endpoint="https://{YOUR_ENDPOINT}.openai.azure.com/openai/deployments/{DEPLOYMENT_NAME}/chat/completions?api-version=2023-07-01-preview",
            )
ashishkumardas1025 commented 11 months ago

I am facing the same error. Can any one help me on this. I also tried using the Chromadb but facing the same error.

docsearch = FAISS.from_documents(texts, embeddings)

dchinn1 commented 11 months ago

I am facing the same error. Can any one help me on this. I also tried using the Chromadb but facing the same error.

docsearch = FAISS.from_documents(texts, embeddings)

Make sure you're using AzureOpenAIEmbeddings and not OpenAIEmbeddings, and you include as a parameter for AzureOpenAIEmbeddings: azure_deployment = ... # <- add your deployment name here

This answer helped me immensely with what I expect is a similar issue to yours (embeddings endpoint 404ing)

https://github.com/langchain-ai/langchain/issues/14018#issuecomment-1837144072

Anang1502 commented 10 months ago

Hi @glejdis, Did you get any solution to this issue? I am also facing the same issue.

giulio-utf commented 8 months ago

Any news on this?

janantala commented 7 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

yuvaldream commented 7 months ago

any new?

35sui-com commented 6 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

it worked! Where did you get the api version?I check Azure document and cloud not find information about the version.

dosubot[bot] commented 6 months ago

To address the NotFoundError with error code 404 when using the AzureChatOpenAI class from LangChain, here are specific steps to resolve the issue:

  1. Verify Environment Variables: Ensure AZURE_OPENAI_ENDPOINT and OPENAI_API_VERSION are correctly set. The endpoint should match https://example-resource.azure.openai.com/, and a supported API version is "2023-05-15".

  2. Check Deployment Name: The deployment_name in the AzureChatOpenAI constructor must match the "Model deployment name" in the Azure portal.

  3. API Key and Azure AD Token: Confirm that AZURE_OPENAI_API_KEY and AZURE_OPENAI_AD_TOKEN are correctly set for authentication.

  4. OpenAI Package: Ensure the openai Python package is installed, as it's required for API calls.

  5. API Version: The openai_api_version parameter should match a version supported by both the openai package and Azure OpenAI service. For using 2024-02-15-preview, verify its support in the official documentation.

  6. Error Handling: Review the error message for additional details and check the Azure portal for deployment status or configuration issues.

Compatibility between openai==1.2.3 and langchain==0.0.335 is known to have issues. The langchain-openai package requires a minimum openai version of 1.10.0.

The LLMChain class is designed for running queries against Language Learning Models (LLMs), formatting prompts, and generating responses from language models.

For more detailed guidance, refer to the AzureChatOpenAI Documentation and the AzureChatOpenAI Source Code.

#### Details **Sources** - [Replication of a complex Azure OpenAI request in langchain](https://github.com/langchain-ai/langchain/discussions/18549) - ['DeploymentNotFound', The API deployment for this resource does not exist.](https://github.com/langchain-ai/langchain/discussions/19996) - [ElasticVectorSearch Error similarity_search openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}](https://github.com/langchain-ai/langchain/issues/16032) - [Resource not found error trying to use chromadb with Azure Open AI](https://github.com/langchain-ai/langchain/issues/15878) - [openai.error.InvalidRequestError: Resource not found](https://github.com/langchain-ai/langchain/issues/7536) - [AzureChatOpenAI raises The API deployment for this resource does not exist when used with ConversationalRetrievalChain](https://github.com/langchain-ai/langchain/issues/7331) - [Agent Executor Error code: 404](https://github.com/langchain-ai/langchain/issues/15004) - [Issue: AzureOpenAI connection with SQL Database](https://github.com/langchain-ai/langchain/issues/8790) - [docs/docs/integrations/chat/azure_chat_openai.ipynb](https://github.com/langchain-ai/langchain/blob/master/docs/docs/integrations/chat/azure_chat_openai.ipynb) - [libs/partners/openai/langchain_openai/chat_models/azure.py](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/azure.py) - [libs/community/langchain_community/chat_models/azure_openai.py](https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/chat_models/azure_openai.py) - [libs/langchain/langchain/chains/llm.py](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/llm.py) - [libs/partners/openai/pyproject.toml](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/pyproject.toml)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

janantala commented 6 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

it worked! Where did you get the api version?I check Azure document and cloud not find information about the version.

From network inspector in https://oai.azure.com/portal chat

dosubot[bot] commented 6 months ago

To resolve the NotFoundError with error code 404 when using AzureChatOpenAI from LangChain, ensure the following configurations are correct:

  1. API Version: Use the correct API version, such as 2024-02-15-preview, as mentioned by a user who found it effective. This version should be supported by Azure OpenAI service.

  2. Azure Endpoint: Confirm your azure_endpoint is correctly set. It should include your specific resource name and possibly the /openai suffix as indicated by another user's successful attempt.

  3. Deployment Name: The deployment_name must exactly match the one in the Azure portal. This is a common source of the 404 error.

  4. API Key and Environment Variables: Ensure your AZURE_OPENAI_API_KEY and other environment variables like AZURE_OPENAI_ENDPOINT are correctly set.

  5. LangChain and OpenAI Package Versions: There are known compatibility issues with certain versions of LangChain and OpenAI. Ensure you're using compatible versions, with LangChain requiring openai library version to be at least 1.10.0.

  6. Model Invocation: Use the correct method and parameters for invoking the model as per LangChain documentation.

If after checking these configurations the issue persists, consider the API version 2024-02-15-preview instead of the model version displayed in the Azure table, as this has resolved the issue for others. Additionally, inspect the network inspector in the Azure portal for the correct API version if necessary.

#### Details **Sources** - [Replication of a complex Azure OpenAI request in langchain](https://github.com/langchain-ai/langchain/discussions/18549) - ['DeploymentNotFound', The API deployment for this resource does not exist.](https://github.com/langchain-ai/langchain/discussions/19996) - [Resource not found error trying to use chromadb with Azure Open AI](https://github.com/langchain-ai/langchain/issues/15878) - [Using AzureChatOpenAI](https://github.com/langchain-ai/langchain/issues/14238) - [openai.error.InvalidRequestError: Resource not found](https://github.com/langchain-ai/langchain/issues/7536) - [NotFoundError for OpenAI with gpt-3.5-turbo model](https://github.com/langchain-ai/langchain/issues/20441) - [AzureChatOpenAI raises The API deployment for this resource does not exist when used with ConversationalRetrievalChain](https://github.com/langchain-ai/langchain/issues/7331) - [langchain.document_loaders.generic GenericLoader not working on Azure OpenAI - InvalidRequestError: Resource Not Found, cannot detect declared resource](https://github.com/langchain-ai/langchain/issues/7298) - [libs/community/langchain_community/chat_models/azure_openai.py](https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/chat_models/azure_openai.py) - [libs/community/langchain_community/embeddings/azure_openai.py](https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/embeddings/azure_openai.py) - [libs/partners/openai/langchain_openai/chat_models/azure.py](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/azure.py) - [docs/docs/integrations/llms/azure_openai.ipynb](https://github.com/langchain-ai/langchain/blob/master/docs/docs/integrations/llms/azure_openai.ipynb) - [libs/cli/langchain_cli/namespaces/migrate/codemods/migrations/openai.json](https://github.com/langchain-ai/langchain/blob/master/libs/cli/langchain_cli/namespaces/migrate/codemods/migrations/openai.json) - [libs/partners/openai/langchain_openai/llms/azure.py](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/llms/azure.py) - [libs/partners/openai/pyproject.toml](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/pyproject.toml)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

35sui-com commented 6 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

it worked! Where did you get the api version?I check Azure document and cloud not find information about the version.

From network inspector in https://oai.azure.com/portal chat

Would you give me screenshot?I can't find your result,and I use the version as the following,langchain return Resource not found error

image
dosubot[bot] commented 6 months ago

To address the "Resource not found" error when using AzureChatOpenAI in LangChain, ensure you're using the correct API version. The recommended API version is 2023-06-01-preview. Here's how to configure it:

  1. Set the API Version: Make sure to set the AZURE_OPENAI_API_VERSION environment variable to "2023-06-01-preview". You can do this directly in your code before initializing the AzureChatOpenAI instance:

    import os
    
    os.environ["AZURE_OPENAI_API_VERSION"] = "2023-06-01-preview"
  2. Initialize AzureChatOpenAI Correctly: When creating an instance of AzureChatOpenAI, pass the openai_api_version parameter with the value "2023-06-01-preview":

    from langchain_openai import AzureChatOpenAI
    
    model = AzureChatOpenAI(
       openai_api_base=BASE_URL,
       openai_api_version="2023-06-01-preview",
       deployment_name=DEPLOYMENT_NAME,
       openai_api_key=API_KEY,
       openai_api_type="azure",
    )
  3. Verify API Version: It's crucial to use an API version supported by Azure OpenAI service. The 2023-06-01-preview version is based on the latest LangChain documentation. For the most current information, refer to the Azure OpenAI Service documentation.

By following these steps, you should be able to resolve the "Resource not found" error. If issues persist, verifying your Azure endpoint, deployment name, and API key for accuracy is recommended.

#### Details **Sources** - ['DeploymentNotFound', The API deployment for this resource does not exist.](https://github.com/langchain-ai/langchain/discussions/19996) - [Issue:The completion operation does not work with the specified model for azure openai api](https://github.com/langchain-ai/langchain/issues/12019) - [Using AzureChatOpenAI](https://github.com/langchain-ai/langchain/issues/14238) - [openai.error.InvalidRequestError: Resource not found](https://github.com/langchain-ai/langchain/issues/7536) - [KeyError: 'openai_api_version'](https://github.com/langchain-ai/langchain/issues/18632) - [AzureChatOpenAI raises The API deployment for this resource does not exist when used with ConversationalRetrievalChain](https://github.com/langchain-ai/langchain/issues/7331) - [langchain.document_loaders.generic GenericLoader not working on Azure OpenAI - InvalidRequestError: Resource Not Found, cannot detect declared resource](https://github.com/langchain-ai/langchain/issues/7298) - [libs/partners/openai/langchain_openai/chat_models/azure.py](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/azure.py) - [libs/community/langchain_community/chat_models/azure_openai.py](https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/chat_models/azure_openai.py) - [docs/docs/integrations/chat/azure_chat_openai.ipynb](https://github.com/langchain-ai/langchain/blob/master/docs/docs/integrations/chat/azure_chat_openai.ipynb) - [libs/partners/openai/langchain_openai/llms/azure.py](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/llms/azure.py) - [libs/community/langchain_community/embeddings/azure_openai.py](https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/embeddings/azure_openai.py) - [libs/partners/openai/langchain_openai/embeddings/azure.py](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/embeddings/azure.py)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

janantala commented 6 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

it worked! Where did you get the api version?I check Azure document and cloud not find information about the version.

From network inspector in https://oai.azure.com/portal chat

Would you give me screenshot?I can't find your result,and I use the version as the following,langchain return Resource not found error image

Screenshot 2024-05-03 at 11 14 06

dosubot[bot] commented 6 months ago

To address the "Resource not found" error when using AzureChatOpenAI in LangChain, it's essential to ensure your setup aligns with Azure's requirements and the expectations of the LangChain library. Here are some tailored steps and considerations:

  1. API Version: Utilize a supported API version. While 2024-02-15-preview has been mentioned as a workaround, it's crucial to use versions that are officially documented and supported for stability, such as 2023-06-01-preview. Experimenting with versions found through tools like network inspectors can be insightful but may lead to unstable integrations.

  2. Azure Endpoint Configuration: Your azure_endpoint must be correctly configured. It should include your specific resource name and, if successful for others, the /openai suffix. This detail is critical as the correct format of the endpoint URL is key to successful integration.

  3. Deployment Name Accuracy: The deployment name in your code must exactly match what is specified in the Azure portal. Discrepancies here are a common source of 404 errors.

  4. Environment Variables and API Key: Verify that your environment variables, such as AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT, are correctly set to match the values in the Azure portal.

  5. LangChain and OpenAI Package Versions: Ensure compatibility between LangChain and OpenAI versions to avoid errors. Consult the LangChain documentation or community discussions for recommendations on which versions work best together.

  6. Specifying API Version in Code: If encountering issues with the API version, directly specify it in your code when initializing the AzureChatOpenAI instance. This ensures you're using the correct version for your setup.

  7. Consult Azure Portal and Documentation: For accurate and up-to-date information regarding API versions and configurations, refer to the Azure OpenAI Service documentation and the Azure portal. While the network inspector tool can provide useful insights, be cautious with using features or versions that are not documented.

If you've followed these steps and continue to experience issues, sharing more specific details about your configuration, including exact error messages and code snippets, can help the community offer more targeted advice.

#### Details **About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

youkaisteve commented 5 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

It works for me, tks

AmrinKareem commented 3 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

This worked for me! Thank you :)

voytas75 commented 2 months ago

changed to newest preview (2024-07-01-preview) resolved my 404, too.

ahmedshafikk commented 2 months ago

Hello, I have resolved this using api version 2024-02-15-preview instead of Model version displayed in azure table 0613

thanks this solved the problem