Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: error: { code: '404', message: 'Resource not found' }, #5550

Closed
5 tasks done
Abhicurio opened this issue May 26, 2024 · 19 comments
Closed
5 tasks done

Error: error: { code: '404', message: 'Resource not found' }, #5550

Abhicurio opened this issue May 26, 2024 · 19 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Abhicurio
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

const model = new OpenAI({

temperature: 0.9,
apiKey: process.env.AZURE_OPENAI_API_KEY,
azureOpenAIApiVersion: process.env.OPENAI_API_VERSION,
azureOpenAIApiInstanceName: process.env.AZURE_API_INSTANCE,
azureOpenAIApiDeploymentName: process.env.AZURE_DEPOYMENT_NAME,

});

Error Message and Stack Trace (if applicable)

Error: Azure OpenAI API instance name not found
at new OpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/embeddings.cjs:162:23)
at new AzureOpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/azure/embeddings.cjs:16:9)
at Object.getAns (/Users/abhijeet/Workspace/Node/UserBackend/lib/modules/v3/chatbot/facade.js:52:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Azure OpenAI API instance name not found
at new OpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/embeddings.cjs:162:23)
at new AzureOpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/azure/embeddings.cjs:16:9)
at Object.getAns (/Users/abhijeet/Workspace/Node/UserBackend/lib/modules/v3/chatbot/facade.js:52:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Description

When I am trying initialization the azure open instance it throws error

Error: Azure OpenAI API instance name not found
at new OpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/embeddings.cjs:162:23)
at new AzureOpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/azure/embeddings.cjs:16:9)
at Object.getAns (/Users/abhijeet/Workspace/Node/UserBackend/lib/modules/v3/chatbot/facade.js:52:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Azure OpenAI API instance name not found
at new OpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/embeddings.cjs:162:23)
at new AzureOpenAIEmbeddings (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/azure/embeddings.cjs:16:9)
at Object.getAns (/Users/abhijeet/Workspace/Node/UserBackend/lib/modules/v3/chatbot/facade.js:52:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

System Info

"@langchain/openai": "^0.0.33",

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label May 26, 2024
Copy link

dosubot bot commented May 26, 2024

To resolve the "Azure OpenAI API instance name not found" error, ensure that you are using the AzureOpenAI class instead of the OpenAI class, as the latter does not support Azure-specific configurations. Additionally, verify that all required parameters are correctly set.

Here is an example of how to correctly initialize an Azure OpenAI instance:

import { AzureOpenAI } from "@langchain/openai";

const model = new AzureOpenAI({
  azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
  azureOpenAIApiDeploymentName: process.env.AZURE_DEPLOYMENT_NAME,
  azureOpenAIApiInstanceName: process.env.AZURE_API_INSTANCE,
  azureOpenAIApiVersion: process.env.AZURE_API_VERSION,
  temperature: 0.9,
});

Ensure that the environment variables AZURE_OPENAI_API_KEY, AZURE_DEPLOYMENT_NAME, AZURE_API_INSTANCE, and AZURE_API_VERSION are correctly set and match the details of your Azure OpenAI service [1][2][3][4].

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.

@jacoblee93
Copy link
Collaborator

Can you try the Dosu comment above?

Docs here: https://js.langchain.com/v0.2/docs/integrations/chat/azure

@Abhicurio
Copy link
Author

@jacoblee93 Please check below code which i am trying with
const model = new AzureOpenAI({
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
azureOpenAIApiInstanceName: process.env.AZURE_API_INSTANCE,
azureOpenAIApiVersion: process.env.AZURE_API_VERSION,
azureOpenAIApiDeploymentName: process.env.AZURE_DEPLOYMENT_NAME,
temperature: 0.9,
});
Screenshot 2024-05-26 at 9 45 24 PM

and getting error Error: Azure OpenAI API deployment name not found
at new OpenAI (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/llms.cjs:311:23)
at new AzureOpenAI (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/azure/llms.cjs:22:9)
at Object.getAns (/Users/abhijeet/Workspace/Node/UserBackend/lib/modules/v3/chatbot/facade.js:39:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Help me with what I am doing wrong

@jacoblee93
Copy link
Collaborator

How are you importing the module? Are you using the AD provider? And can you share your package.json?

I wonder if this is related to #5521

@Abhicurio
Copy link
Author

The issue is i am not using the same key name which langchain provide in docs in .env file .
when I add same key in .env this error gone
now I am getting 404 resource not found error
NotFoundError: 404 Resource not found
at APIError.generate (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/openai/error.js:54:20)
at AzureOpenAI.makeStatusError (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/openai/core.js:263:33)
at AzureOpenAI.makeRequest (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/openai/core.js:306:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/abhijeet/Workspace/Node/UserBackend/node_modules/@langchain/openai/dist/azure/embeddings.cjs:67:29
at async RetryOperation._fn (/Users/abhijeet/Workspace/Node/UserBackend/node_modules/p-retry/index.js:50:12) {
status: 404,
headers: {
'apim-request-id': '739b8e6f-715c-4446-8150-60c63c4cb311',
'content-length': '56',
'content-type': 'application/json',
date: 'Sun, 26 May 2024 16:51:03 GMT',
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
'x-content-type-options': 'nosniff'
},
request_id: undefined,
error: { code: '404', message: 'Resource not found' },
code: '404',
param: undefined,
type: undefined,
attemptNumber: 1,
retriesLeft: 6
}
I am providing correct API key, instance name , API version correctly I double check it
@jacoblee93 Please help

@jacoblee93
Copy link
Collaborator

I'm so confused. Can you answer my questions above?

@Abhicurio
Copy link
Author

package.json
facade.txt
@jacoblee93 I am attaching my project pakage.json file along with langchain function file please check and help

@jeasonnow
Copy link
Contributor

Your issue is related to #5521 , but you can easily resolve it by changing the environment variable names to those conventionally used within langchainjs. @Abhicurio

AZURE_API_INSTANCE -> AZURE_OPENAI_API_INSTANCE_NAME
AZURE_DEPOYMENT_NAME -> AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME | AZURE_OPENAI_API_DEPLOYMENT_NAME

And use like this.

const model = new OpenAI({
  temperature: 0.9,
});

@Abhicurio
Copy link
Author

Your issue is related to #5521 , but you can easily resolve it by changing the environment variable names to those conventionally used within langchainjs. @Abhicurio

AZURE_API_INSTANCE -> AZURE_OPENAI_API_INSTANCE_NAME AZURE_DEPOYMENT_NAME -> AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME | AZURE_OPENAI_API_DEPLOYMENT_NAME

And use like this.

const model = new OpenAI({
  temperature: 0.9,
});

Hi @jeasonnow
I've updated the text to make it clearer:

"I changed the environment variable to fix the issue, but now I'm getting an error: { code: '404', message: 'Resource not found' }. When I try to access the Azure URL directly, it works, but when I use the langchain module, it throws a 404 resource not found error. I've attached my code file and package.json file. Can you take a look and see what mistake I'm making?"

@Abhicurio Abhicurio changed the title Error: Azure OpenAI API instance name not found Error: error: { code: '404', message: 'Resource not found' }, May 27, 2024
@jeasonnow
Copy link
Contributor

jeasonnow commented May 27, 2024

Your issue is related to #5521 , but you can easily resolve it by changing the environment variable names to those conventionally used within langchainjs. @Abhicurio
AZURE_API_INSTANCE -> AZURE_OPENAI_API_INSTANCE_NAME AZURE_DEPOYMENT_NAME -> AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME | AZURE_OPENAI_API_DEPLOYMENT_NAME
And use like this.

const model = new OpenAI({
  temperature: 0.9,
});

Hi @jeasonnow I've updated the text to make it clearer:

"I changed the environment variable to fix the issue, but now I'm getting an error: { code: '404', message: 'Resource not found' }. When I try to access the Azure URL directly, it works, but when I use the langchain module, it throws a 404 resource not found error. I've attached my code file and package.json file. Can you take a look and see what mistake I'm making?"

Okay, I understand. Could you please provide the specific details of the request you made through the azure REST API? A curl command would help me better analyze the issue.

Do not leak your critical information: apiKey instanceName

@Abhicurio
Copy link
Author

Your issue is related to #5521 , but you can easily resolve it by changing the environment variable names to those conventionally used within langchainjs. @Abhicurio
AZURE_API_INSTANCE -> AZURE_OPENAI_API_INSTANCE_NAME AZURE_DEPOYMENT_NAME -> AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME | AZURE_OPENAI_API_DEPLOYMENT_NAME
And use like this.

const model = new OpenAI({
  temperature: 0.9,
});

Hi @jeasonnow I've updated the text to make it clearer:
"I changed the environment variable to fix the issue, but now I'm getting an error: { code: '404', message: 'Resource not found' }. When I try to access the Azure URL directly, it works, but when I use the langchain module, it throws a 404 resource not found error. I've attached my code file and package.json file. Can you take a look and see what mistake I'm making?"

Okay, I understand. Could you please provide the specific details of the request you made through the azure REST API? A curl command would help me better analyze the issue.

Do not leak your critical information: apiKey instanceName

@jeasonnow I am using langchain npm module
const {
AzureOpenAI,
} = require("@langchain/openai");

const model = new AzureOpenAI({
temperature: 0.9,
});

@jeasonnow
Copy link
Contributor

Did you use AZURE_OPENAI_BASE_PATH? @Abhicurio

@Abhicurio
Copy link
Author

Abhicurio commented May 27, 2024

AZURE_OPENAI_BASE_PATH

Yes i used , it is in my .env file
here below are the keys is in .env file AZURE_OPENAI_API_KEY=""
AZURE_OPENAI_API_VERSION=
AZURE_OPENAI_API_INSTANCE_NAME=
AZURE_OPENAI_API_DEPLOYMENT_NAME=
AZURE_OPENAI_BASE_PATH=
@jeasonnow

@jeasonnow
Copy link
Contributor

export function getEndpoint(config: OpenAIEndpointConfig) {
const {
azureOpenAIApiDeploymentName,
azureOpenAIApiInstanceName,
azureOpenAIApiKey,
azureOpenAIBasePath,
baseURL,
azureADTokenProvider,
} = config;
if (
azureOpenAIApiKey &&
azureOpenAIBasePath &&
azureOpenAIApiDeploymentName
) {
return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
}
if (azureOpenAIApiKey || azureADTokenProvider) {
if (!azureOpenAIApiInstanceName) {
throw new Error(
"azureOpenAIApiInstanceName is required when using azureOpenAIApiKey"
);
}
if (!azureOpenAIApiDeploymentName) {
throw new Error(
"azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey"
);
}
return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;
}
return baseURL;
}

If you used AZURE_OPENAI_BASE_PATH, it will generate a baseURL that matches your configuration. Please first confirm that your basePath is accessible.

@Abhicurio
Copy link
Author

@jeasonnow
Screenshot 2024-05-27 at 3 06 32 PM
I have put the console for .env file and I am able to access the baseurl

@jeasonnow
Copy link
Contributor

jeasonnow commented May 27, 2024

Please check the source code I sent. If you declare AZURE_OPENAI_BASE_PATH here, your baseURL will be ${AZURE_OPENAI_BASE_PATH}/${AZURE_OPENAI_API_DEPLOYMENT_NAME}, which is clearly incorrect. If you want to ensure normal usage, please remove AZURE_OPENAI_BASE_PATH or set AZURE_OPENAI_BASE_PATH to https://dev-curio.openai.azure.com/openai/deployments.

@Abhicurio
Copy link
Author

@jeasonnow Thanks you so much it is working now
issue is azure providing the baseUrl that need openai/deployments after that

Thanks a lot @jeasonnow

@jacoblee93
Copy link
Collaborator

You're the best @jeasonnow!

@brja
Copy link

brja commented Aug 18, 2024

@jeasonnow

I confirm that appending the postfix '/openai/deployments' to the AZURE_OPENAI_BASE_PATH resolves the issue. However, I am wondering if the Python version is more resilient when this postfix is omitted.

from langchain_openai import AzureChatOpenAI

llm = AzureChatOpenAI(
    ...
    azure_endpoint="NOTE THAT THIS DOES NOT NEED THE 'openai/deployments' POSTFIX"
    ...
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

4 participants