@langchain/openai 0.3.16 → 0.4.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ exports.AzureChatOpenAI = void 0;
4
4
  const openai_1 = require("openai");
5
5
  const chat_models_js_1 = require("../chat_models.cjs");
6
6
  const azure_js_1 = require("../utils/azure.cjs");
7
+ const env_1 = require("@langchain/core/utils/env");
7
8
  /**
8
9
  * Azure OpenAI chat model integration.
9
10
  *
@@ -433,16 +434,30 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
433
434
  };
434
435
  }
435
436
  constructor(fields) {
436
- const newFields = fields ? { ...fields } : fields;
437
- if (newFields) {
438
- // don't rewrite the fields if they are already set
439
- newFields.azureOpenAIApiDeploymentName =
440
- newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
441
- newFields.azureOpenAIApiKey =
442
- newFields.azureOpenAIApiKey ?? newFields.openAIApiKey;
443
- newFields.azureOpenAIApiVersion =
444
- newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
445
- }
437
+ const newFields = fields ? { ...fields } : {};
438
+ newFields.azureOpenAIApiDeploymentName =
439
+ newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
440
+ newFields.azureOpenAIApiKey =
441
+ newFields.azureOpenAIApiKey ??
442
+ newFields.openAIApiKey ??
443
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
444
+ newFields.azureOpenAIApiVersion =
445
+ newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
446
+ newFields.azureOpenAIApiInstanceName =
447
+ fields?.azureOpenAIApiInstanceName ??
448
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
449
+ newFields.azureOpenAIApiDeploymentName =
450
+ fields?.azureOpenAIApiDeploymentName ??
451
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME");
452
+ newFields.azureOpenAIApiVersion =
453
+ fields?.azureOpenAIApiVersion ??
454
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
455
+ newFields.azureOpenAIBasePath =
456
+ fields?.azureOpenAIBasePath ??
457
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
458
+ newFields.azureOpenAIEndpoint =
459
+ fields?.azureOpenAIEndpoint ??
460
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_ENDPOINT");
446
461
  super(newFields);
447
462
  }
448
463
  getLsParams(options) {
@@ -1,6 +1,7 @@
1
1
  import { AzureOpenAI as AzureOpenAIClient } from "openai";
2
2
  import { ChatOpenAI } from "../chat_models.js";
3
3
  import { getEndpoint } from "../utils/azure.js";
4
+ import { getEnvironmentVariable } from "@langchain/core/utils/env";
4
5
  /**
5
6
  * Azure OpenAI chat model integration.
6
7
  *
@@ -430,16 +431,30 @@ export class AzureChatOpenAI extends ChatOpenAI {
430
431
  };
431
432
  }
432
433
  constructor(fields) {
433
- const newFields = fields ? { ...fields } : fields;
434
- if (newFields) {
435
- // don't rewrite the fields if they are already set
436
- newFields.azureOpenAIApiDeploymentName =
437
- newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
438
- newFields.azureOpenAIApiKey =
439
- newFields.azureOpenAIApiKey ?? newFields.openAIApiKey;
440
- newFields.azureOpenAIApiVersion =
441
- newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
442
- }
434
+ const newFields = fields ? { ...fields } : {};
435
+ newFields.azureOpenAIApiDeploymentName =
436
+ newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
437
+ newFields.azureOpenAIApiKey =
438
+ newFields.azureOpenAIApiKey ??
439
+ newFields.openAIApiKey ??
440
+ getEnvironmentVariable("AZURE_OPENAI_API_KEY");
441
+ newFields.azureOpenAIApiVersion =
442
+ newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
443
+ newFields.azureOpenAIApiInstanceName =
444
+ fields?.azureOpenAIApiInstanceName ??
445
+ getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
446
+ newFields.azureOpenAIApiDeploymentName =
447
+ fields?.azureOpenAIApiDeploymentName ??
448
+ getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME");
449
+ newFields.azureOpenAIApiVersion =
450
+ fields?.azureOpenAIApiVersion ??
451
+ getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
452
+ newFields.azureOpenAIBasePath =
453
+ fields?.azureOpenAIBasePath ??
454
+ getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
455
+ newFields.azureOpenAIEndpoint =
456
+ fields?.azureOpenAIEndpoint ??
457
+ getEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
443
458
  super(newFields);
444
459
  }
445
460
  getLsParams(options) {
@@ -1047,31 +1047,19 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
1047
1047
  fields?.configuration?.apiKey ??
1048
1048
  (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
1049
1049
  this.apiKey = this.openAIApiKey;
1050
- this.azureOpenAIApiKey =
1051
- fields?.azureOpenAIApiKey ??
1052
- (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
1050
+ this.azureOpenAIApiKey = fields?.azureOpenAIApiKey;
1053
1051
  this.azureADTokenProvider = fields?.azureADTokenProvider ?? undefined;
1054
1052
  if (!this.azureOpenAIApiKey && !this.apiKey && !this.azureADTokenProvider) {
1055
1053
  throw new Error("OpenAI or Azure OpenAI API key or Token Provider not found");
1056
1054
  }
1057
- this.azureOpenAIApiInstanceName =
1058
- fields?.azureOpenAIApiInstanceName ??
1059
- (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
1060
- this.azureOpenAIApiDeploymentName =
1061
- fields?.azureOpenAIApiDeploymentName ??
1062
- (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME");
1063
- this.azureOpenAIApiVersion =
1064
- fields?.azureOpenAIApiVersion ??
1065
- (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
1066
- this.azureOpenAIBasePath =
1067
- fields?.azureOpenAIBasePath ??
1068
- (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
1055
+ this.azureOpenAIApiInstanceName = fields?.azureOpenAIApiInstanceName;
1056
+ this.azureOpenAIApiDeploymentName = fields?.azureOpenAIApiDeploymentName;
1057
+ this.azureOpenAIApiVersion = fields?.azureOpenAIApiVersion;
1058
+ this.azureOpenAIBasePath = fields?.azureOpenAIBasePath;
1059
+ this.azureOpenAIEndpoint = fields?.azureOpenAIEndpoint;
1069
1060
  this.organization =
1070
1061
  fields?.configuration?.organization ??
1071
1062
  (0, env_1.getEnvironmentVariable)("OPENAI_ORGANIZATION");
1072
- this.azureOpenAIEndpoint =
1073
- fields?.azureOpenAIEndpoint ??
1074
- (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_ENDPOINT");
1075
1063
  this.modelName = fields?.model ?? fields?.modelName ?? this.model;
1076
1064
  this.model = this.modelName;
1077
1065
  this.modelKwargs = fields?.modelKwargs ?? {};
@@ -1115,6 +1103,9 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
1115
1103
  // Streaming usage is not supported by Azure deployments, so default to false
1116
1104
  this.streamUsage = false;
1117
1105
  }
1106
+ if (this.model === "o1") {
1107
+ this.disableStreaming = true;
1108
+ }
1118
1109
  this.streaming = fields?.streaming ?? false;
1119
1110
  this.streamUsage = fields?.streamUsage ?? this.streamUsage;
1120
1111
  this.clientConfig = {
@@ -1042,31 +1042,19 @@ export class ChatOpenAI extends BaseChatModel {
1042
1042
  fields?.configuration?.apiKey ??
1043
1043
  getEnvironmentVariable("OPENAI_API_KEY");
1044
1044
  this.apiKey = this.openAIApiKey;
1045
- this.azureOpenAIApiKey =
1046
- fields?.azureOpenAIApiKey ??
1047
- getEnvironmentVariable("AZURE_OPENAI_API_KEY");
1045
+ this.azureOpenAIApiKey = fields?.azureOpenAIApiKey;
1048
1046
  this.azureADTokenProvider = fields?.azureADTokenProvider ?? undefined;
1049
1047
  if (!this.azureOpenAIApiKey && !this.apiKey && !this.azureADTokenProvider) {
1050
1048
  throw new Error("OpenAI or Azure OpenAI API key or Token Provider not found");
1051
1049
  }
1052
- this.azureOpenAIApiInstanceName =
1053
- fields?.azureOpenAIApiInstanceName ??
1054
- getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
1055
- this.azureOpenAIApiDeploymentName =
1056
- fields?.azureOpenAIApiDeploymentName ??
1057
- getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME");
1058
- this.azureOpenAIApiVersion =
1059
- fields?.azureOpenAIApiVersion ??
1060
- getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
1061
- this.azureOpenAIBasePath =
1062
- fields?.azureOpenAIBasePath ??
1063
- getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
1050
+ this.azureOpenAIApiInstanceName = fields?.azureOpenAIApiInstanceName;
1051
+ this.azureOpenAIApiDeploymentName = fields?.azureOpenAIApiDeploymentName;
1052
+ this.azureOpenAIApiVersion = fields?.azureOpenAIApiVersion;
1053
+ this.azureOpenAIBasePath = fields?.azureOpenAIBasePath;
1054
+ this.azureOpenAIEndpoint = fields?.azureOpenAIEndpoint;
1064
1055
  this.organization =
1065
1056
  fields?.configuration?.organization ??
1066
1057
  getEnvironmentVariable("OPENAI_ORGANIZATION");
1067
- this.azureOpenAIEndpoint =
1068
- fields?.azureOpenAIEndpoint ??
1069
- getEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
1070
1058
  this.modelName = fields?.model ?? fields?.modelName ?? this.model;
1071
1059
  this.model = this.modelName;
1072
1060
  this.modelKwargs = fields?.modelKwargs ?? {};
@@ -1110,6 +1098,9 @@ export class ChatOpenAI extends BaseChatModel {
1110
1098
  // Streaming usage is not supported by Azure deployments, so default to false
1111
1099
  this.streamUsage = false;
1112
1100
  }
1101
+ if (this.model === "o1") {
1102
+ this.disableStreaming = true;
1103
+ }
1113
1104
  this.streaming = fields?.streaming ?? false;
1114
1105
  this.streamUsage = fields?.streamUsage ?? this.streamUsage;
1115
1106
  this.clientConfig = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.3.16",
3
+ "version": "0.4.0-rc.0",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,7 +41,7 @@
41
41
  "zod-to-json-schema": "^3.22.3"
42
42
  },
43
43
  "peerDependencies": {
44
- "@langchain/core": ">=0.2.26 <0.4.0"
44
+ "@langchain/core": ">=0.3.29 <0.4.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@azure/identity": "^4.2.1",