Open glejdis opened 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.
🤖
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.
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.
@dosubot NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
🤖
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:
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.
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.
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.
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.
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:
I hope this helps! If you have any other questions, feel free to ask.
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.
also having the same error with OpenAI()
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])
I have the same issue, which has to do with API VERSION 2023-11-01 vs 2023-07-01-Preview (which worked beforehand...)
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",
)
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)
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
Hi @glejdis, Did you get any solution to this issue? I am also facing the same issue.
Any news on this?
Hello, I have resolved this using api version 2024-02-15-preview
instead of Model version displayed in azure table 0613
any new?
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
it worked! Where did you get the api version?I check Azure document and cloud not find information about the version.
To address the NotFoundError
with error code 404 when using the AzureChatOpenAI
class from LangChain, here are specific steps to resolve the issue:
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"
.
Check Deployment Name: The deployment_name
in the AzureChatOpenAI
constructor must match the "Model deployment name" in the Azure portal.
API Key and Azure AD Token: Confirm that AZURE_OPENAI_API_KEY
and AZURE_OPENAI_AD_TOKEN
are correctly set for authentication.
OpenAI Package: Ensure the openai
Python package is installed, as it's required for API calls.
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.
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.
To continue the conversation, mention @dosu.
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
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
To resolve the NotFoundError
with error code 404 when using AzureChatOpenAI
from LangChain, ensure the following configurations are correct:
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.
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.
Deployment Name: The deployment_name
must exactly match the one in the Azure portal. This is a common source of the 404 error.
API Key and Environment Variables: Ensure your AZURE_OPENAI_API_KEY
and other environment variables like AZURE_OPENAI_ENDPOINT
are correctly set.
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.
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.
To continue the conversation, mention @dosu.
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
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
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:
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"
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",
)
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.
To continue the conversation, mention @dosu.
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
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
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:
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.
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.
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.
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.
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.
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.
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.
To continue the conversation, mention @dosu.
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
It works for me, tks
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
This worked for me! Thank you :)
changed to newest preview (2024-07-01-preview
) resolved my 404, too.
Hello, I have resolved this using api version
2024-02-15-preview
instead of Model version displayed in azure table0613
thanks this solved the problem
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