Closed rossanodr closed 5 hours ago
I found a similar issue that was closed, which might be relevant to your problem:
To specify the azureOpenAIApiDeploymentName
and other related parameters programmatically in LangChain.js without relying on environment variables, you can directly pass these parameters as part of the configuration object when initializing the classes. Here's an example of how you can do this:
import { AzureChatOpenAI } from "@langchain/openai";
import { OpenAIEmbeddings } from "@langchain/openai";
// Initialize AzureChatOpenAI with manual deployment parameters
const model = new AzureChatOpenAI({
model: 'modelName',
azureOpenAIApiKey: 'your-api-key',
azureOpenAIApiDeploymentName: 'my-deployment-name',
azureOpenAIApiInstanceName: 'my-instance-name',
azureOpenAIApiVersion: 'your-api-version', // if needed
});
// Initialize OpenAIEmbeddings with manual API keys and deployment parameters
const embeddings = new OpenAIEmbeddings({
azureOpenAIApiKey: 'your-api-key',
azureOpenAIApiInstanceName: 'my-instance-name',
azureOpenAIApiDeploymentName: 'my-deployment-name',
model: "text-embedding-3-small",
});
This approach allows you to dynamically specify different deployment names and other configurations without relying on environment variables, providing the flexibility you need for projects with multiple deployment names [2][3].
To continue talking to Dosu, mention @dosu.
dynamically within the same proj @dosu, this is exactly what is not working.
To address the issue of dynamically specifying the azureOpenAIApiDeploymentName
and other related parameters without relying on environment variables, ensure that you are passing all necessary parameters directly in the configuration object when initializing the classes. If this approach is not working, double-check that all required parameters are correctly set and that there are no typos or missing values.
For AzureChatOpenAI
, make sure you include:
azureOpenAIApiKey
azureOpenAIApiDeploymentName
azureOpenAIApiInstanceName
For OpenAIEmbeddings
, ensure similar parameters are set if applicable.
If the problem persists, it might be due to a bug or limitation in the current version of LangChain.js. Consider checking for any updates or patches that might address this issue. If the problem continues, reviewing the implementation details of these classes might provide further insights into any overlooked configuration requirements.
To continue talking to Dosu, mention @dosu.
There's a conflict between AZURE_OPENAI_API_KEY and OPENAI_API_KEY. I had to rename AZURE_OPENAI_API_KEY, and now everything is working properly.
Checked other resources
Example Code
import { OpenAIEmbeddings } from "@langchain/openai"; import { AzureChatOpenAI } from "@langchain/openai"; // Attempting to initialize AzureChatOpenAI with manual deployment parameters const model = new AzureChatOpenAI({
model: 'modelName', azureOpenAIApiDeploymentName: 'my-deployment-name', azureOpenAIApiInstanceName: "my-instance-name", });
// Attempting to initialize OpenAIEmbeddings with manual API keys and deployment parameters const embeddings = new OpenAIEmbeddings({ openAIApiKey: process.env.OPENAI_API_KEY, model: "text-embedding-3-small", azureOpenAIApiKey: "", azureOpenAIApiInstanceName: "", azureOpenAIApiDeploymentName: "", });
Error Message and Stack Trace (if applicable)
β¨― Error: Azure OpenAI API deployment name not found
Description
When initializing
AzureChatOpenAI
orOpenAIEmbeddings
without relying solely on environment variables, the application defaults to using the deployment name defined in theAZURE_OPENAI_API_DEPLOYMENT_NAME
environment variable. This limitation prevents the use of multiple deployment names dynamically within the same project. Specifically:AzureChatOpenAI Initialization:
AzureChatOpenAI
with a specific deployment name manually results in an error if the environment variableAZURE_OPENAI_API_DEPLOYMENT_NAME
is not set.OpenAIEmbeddings Initialization:
OpenAIEmbeddings
to attempt accessing Azure embeddings using the deployment name defined in the environment variables.Desired Behavior: Allow developers to specify the
azureOpenAIApiDeploymentName
(and other related parameters) programmatically without being forced to rely on environment variables. This flexibility is essential for projects that utilize multiple deployment names and cannot have a single default deployment name.System Info
langchain@npm:0.2.20 ββ Instances: 1 ββ Version: 0.2.20 β ββ Dependencies ββ @langchain/core@npm:^0.2.18 β npm:0.2.31 ββ @langchain/openai@npm:>=0.1.0 <0.3.0 β npm:0.2.10 ββ @langchain/textsplitters@npm:~0.0.0 β npm:0.0.3 ββ binary-extensions@npm:^2.2.0 β npm:2.3.0 ββ js-tiktoken@npm:^1.0.12 β npm:1.0.12 ββ js-yaml@npm:^4.1.0 β npm:4.1.0 ββ jsonpointer@npm:^5.0.1 β npm:5.0.1 ββ langsmith@npm:^0.1.56-rc.1 β npm:0.1.64 ββ openapi-types@npm:^12.1.3 β npm:12.1.3 ββ p-retry@npm:4 β npm:4.6.2 ββ uuid@npm:^10.0.0 β npm:10.0.0 ββ yaml@npm:^2.2.1 β npm:2.6.0 ββ zod-to-json-schema@npm:^3.22.3 β npm:3.23.2 ββ zod@npm:^3.22.4 β npm:3.23.8