-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Unable to Specify Azure OpenAI API Deployment Name Manually Without Environment Variable #7206
Comments
I found a similar issue that was closed, which might be relevant to your problem:
To specify the 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 address the issue of dynamically specifying the For
For 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. |
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
The text was updated successfully, but these errors were encountered: