@langchain/openai 0.0.26 → 0.0.27

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.
@@ -150,7 +150,7 @@ function convertMessagesToOpenAIParams(messages) {
150
150
  * // Create a new instance of ChatOpenAI with specific temperature and model name settings
151
151
  * const model = new ChatOpenAI({
152
152
  * temperature: 0.9,
153
- * modelName: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
153
+ * model: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
154
154
  * });
155
155
  *
156
156
  * // Invoke the model with a message and await the response
@@ -181,6 +181,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
181
181
  get lc_secrets() {
182
182
  return {
183
183
  openAIApiKey: "OPENAI_API_KEY",
184
+ apiKey: "OPENAI_API_KEY",
184
185
  azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
185
186
  organization: "OPENAI_ORGANIZATION",
186
187
  };
@@ -189,6 +190,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
189
190
  return {
190
191
  modelName: "model",
191
192
  openAIApiKey: "openai_api_key",
193
+ apiKey: "openai_api_key",
192
194
  azureOpenAIApiVersion: "azure_openai_api_version",
193
195
  azureOpenAIApiKey: "azure_openai_api_key",
194
196
  azureOpenAIApiInstanceName: "azure_openai_api_instance_name",
@@ -247,6 +249,12 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
247
249
  writable: true,
248
250
  value: "gpt-3.5-turbo"
249
251
  });
252
+ Object.defineProperty(this, "model", {
253
+ enumerable: true,
254
+ configurable: true,
255
+ writable: true,
256
+ value: "gpt-3.5-turbo"
257
+ });
250
258
  Object.defineProperty(this, "modelKwargs", {
251
259
  enumerable: true,
252
260
  configurable: true,
@@ -259,6 +267,12 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
259
267
  writable: true,
260
268
  value: void 0
261
269
  });
270
+ Object.defineProperty(this, "stopSequences", {
271
+ enumerable: true,
272
+ configurable: true,
273
+ writable: true,
274
+ value: void 0
275
+ });
262
276
  Object.defineProperty(this, "user", {
263
277
  enumerable: true,
264
278
  configurable: true,
@@ -301,6 +315,12 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
301
315
  writable: true,
302
316
  value: void 0
303
317
  });
318
+ Object.defineProperty(this, "apiKey", {
319
+ enumerable: true,
320
+ configurable: true,
321
+ writable: true,
322
+ value: void 0
323
+ });
304
324
  Object.defineProperty(this, "azureOpenAIApiVersion", {
305
325
  enumerable: true,
306
326
  configurable: true,
@@ -350,11 +370,14 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
350
370
  value: void 0
351
371
  });
352
372
  this.openAIApiKey =
353
- fields?.openAIApiKey ?? (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
373
+ fields?.apiKey ??
374
+ fields?.openAIApiKey ??
375
+ (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
376
+ this.apiKey = this.openAIApiKey;
354
377
  this.azureOpenAIApiKey =
355
378
  fields?.azureOpenAIApiKey ??
356
379
  (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
357
- if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
380
+ if (!this.azureOpenAIApiKey && !this.apiKey) {
358
381
  throw new Error("OpenAI or Azure OpenAI API key not found");
359
382
  }
360
383
  this.azureOpenAIApiInstanceName =
@@ -372,7 +395,8 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
372
395
  this.organization =
373
396
  fields?.configuration?.organization ??
374
397
  (0, env_1.getEnvironmentVariable)("OPENAI_ORGANIZATION");
375
- this.modelName = fields?.modelName ?? this.modelName;
398
+ this.modelName = fields?.model ?? fields?.modelName ?? this.model;
399
+ this.model = this.modelName;
376
400
  this.modelKwargs = fields?.modelKwargs ?? {};
377
401
  this.timeout = fields?.timeout;
378
402
  this.temperature = fields?.temperature ?? this.temperature;
@@ -384,7 +408,8 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
384
408
  this.topLogprobs = fields?.topLogprobs;
385
409
  this.n = fields?.n ?? this.n;
386
410
  this.logitBias = fields?.logitBias;
387
- this.stop = fields?.stop;
411
+ this.stop = fields?.stopSequences ?? fields?.stop;
412
+ this.stopSequences = this?.stop;
388
413
  this.user = fields?.user;
389
414
  this.streaming = fields?.streaming ?? false;
390
415
  if (this.azureOpenAIApiKey) {
@@ -397,10 +422,10 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
397
422
  if (!this.azureOpenAIApiVersion) {
398
423
  throw new Error("Azure OpenAI API version not found");
399
424
  }
400
- this.openAIApiKey = this.openAIApiKey ?? "";
425
+ this.apiKey = this.apiKey ?? "";
401
426
  }
402
427
  this.clientConfig = {
403
- apiKey: this.openAIApiKey,
428
+ apiKey: this.apiKey,
404
429
  organization: this.organization,
405
430
  baseURL: configuration?.basePath ?? fields?.configuration?.basePath,
406
431
  dangerouslyAllowBrowser: true,
@@ -421,7 +446,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
421
446
  tools.every((tool) => Array.isArray(tool.lc_namespace)));
422
447
  }
423
448
  const params = {
424
- model: this.modelName,
449
+ model: this.model,
425
450
  temperature: this.temperature,
426
451
  top_p: this.topP,
427
452
  frequency_penalty: this.frequencyPenalty,
@@ -431,7 +456,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
431
456
  top_logprobs: this.topLogprobs,
432
457
  n: this.n,
433
458
  logit_bias: this.logitBias,
434
- stop: options?.stop ?? this.stop,
459
+ stop: options?.stop ?? this.stopSequences,
435
460
  user: this.user,
436
461
  stream: this.streaming,
437
462
  functions: options?.functions,
@@ -449,7 +474,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
449
474
  /** @ignore */
450
475
  _identifyingParams() {
451
476
  return {
452
- model_name: this.modelName,
477
+ model_name: this.model,
453
478
  ...this.invocationParams(),
454
479
  ...this.clientConfig,
455
480
  };
@@ -634,7 +659,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
634
659
  let tokensPerMessage = 0;
635
660
  let tokensPerName = 0;
636
661
  // From: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb
637
- if (this.modelName === "gpt-3.5-turbo-0301") {
662
+ if (this.model === "gpt-3.5-turbo-0301") {
638
663
  tokensPerMessage = 4;
639
664
  tokensPerName = -1;
640
665
  }
@@ -51,7 +51,7 @@ export interface ChatOpenAICallOptions extends OpenAICallOptions, BaseFunctionCa
51
51
  * // Create a new instance of ChatOpenAI with specific temperature and model name settings
52
52
  * const model = new ChatOpenAI({
53
53
  * temperature: 0.9,
54
- * modelName: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
54
+ * model: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
55
55
  * });
56
56
  *
57
57
  * // Invoke the model with a message and await the response
@@ -77,8 +77,10 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
77
77
  n: number;
78
78
  logitBias?: Record<string, number>;
79
79
  modelName: string;
80
+ model: string;
80
81
  modelKwargs?: OpenAIChatInput["modelKwargs"];
81
82
  stop?: string[];
83
+ stopSequences?: string[];
82
84
  user?: string;
83
85
  timeout?: number;
84
86
  streaming: boolean;
@@ -86,6 +88,7 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
86
88
  logprobs?: boolean;
87
89
  topLogprobs?: number;
88
90
  openAIApiKey?: string;
91
+ apiKey?: string;
89
92
  azureOpenAIApiVersion?: string;
90
93
  azureOpenAIApiKey?: string;
91
94
  azureOpenAIApiInstanceName?: string;
@@ -146,7 +146,7 @@ function convertMessagesToOpenAIParams(messages) {
146
146
  * // Create a new instance of ChatOpenAI with specific temperature and model name settings
147
147
  * const model = new ChatOpenAI({
148
148
  * temperature: 0.9,
149
- * modelName: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
149
+ * model: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
150
150
  * });
151
151
  *
152
152
  * // Invoke the model with a message and await the response
@@ -177,6 +177,7 @@ export class ChatOpenAI extends BaseChatModel {
177
177
  get lc_secrets() {
178
178
  return {
179
179
  openAIApiKey: "OPENAI_API_KEY",
180
+ apiKey: "OPENAI_API_KEY",
180
181
  azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
181
182
  organization: "OPENAI_ORGANIZATION",
182
183
  };
@@ -185,6 +186,7 @@ export class ChatOpenAI extends BaseChatModel {
185
186
  return {
186
187
  modelName: "model",
187
188
  openAIApiKey: "openai_api_key",
189
+ apiKey: "openai_api_key",
188
190
  azureOpenAIApiVersion: "azure_openai_api_version",
189
191
  azureOpenAIApiKey: "azure_openai_api_key",
190
192
  azureOpenAIApiInstanceName: "azure_openai_api_instance_name",
@@ -243,6 +245,12 @@ export class ChatOpenAI extends BaseChatModel {
243
245
  writable: true,
244
246
  value: "gpt-3.5-turbo"
245
247
  });
248
+ Object.defineProperty(this, "model", {
249
+ enumerable: true,
250
+ configurable: true,
251
+ writable: true,
252
+ value: "gpt-3.5-turbo"
253
+ });
246
254
  Object.defineProperty(this, "modelKwargs", {
247
255
  enumerable: true,
248
256
  configurable: true,
@@ -255,6 +263,12 @@ export class ChatOpenAI extends BaseChatModel {
255
263
  writable: true,
256
264
  value: void 0
257
265
  });
266
+ Object.defineProperty(this, "stopSequences", {
267
+ enumerable: true,
268
+ configurable: true,
269
+ writable: true,
270
+ value: void 0
271
+ });
258
272
  Object.defineProperty(this, "user", {
259
273
  enumerable: true,
260
274
  configurable: true,
@@ -297,6 +311,12 @@ export class ChatOpenAI extends BaseChatModel {
297
311
  writable: true,
298
312
  value: void 0
299
313
  });
314
+ Object.defineProperty(this, "apiKey", {
315
+ enumerable: true,
316
+ configurable: true,
317
+ writable: true,
318
+ value: void 0
319
+ });
300
320
  Object.defineProperty(this, "azureOpenAIApiVersion", {
301
321
  enumerable: true,
302
322
  configurable: true,
@@ -346,11 +366,14 @@ export class ChatOpenAI extends BaseChatModel {
346
366
  value: void 0
347
367
  });
348
368
  this.openAIApiKey =
349
- fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
369
+ fields?.apiKey ??
370
+ fields?.openAIApiKey ??
371
+ getEnvironmentVariable("OPENAI_API_KEY");
372
+ this.apiKey = this.openAIApiKey;
350
373
  this.azureOpenAIApiKey =
351
374
  fields?.azureOpenAIApiKey ??
352
375
  getEnvironmentVariable("AZURE_OPENAI_API_KEY");
353
- if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
376
+ if (!this.azureOpenAIApiKey && !this.apiKey) {
354
377
  throw new Error("OpenAI or Azure OpenAI API key not found");
355
378
  }
356
379
  this.azureOpenAIApiInstanceName =
@@ -368,7 +391,8 @@ export class ChatOpenAI extends BaseChatModel {
368
391
  this.organization =
369
392
  fields?.configuration?.organization ??
370
393
  getEnvironmentVariable("OPENAI_ORGANIZATION");
371
- this.modelName = fields?.modelName ?? this.modelName;
394
+ this.modelName = fields?.model ?? fields?.modelName ?? this.model;
395
+ this.model = this.modelName;
372
396
  this.modelKwargs = fields?.modelKwargs ?? {};
373
397
  this.timeout = fields?.timeout;
374
398
  this.temperature = fields?.temperature ?? this.temperature;
@@ -380,7 +404,8 @@ export class ChatOpenAI extends BaseChatModel {
380
404
  this.topLogprobs = fields?.topLogprobs;
381
405
  this.n = fields?.n ?? this.n;
382
406
  this.logitBias = fields?.logitBias;
383
- this.stop = fields?.stop;
407
+ this.stop = fields?.stopSequences ?? fields?.stop;
408
+ this.stopSequences = this?.stop;
384
409
  this.user = fields?.user;
385
410
  this.streaming = fields?.streaming ?? false;
386
411
  if (this.azureOpenAIApiKey) {
@@ -393,10 +418,10 @@ export class ChatOpenAI extends BaseChatModel {
393
418
  if (!this.azureOpenAIApiVersion) {
394
419
  throw new Error("Azure OpenAI API version not found");
395
420
  }
396
- this.openAIApiKey = this.openAIApiKey ?? "";
421
+ this.apiKey = this.apiKey ?? "";
397
422
  }
398
423
  this.clientConfig = {
399
- apiKey: this.openAIApiKey,
424
+ apiKey: this.apiKey,
400
425
  organization: this.organization,
401
426
  baseURL: configuration?.basePath ?? fields?.configuration?.basePath,
402
427
  dangerouslyAllowBrowser: true,
@@ -417,7 +442,7 @@ export class ChatOpenAI extends BaseChatModel {
417
442
  tools.every((tool) => Array.isArray(tool.lc_namespace)));
418
443
  }
419
444
  const params = {
420
- model: this.modelName,
445
+ model: this.model,
421
446
  temperature: this.temperature,
422
447
  top_p: this.topP,
423
448
  frequency_penalty: this.frequencyPenalty,
@@ -427,7 +452,7 @@ export class ChatOpenAI extends BaseChatModel {
427
452
  top_logprobs: this.topLogprobs,
428
453
  n: this.n,
429
454
  logit_bias: this.logitBias,
430
- stop: options?.stop ?? this.stop,
455
+ stop: options?.stop ?? this.stopSequences,
431
456
  user: this.user,
432
457
  stream: this.streaming,
433
458
  functions: options?.functions,
@@ -445,7 +470,7 @@ export class ChatOpenAI extends BaseChatModel {
445
470
  /** @ignore */
446
471
  _identifyingParams() {
447
472
  return {
448
- model_name: this.modelName,
473
+ model_name: this.model,
449
474
  ...this.invocationParams(),
450
475
  ...this.clientConfig,
451
476
  };
@@ -630,7 +655,7 @@ export class ChatOpenAI extends BaseChatModel {
630
655
  let tokensPerMessage = 0;
631
656
  let tokensPerName = 0;
632
657
  // From: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb
633
- if (this.modelName === "gpt-3.5-turbo-0301") {
658
+ if (this.model === "gpt-3.5-turbo-0301") {
634
659
  tokensPerMessage = 4;
635
660
  tokensPerName = -1;
636
661
  }
@@ -32,6 +32,12 @@ class OpenAIEmbeddings extends embeddings_1.Embeddings {
32
32
  writable: true,
33
33
  value: "text-embedding-ada-002"
34
34
  });
35
+ Object.defineProperty(this, "model", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: "text-embedding-ada-002"
40
+ });
35
41
  Object.defineProperty(this, "batchSize", {
36
42
  enumerable: true,
37
43
  configurable: true,
@@ -109,7 +115,8 @@ class OpenAIEmbeddings extends embeddings_1.Embeddings {
109
115
  writable: true,
110
116
  value: void 0
111
117
  });
112
- let apiKey = fieldsWithDefaults?.openAIApiKey ??
118
+ let apiKey = fieldsWithDefaults?.apiKey ??
119
+ fieldsWithDefaults?.openAIApiKey ??
113
120
  (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
114
121
  const azureApiKey = fieldsWithDefaults?.azureOpenAIApiKey ??
115
122
  (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
@@ -130,7 +137,9 @@ class OpenAIEmbeddings extends embeddings_1.Embeddings {
130
137
  this.organization =
131
138
  fieldsWithDefaults?.configuration?.organization ??
132
139
  (0, env_1.getEnvironmentVariable)("OPENAI_ORGANIZATION");
133
- this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
140
+ this.modelName =
141
+ fieldsWithDefaults?.model ?? fieldsWithDefaults?.modelName ?? this.model;
142
+ this.model = this.modelName;
134
143
  this.batchSize =
135
144
  fieldsWithDefaults?.batchSize ?? (azureApiKey ? 1 : this.batchSize);
136
145
  this.stripNewLines =
@@ -175,7 +184,7 @@ class OpenAIEmbeddings extends embeddings_1.Embeddings {
175
184
  const batches = (0, chunk_array_1.chunkArray)(this.stripNewLines ? texts.map((t) => t.replace(/\n/g, " ")) : texts, this.batchSize);
176
185
  const batchRequests = batches.map((batch) => {
177
186
  const params = {
178
- model: this.modelName,
187
+ model: this.model,
179
188
  input: batch,
180
189
  };
181
190
  if (this.dimensions) {
@@ -202,7 +211,7 @@ class OpenAIEmbeddings extends embeddings_1.Embeddings {
202
211
  */
203
212
  async embedQuery(text) {
204
213
  const params = {
205
- model: this.modelName,
214
+ model: this.model,
206
215
  input: this.stripNewLines ? text.replace(/\n/g, " ") : text,
207
216
  };
208
217
  if (this.dimensions) {
@@ -6,8 +6,13 @@ import { AzureOpenAIInput, LegacyOpenAIInput } from "./types.js";
6
6
  * defines additional parameters specific to the OpenAIEmbeddings class.
7
7
  */
8
8
  export interface OpenAIEmbeddingsParams extends EmbeddingsParams {
9
- /** Model name to use */
9
+ /**
10
+ * Model name to use
11
+ * Alias for `model`
12
+ */
10
13
  modelName: string;
14
+ /** Model name to use */
15
+ model: string;
11
16
  /**
12
17
  * The number of dimensions the resulting output embeddings should have.
13
18
  * Only supported in `text-embedding-3` and later models.
@@ -46,6 +51,7 @@ export interface OpenAIEmbeddingsParams extends EmbeddingsParams {
46
51
  */
47
52
  export declare class OpenAIEmbeddings extends Embeddings implements OpenAIEmbeddingsParams, AzureOpenAIInput {
48
53
  modelName: string;
54
+ model: string;
49
55
  batchSize: number;
50
56
  stripNewLines: boolean;
51
57
  /**
@@ -64,7 +70,13 @@ export declare class OpenAIEmbeddings extends Embeddings implements OpenAIEmbedd
64
70
  private clientConfig;
65
71
  constructor(fields?: Partial<OpenAIEmbeddingsParams> & Partial<AzureOpenAIInput> & {
66
72
  verbose?: boolean;
73
+ /**
74
+ * The OpenAI API key to use.
75
+ * Alias for `apiKey`.
76
+ */
67
77
  openAIApiKey?: string;
78
+ /** The OpenAI API key to use. */
79
+ apiKey?: string;
68
80
  configuration?: ClientOptions;
69
81
  }, configuration?: ClientOptions & LegacyOpenAIInput);
70
82
  /**
@@ -29,6 +29,12 @@ export class OpenAIEmbeddings extends Embeddings {
29
29
  writable: true,
30
30
  value: "text-embedding-ada-002"
31
31
  });
32
+ Object.defineProperty(this, "model", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: "text-embedding-ada-002"
37
+ });
32
38
  Object.defineProperty(this, "batchSize", {
33
39
  enumerable: true,
34
40
  configurable: true,
@@ -106,7 +112,8 @@ export class OpenAIEmbeddings extends Embeddings {
106
112
  writable: true,
107
113
  value: void 0
108
114
  });
109
- let apiKey = fieldsWithDefaults?.openAIApiKey ??
115
+ let apiKey = fieldsWithDefaults?.apiKey ??
116
+ fieldsWithDefaults?.openAIApiKey ??
110
117
  getEnvironmentVariable("OPENAI_API_KEY");
111
118
  const azureApiKey = fieldsWithDefaults?.azureOpenAIApiKey ??
112
119
  getEnvironmentVariable("AZURE_OPENAI_API_KEY");
@@ -127,7 +134,9 @@ export class OpenAIEmbeddings extends Embeddings {
127
134
  this.organization =
128
135
  fieldsWithDefaults?.configuration?.organization ??
129
136
  getEnvironmentVariable("OPENAI_ORGANIZATION");
130
- this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
137
+ this.modelName =
138
+ fieldsWithDefaults?.model ?? fieldsWithDefaults?.modelName ?? this.model;
139
+ this.model = this.modelName;
131
140
  this.batchSize =
132
141
  fieldsWithDefaults?.batchSize ?? (azureApiKey ? 1 : this.batchSize);
133
142
  this.stripNewLines =
@@ -172,7 +181,7 @@ export class OpenAIEmbeddings extends Embeddings {
172
181
  const batches = chunkArray(this.stripNewLines ? texts.map((t) => t.replace(/\n/g, " ")) : texts, this.batchSize);
173
182
  const batchRequests = batches.map((batch) => {
174
183
  const params = {
175
- model: this.modelName,
184
+ model: this.model,
176
185
  input: batch,
177
186
  };
178
187
  if (this.dimensions) {
@@ -199,7 +208,7 @@ export class OpenAIEmbeddings extends Embeddings {
199
208
  */
200
209
  async embedQuery(text) {
201
210
  const params = {
202
- model: this.modelName,
211
+ model: this.model,
203
212
  input: this.stripNewLines ? text.replace(/\n/g, " ") : text,
204
213
  };
205
214
  if (this.dimensions) {
package/dist/legacy.cjs CHANGED
@@ -130,6 +130,12 @@ class OpenAIChat extends llms_1.LLM {
130
130
  writable: true,
131
131
  value: "gpt-3.5-turbo"
132
132
  });
133
+ Object.defineProperty(this, "model", {
134
+ enumerable: true,
135
+ configurable: true,
136
+ writable: true,
137
+ value: "gpt-3.5-turbo"
138
+ });
133
139
  Object.defineProperty(this, "prefixMessages", {
134
140
  enumerable: true,
135
141
  configurable: true,
package/dist/legacy.d.ts CHANGED
@@ -69,6 +69,7 @@ export declare class OpenAIChat extends LLM<OpenAIChatCallOptions> implements Op
69
69
  logitBias?: Record<string, number>;
70
70
  maxTokens?: number;
71
71
  modelName: string;
72
+ model: string;
72
73
  prefixMessages?: OpenAIClient.Chat.ChatCompletionMessageParam[];
73
74
  modelKwargs?: OpenAIChatInput["modelKwargs"];
74
75
  timeout?: number;
package/dist/legacy.js CHANGED
@@ -127,6 +127,12 @@ export class OpenAIChat extends LLM {
127
127
  writable: true,
128
128
  value: "gpt-3.5-turbo"
129
129
  });
130
+ Object.defineProperty(this, "model", {
131
+ enumerable: true,
132
+ configurable: true,
133
+ writable: true,
134
+ value: "gpt-3.5-turbo"
135
+ });
130
136
  Object.defineProperty(this, "prefixMessages", {
131
137
  enumerable: true,
132
138
  configurable: true,
package/dist/llms.cjs CHANGED
@@ -53,6 +53,7 @@ class OpenAI extends llms_1.BaseLLM {
53
53
  get lc_secrets() {
54
54
  return {
55
55
  openAIApiKey: "OPENAI_API_KEY",
56
+ apiKey: "OPENAI_API_KEY",
56
57
  azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
57
58
  organization: "OPENAI_ORGANIZATION",
58
59
  };
@@ -61,6 +62,7 @@ class OpenAI extends llms_1.BaseLLM {
61
62
  return {
62
63
  modelName: "model",
63
64
  openAIApiKey: "openai_api_key",
65
+ apiKey: "openai_api_key",
64
66
  azureOpenAIApiVersion: "azure_openai_api_version",
65
67
  azureOpenAIApiKey: "azure_openai_api_key",
66
68
  azureOpenAIApiInstanceName: "azure_openai_api_instance_name",
@@ -70,9 +72,9 @@ class OpenAI extends llms_1.BaseLLM {
70
72
  constructor(fields,
71
73
  /** @deprecated */
72
74
  configuration) {
73
- if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
74
- fields?.modelName?.startsWith("gpt-4")) &&
75
- !fields?.modelName?.includes("-instruct")) {
75
+ let model = fields?.model ?? fields?.modelName;
76
+ if ((model?.startsWith("gpt-3.5-turbo") || model?.startsWith("gpt-4")) &&
77
+ !model?.includes("-instruct")) {
76
78
  // eslint-disable-next-line no-constructor-return
77
79
  return new legacy_js_1.OpenAIChat(fields, configuration);
78
80
  }
@@ -137,6 +139,12 @@ class OpenAI extends llms_1.BaseLLM {
137
139
  writable: true,
138
140
  value: "gpt-3.5-turbo-instruct"
139
141
  });
142
+ Object.defineProperty(this, "model", {
143
+ enumerable: true,
144
+ configurable: true,
145
+ writable: true,
146
+ value: "gpt-3.5-turbo-instruct"
147
+ });
140
148
  Object.defineProperty(this, "modelKwargs", {
141
149
  enumerable: true,
142
150
  configurable: true,
@@ -161,6 +169,12 @@ class OpenAI extends llms_1.BaseLLM {
161
169
  writable: true,
162
170
  value: void 0
163
171
  });
172
+ Object.defineProperty(this, "stopSequences", {
173
+ enumerable: true,
174
+ configurable: true,
175
+ writable: true,
176
+ value: void 0
177
+ });
164
178
  Object.defineProperty(this, "user", {
165
179
  enumerable: true,
166
180
  configurable: true,
@@ -179,6 +193,12 @@ class OpenAI extends llms_1.BaseLLM {
179
193
  writable: true,
180
194
  value: void 0
181
195
  });
196
+ Object.defineProperty(this, "apiKey", {
197
+ enumerable: true,
198
+ configurable: true,
199
+ writable: true,
200
+ value: void 0
201
+ });
182
202
  Object.defineProperty(this, "azureOpenAIApiVersion", {
183
203
  enumerable: true,
184
204
  configurable: true,
@@ -227,12 +247,16 @@ class OpenAI extends llms_1.BaseLLM {
227
247
  writable: true,
228
248
  value: void 0
229
249
  });
250
+ model = model ?? this.model;
230
251
  this.openAIApiKey =
231
- fields?.openAIApiKey ?? (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
252
+ fields?.apiKey ??
253
+ fields?.openAIApiKey ??
254
+ (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
255
+ this.apiKey = this.openAIApiKey;
232
256
  this.azureOpenAIApiKey =
233
257
  fields?.azureOpenAIApiKey ??
234
258
  (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
235
- if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
259
+ if (!this.azureOpenAIApiKey && !this.apiKey) {
236
260
  throw new Error("OpenAI or Azure OpenAI API key not found");
237
261
  }
238
262
  this.azureOpenAIApiInstanceName =
@@ -252,7 +276,8 @@ class OpenAI extends llms_1.BaseLLM {
252
276
  this.organization =
253
277
  fields?.configuration?.organization ??
254
278
  (0, env_1.getEnvironmentVariable)("OPENAI_ORGANIZATION");
255
- this.modelName = fields?.modelName ?? this.modelName;
279
+ this.modelName = model;
280
+ this.model = model;
256
281
  this.modelKwargs = fields?.modelKwargs ?? {};
257
282
  this.batchSize = fields?.batchSize ?? this.batchSize;
258
283
  this.timeout = fields?.timeout;
@@ -264,7 +289,8 @@ class OpenAI extends llms_1.BaseLLM {
264
289
  this.n = fields?.n ?? this.n;
265
290
  this.bestOf = fields?.bestOf ?? this.bestOf;
266
291
  this.logitBias = fields?.logitBias;
267
- this.stop = fields?.stop;
292
+ this.stop = fields?.stopSequences ?? fields?.stop;
293
+ this.stopSequences = fields?.stopSequences;
268
294
  this.user = fields?.user;
269
295
  this.streaming = fields?.streaming ?? false;
270
296
  if (this.streaming && this.bestOf && this.bestOf > 1) {
@@ -280,10 +306,10 @@ class OpenAI extends llms_1.BaseLLM {
280
306
  if (!this.azureOpenAIApiVersion) {
281
307
  throw new Error("Azure OpenAI API version not found");
282
308
  }
283
- this.openAIApiKey = this.openAIApiKey ?? "";
309
+ this.apiKey = this.apiKey ?? "";
284
310
  }
285
311
  this.clientConfig = {
286
- apiKey: this.openAIApiKey,
312
+ apiKey: this.apiKey,
287
313
  organization: this.organization,
288
314
  baseURL: configuration?.basePath ?? fields?.configuration?.basePath,
289
315
  dangerouslyAllowBrowser: true,
@@ -300,7 +326,7 @@ class OpenAI extends llms_1.BaseLLM {
300
326
  */
301
327
  invocationParams(options) {
302
328
  return {
303
- model: this.modelName,
329
+ model: this.model,
304
330
  temperature: this.temperature,
305
331
  max_tokens: this.maxTokens,
306
332
  top_p: this.topP,
@@ -309,7 +335,7 @@ class OpenAI extends llms_1.BaseLLM {
309
335
  n: this.n,
310
336
  best_of: this.bestOf,
311
337
  logit_bias: this.logitBias,
312
- stop: options?.stop ?? this.stop,
338
+ stop: options?.stop ?? this.stopSequences,
313
339
  user: this.user,
314
340
  stream: this.streaming,
315
341
  ...this.modelKwargs,
@@ -318,7 +344,7 @@ class OpenAI extends llms_1.BaseLLM {
318
344
  /** @ignore */
319
345
  _identifyingParams() {
320
346
  return {
321
- model_name: this.modelName,
347
+ model_name: this.model,
322
348
  ...this.invocationParams(),
323
349
  ...this.clientConfig,
324
350
  };
@@ -357,7 +383,7 @@ class OpenAI extends llms_1.BaseLLM {
357
383
  params.max_tokens = await (0, base_1.calculateMaxTokens)({
358
384
  prompt: prompts[0],
359
385
  // Cast here to allow for other models that may not fit the union
360
- modelName: this.modelName,
386
+ modelName: this.model,
361
387
  });
362
388
  }
363
389
  for (let i = 0; i < subPrompts.length; i += 1) {
package/dist/llms.d.ts CHANGED
@@ -55,13 +55,16 @@ export declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOp
55
55
  bestOf?: number;
56
56
  logitBias?: Record<string, number>;
57
57
  modelName: string;
58
+ model: string;
58
59
  modelKwargs?: OpenAIInput["modelKwargs"];
59
60
  batchSize: number;
60
61
  timeout?: number;
61
62
  stop?: string[];
63
+ stopSequences?: string[];
62
64
  user?: string;
63
65
  streaming: boolean;
64
66
  openAIApiKey?: string;
67
+ apiKey?: string;
65
68
  azureOpenAIApiVersion?: string;
66
69
  azureOpenAIApiKey?: string;
67
70
  azureOpenAIApiInstanceName?: string;
package/dist/llms.js CHANGED
@@ -50,6 +50,7 @@ export class OpenAI extends BaseLLM {
50
50
  get lc_secrets() {
51
51
  return {
52
52
  openAIApiKey: "OPENAI_API_KEY",
53
+ apiKey: "OPENAI_API_KEY",
53
54
  azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
54
55
  organization: "OPENAI_ORGANIZATION",
55
56
  };
@@ -58,6 +59,7 @@ export class OpenAI extends BaseLLM {
58
59
  return {
59
60
  modelName: "model",
60
61
  openAIApiKey: "openai_api_key",
62
+ apiKey: "openai_api_key",
61
63
  azureOpenAIApiVersion: "azure_openai_api_version",
62
64
  azureOpenAIApiKey: "azure_openai_api_key",
63
65
  azureOpenAIApiInstanceName: "azure_openai_api_instance_name",
@@ -67,9 +69,9 @@ export class OpenAI extends BaseLLM {
67
69
  constructor(fields,
68
70
  /** @deprecated */
69
71
  configuration) {
70
- if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
71
- fields?.modelName?.startsWith("gpt-4")) &&
72
- !fields?.modelName?.includes("-instruct")) {
72
+ let model = fields?.model ?? fields?.modelName;
73
+ if ((model?.startsWith("gpt-3.5-turbo") || model?.startsWith("gpt-4")) &&
74
+ !model?.includes("-instruct")) {
73
75
  // eslint-disable-next-line no-constructor-return
74
76
  return new OpenAIChat(fields, configuration);
75
77
  }
@@ -134,6 +136,12 @@ export class OpenAI extends BaseLLM {
134
136
  writable: true,
135
137
  value: "gpt-3.5-turbo-instruct"
136
138
  });
139
+ Object.defineProperty(this, "model", {
140
+ enumerable: true,
141
+ configurable: true,
142
+ writable: true,
143
+ value: "gpt-3.5-turbo-instruct"
144
+ });
137
145
  Object.defineProperty(this, "modelKwargs", {
138
146
  enumerable: true,
139
147
  configurable: true,
@@ -158,6 +166,12 @@ export class OpenAI extends BaseLLM {
158
166
  writable: true,
159
167
  value: void 0
160
168
  });
169
+ Object.defineProperty(this, "stopSequences", {
170
+ enumerable: true,
171
+ configurable: true,
172
+ writable: true,
173
+ value: void 0
174
+ });
161
175
  Object.defineProperty(this, "user", {
162
176
  enumerable: true,
163
177
  configurable: true,
@@ -176,6 +190,12 @@ export class OpenAI extends BaseLLM {
176
190
  writable: true,
177
191
  value: void 0
178
192
  });
193
+ Object.defineProperty(this, "apiKey", {
194
+ enumerable: true,
195
+ configurable: true,
196
+ writable: true,
197
+ value: void 0
198
+ });
179
199
  Object.defineProperty(this, "azureOpenAIApiVersion", {
180
200
  enumerable: true,
181
201
  configurable: true,
@@ -224,12 +244,16 @@ export class OpenAI extends BaseLLM {
224
244
  writable: true,
225
245
  value: void 0
226
246
  });
247
+ model = model ?? this.model;
227
248
  this.openAIApiKey =
228
- fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
249
+ fields?.apiKey ??
250
+ fields?.openAIApiKey ??
251
+ getEnvironmentVariable("OPENAI_API_KEY");
252
+ this.apiKey = this.openAIApiKey;
229
253
  this.azureOpenAIApiKey =
230
254
  fields?.azureOpenAIApiKey ??
231
255
  getEnvironmentVariable("AZURE_OPENAI_API_KEY");
232
- if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
256
+ if (!this.azureOpenAIApiKey && !this.apiKey) {
233
257
  throw new Error("OpenAI or Azure OpenAI API key not found");
234
258
  }
235
259
  this.azureOpenAIApiInstanceName =
@@ -249,7 +273,8 @@ export class OpenAI extends BaseLLM {
249
273
  this.organization =
250
274
  fields?.configuration?.organization ??
251
275
  getEnvironmentVariable("OPENAI_ORGANIZATION");
252
- this.modelName = fields?.modelName ?? this.modelName;
276
+ this.modelName = model;
277
+ this.model = model;
253
278
  this.modelKwargs = fields?.modelKwargs ?? {};
254
279
  this.batchSize = fields?.batchSize ?? this.batchSize;
255
280
  this.timeout = fields?.timeout;
@@ -261,7 +286,8 @@ export class OpenAI extends BaseLLM {
261
286
  this.n = fields?.n ?? this.n;
262
287
  this.bestOf = fields?.bestOf ?? this.bestOf;
263
288
  this.logitBias = fields?.logitBias;
264
- this.stop = fields?.stop;
289
+ this.stop = fields?.stopSequences ?? fields?.stop;
290
+ this.stopSequences = fields?.stopSequences;
265
291
  this.user = fields?.user;
266
292
  this.streaming = fields?.streaming ?? false;
267
293
  if (this.streaming && this.bestOf && this.bestOf > 1) {
@@ -277,10 +303,10 @@ export class OpenAI extends BaseLLM {
277
303
  if (!this.azureOpenAIApiVersion) {
278
304
  throw new Error("Azure OpenAI API version not found");
279
305
  }
280
- this.openAIApiKey = this.openAIApiKey ?? "";
306
+ this.apiKey = this.apiKey ?? "";
281
307
  }
282
308
  this.clientConfig = {
283
- apiKey: this.openAIApiKey,
309
+ apiKey: this.apiKey,
284
310
  organization: this.organization,
285
311
  baseURL: configuration?.basePath ?? fields?.configuration?.basePath,
286
312
  dangerouslyAllowBrowser: true,
@@ -297,7 +323,7 @@ export class OpenAI extends BaseLLM {
297
323
  */
298
324
  invocationParams(options) {
299
325
  return {
300
- model: this.modelName,
326
+ model: this.model,
301
327
  temperature: this.temperature,
302
328
  max_tokens: this.maxTokens,
303
329
  top_p: this.topP,
@@ -306,7 +332,7 @@ export class OpenAI extends BaseLLM {
306
332
  n: this.n,
307
333
  best_of: this.bestOf,
308
334
  logit_bias: this.logitBias,
309
- stop: options?.stop ?? this.stop,
335
+ stop: options?.stop ?? this.stopSequences,
310
336
  user: this.user,
311
337
  stream: this.streaming,
312
338
  ...this.modelKwargs,
@@ -315,7 +341,7 @@ export class OpenAI extends BaseLLM {
315
341
  /** @ignore */
316
342
  _identifyingParams() {
317
343
  return {
318
- model_name: this.modelName,
344
+ model_name: this.model,
319
345
  ...this.invocationParams(),
320
346
  ...this.clientConfig,
321
347
  };
@@ -354,7 +380,7 @@ export class OpenAI extends BaseLLM {
354
380
  params.max_tokens = await calculateMaxTokens({
355
381
  prompt: prompts[0],
356
382
  // Cast here to allow for other models that may not fit the union
357
- modelName: this.modelName,
383
+ modelName: this.model,
358
384
  });
359
385
  }
360
386
  for (let i = 0; i < subPrompts.length; i += 1) {
@@ -31,7 +31,7 @@ class DallEAPIWrapper extends tools_1.Tool {
31
31
  writable: true,
32
32
  value: void 0
33
33
  });
34
- Object.defineProperty(this, "modelName", {
34
+ Object.defineProperty(this, "model", {
35
35
  enumerable: true,
36
36
  configurable: true,
37
37
  writable: true,
@@ -73,7 +73,9 @@ class DallEAPIWrapper extends tools_1.Tool {
73
73
  writable: true,
74
74
  value: void 0
75
75
  });
76
- const openAIApiKey = fields?.openAIApiKey ?? (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
76
+ const openAIApiKey = fields?.apiKey ??
77
+ fields?.openAIApiKey ??
78
+ (0, env_1.getEnvironmentVariable)("OPENAI_API_KEY");
77
79
  const organization = fields?.organization ?? (0, env_1.getEnvironmentVariable)("OPENAI_ORGANIZATION");
78
80
  const clientConfig = {
79
81
  apiKey: openAIApiKey,
@@ -81,7 +83,7 @@ class DallEAPIWrapper extends tools_1.Tool {
81
83
  dangerouslyAllowBrowser: true,
82
84
  };
83
85
  this.client = new openai_1.OpenAI(clientConfig);
84
- this.modelName = fields?.modelName ?? this.modelName;
86
+ this.model = fields?.model ?? fields?.modelName ?? this.model;
85
87
  this.style = fields?.style ?? this.style;
86
88
  this.quality = fields?.quality ?? this.quality;
87
89
  this.n = fields?.n ?? this.n;
@@ -92,7 +94,7 @@ class DallEAPIWrapper extends tools_1.Tool {
92
94
  /** @ignore */
93
95
  async _call(input) {
94
96
  const response = await this.client.images.generate({
95
- model: this.modelName,
97
+ model: this.model,
96
98
  prompt: input,
97
99
  n: this.n,
98
100
  size: this.size,
@@ -6,14 +6,26 @@ import { Tool, ToolParams } from "@langchain/core/tools";
6
6
  export interface DallEAPIWrapperParams extends ToolParams {
7
7
  /**
8
8
  * The OpenAI API key
9
+ * Alias for `apiKey`
9
10
  */
10
11
  openAIApiKey?: string;
12
+ /**
13
+ * The OpenAI API key
14
+ */
15
+ apiKey?: string;
11
16
  /**
12
17
  * The model to use.
18
+ * Alias for `model`
13
19
  * @params "dall-e-2" | "dall-e-3"
14
20
  * @default "dall-e-3"
15
21
  */
16
22
  modelName?: string;
23
+ /**
24
+ * The model to use.
25
+ * @params "dall-e-2" | "dall-e-3"
26
+ * @default "dall-e-3"
27
+ */
28
+ model?: string;
17
29
  /**
18
30
  * The style of the generated images. Must be one of vivid or natural.
19
31
  * Vivid causes the model to lean towards generating hyper-real and dramatic images.
@@ -66,7 +78,7 @@ export declare class DallEAPIWrapper extends Tool {
66
78
  description: string;
67
79
  protected client: OpenAIClient;
68
80
  static readonly toolName = "dalle_api_wrapper";
69
- private modelName;
81
+ private model;
70
82
  private style;
71
83
  private quality;
72
84
  private n;
@@ -28,7 +28,7 @@ export class DallEAPIWrapper extends Tool {
28
28
  writable: true,
29
29
  value: void 0
30
30
  });
31
- Object.defineProperty(this, "modelName", {
31
+ Object.defineProperty(this, "model", {
32
32
  enumerable: true,
33
33
  configurable: true,
34
34
  writable: true,
@@ -70,7 +70,9 @@ export class DallEAPIWrapper extends Tool {
70
70
  writable: true,
71
71
  value: void 0
72
72
  });
73
- const openAIApiKey = fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
73
+ const openAIApiKey = fields?.apiKey ??
74
+ fields?.openAIApiKey ??
75
+ getEnvironmentVariable("OPENAI_API_KEY");
74
76
  const organization = fields?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION");
75
77
  const clientConfig = {
76
78
  apiKey: openAIApiKey,
@@ -78,7 +80,7 @@ export class DallEAPIWrapper extends Tool {
78
80
  dangerouslyAllowBrowser: true,
79
81
  };
80
82
  this.client = new OpenAIClient(clientConfig);
81
- this.modelName = fields?.modelName ?? this.modelName;
83
+ this.model = fields?.model ?? fields?.modelName ?? this.model;
82
84
  this.style = fields?.style ?? this.style;
83
85
  this.quality = fields?.quality ?? this.quality;
84
86
  this.n = fields?.n ?? this.n;
@@ -89,7 +91,7 @@ export class DallEAPIWrapper extends Tool {
89
91
  /** @ignore */
90
92
  async _call(input) {
91
93
  const response = await this.client.images.generate({
92
- model: this.modelName,
94
+ model: this.model,
93
95
  prompt: input,
94
96
  n: this.n,
95
97
  size: this.size,
package/dist/types.d.ts CHANGED
@@ -24,15 +24,25 @@ export declare interface OpenAIBaseInput {
24
24
  user?: string;
25
25
  /** Whether to stream the results or not. Enabling disables tokenUsage reporting */
26
26
  streaming: boolean;
27
- /** Model name to use */
27
+ /**
28
+ * Model name to use
29
+ * Alias for `model`
30
+ */
28
31
  modelName: string;
32
+ /** Model name to use */
33
+ model: string;
29
34
  /** Holds any additional parameters that are valid to pass to {@link
30
35
  * https://platform.openai.com/docs/api-reference/completions/create |
31
36
  * `openai.createCompletion`} that are not explicitly specified on this class.
32
37
  */
33
38
  modelKwargs?: Record<string, any>;
34
- /** List of stop words to use when generating */
39
+ /**
40
+ * List of stop words to use when generating
41
+ * Alias for `stopSequences`
42
+ */
35
43
  stop?: string[];
44
+ /** List of stop words to use when generating */
45
+ stopSequences?: string[];
36
46
  /**
37
47
  * Timeout to use when making requests to OpenAI.
38
48
  */
@@ -40,8 +50,14 @@ export declare interface OpenAIBaseInput {
40
50
  /**
41
51
  * API key to use when making requests to OpenAI. Defaults to the value of
42
52
  * `OPENAI_API_KEY` environment variable.
53
+ * Alias for `apiKey`
43
54
  */
44
55
  openAIApiKey?: string;
56
+ /**
57
+ * API key to use when making requests to OpenAI. Defaults to the value of
58
+ * `OPENAI_API_KEY` environment variable.
59
+ */
60
+ apiKey?: string;
45
61
  }
46
62
  export type OpenAICoreRequestOptions<Req extends object = Record<string, unknown>> = {
47
63
  path?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {