@langchain/openai 0.3.17 → 0.4.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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AzureChatOpenAI = void 0;
4
4
  const openai_1 = require("openai");
5
+ const env_1 = require("@langchain/core/utils/env");
5
6
  const chat_models_js_1 = require("../chat_models.cjs");
6
7
  const azure_js_1 = require("../utils/azure.cjs");
7
8
  /**
@@ -256,7 +257,7 @@ const azure_js_1 = require("../utils/azure.cjs");
256
257
  * const Joke = z.object({
257
258
  * setup: z.string().describe("The setup of the joke"),
258
259
  * punchline: z.string().describe("The punchline to the joke"),
259
- * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
260
+ * rating: z.number().nullable().describe("How funny the joke is, from 1 to 10")
260
261
  * }).describe('Joke to tell user.');
261
262
  *
262
263
  * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
@@ -422,6 +423,7 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
422
423
  }
423
424
  get lc_aliases() {
424
425
  return {
426
+ ...super.lc_aliases,
425
427
  openAIApiKey: "openai_api_key",
426
428
  openAIApiVersion: "openai_api_version",
427
429
  openAIBasePath: "openai_api_base",
@@ -432,18 +434,82 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
432
434
  azureOpenAIApiDeploymentName: "deployment_name",
433
435
  };
434
436
  }
437
+ get lc_secrets() {
438
+ return {
439
+ ...super.lc_secrets,
440
+ azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
441
+ };
442
+ }
435
443
  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;
444
+ super(fields);
445
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
446
+ enumerable: true,
447
+ configurable: true,
448
+ writable: true,
449
+ value: void 0
450
+ });
451
+ Object.defineProperty(this, "azureOpenAIApiKey", {
452
+ enumerable: true,
453
+ configurable: true,
454
+ writable: true,
455
+ value: void 0
456
+ });
457
+ Object.defineProperty(this, "azureADTokenProvider", {
458
+ enumerable: true,
459
+ configurable: true,
460
+ writable: true,
461
+ value: void 0
462
+ });
463
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
464
+ enumerable: true,
465
+ configurable: true,
466
+ writable: true,
467
+ value: void 0
468
+ });
469
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
470
+ enumerable: true,
471
+ configurable: true,
472
+ writable: true,
473
+ value: void 0
474
+ });
475
+ Object.defineProperty(this, "azureOpenAIBasePath", {
476
+ enumerable: true,
477
+ configurable: true,
478
+ writable: true,
479
+ value: void 0
480
+ });
481
+ Object.defineProperty(this, "azureOpenAIEndpoint", {
482
+ enumerable: true,
483
+ configurable: true,
484
+ writable: true,
485
+ value: void 0
486
+ });
487
+ this.azureOpenAIApiKey =
488
+ fields?.azureOpenAIApiKey ??
489
+ fields?.openAIApiKey ??
490
+ fields?.apiKey ??
491
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
492
+ this.azureOpenAIApiInstanceName =
493
+ fields?.azureOpenAIApiInstanceName ??
494
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
495
+ this.azureOpenAIApiDeploymentName =
496
+ fields?.azureOpenAIApiDeploymentName ??
497
+ fields?.deploymentName ??
498
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME");
499
+ this.azureOpenAIApiVersion =
500
+ fields?.azureOpenAIApiVersion ??
501
+ fields?.openAIApiVersion ??
502
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
503
+ this.azureOpenAIBasePath =
504
+ fields?.azureOpenAIBasePath ??
505
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
506
+ this.azureOpenAIEndpoint =
507
+ fields?.azureOpenAIEndpoint ??
508
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_ENDPOINT");
509
+ this.azureADTokenProvider = fields?.azureADTokenProvider;
510
+ if (!this.azureOpenAIApiKey && !this.apiKey && !this.azureADTokenProvider) {
511
+ throw new Error("Azure OpenAI API key or Token Provider not found");
445
512
  }
446
- super(newFields);
447
513
  }
448
514
  getLsParams(options) {
449
515
  const params = super.getLsParams(options);
@@ -1,7 +1,8 @@
1
1
  import { type ClientOptions } from "openai";
2
2
  import { LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
3
3
  import { ChatOpenAI } from "../chat_models.js";
4
- import { AzureOpenAIInput, LegacyOpenAIInput, OpenAIChatInput, OpenAICoreRequestOptions } from "../types.js";
4
+ import { AzureOpenAIInput, OpenAIChatInput, OpenAICoreRequestOptions } from "../types.js";
5
+ export type { AzureOpenAIInput };
5
6
  /**
6
7
  * Azure OpenAI chat model integration.
7
8
  *
@@ -254,7 +255,7 @@ import { AzureOpenAIInput, LegacyOpenAIInput, OpenAIChatInput, OpenAICoreRequest
254
255
  * const Joke = z.object({
255
256
  * setup: z.string().describe("The setup of the joke"),
256
257
  * punchline: z.string().describe("The punchline to the joke"),
257
- * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
258
+ * rating: z.number().nullable().describe("How funny the joke is, from 1 to 10")
258
259
  * }).describe('Joke to tell user.');
259
260
  *
260
261
  * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
@@ -415,15 +416,25 @@ import { AzureOpenAIInput, LegacyOpenAIInput, OpenAIChatInput, OpenAICoreRequest
415
416
  * </details>
416
417
  */
417
418
  export declare class AzureChatOpenAI extends ChatOpenAI {
419
+ azureOpenAIApiVersion?: string;
420
+ azureOpenAIApiKey?: string;
421
+ azureADTokenProvider?: () => Promise<string>;
422
+ azureOpenAIApiInstanceName?: string;
423
+ azureOpenAIApiDeploymentName?: string;
424
+ azureOpenAIBasePath?: string;
425
+ azureOpenAIEndpoint?: string;
418
426
  _llmType(): string;
419
427
  get lc_aliases(): Record<string, string>;
428
+ get lc_secrets(): {
429
+ [key: string]: string;
430
+ } | undefined;
420
431
  constructor(fields?: Partial<OpenAIChatInput> & Partial<AzureOpenAIInput> & {
421
432
  openAIApiKey?: string;
422
433
  openAIApiVersion?: string;
423
434
  openAIBasePath?: string;
424
435
  deploymentName?: string;
425
436
  } & BaseChatModelParams & {
426
- configuration?: ClientOptions & LegacyOpenAIInput;
437
+ configuration?: ClientOptions;
427
438
  });
428
439
  getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
429
440
  protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
@@ -1,4 +1,5 @@
1
1
  import { AzureOpenAI as AzureOpenAIClient } from "openai";
2
+ import { getEnvironmentVariable } from "@langchain/core/utils/env";
2
3
  import { ChatOpenAI } from "../chat_models.js";
3
4
  import { getEndpoint } from "../utils/azure.js";
4
5
  /**
@@ -253,7 +254,7 @@ import { getEndpoint } from "../utils/azure.js";
253
254
  * const Joke = z.object({
254
255
  * setup: z.string().describe("The setup of the joke"),
255
256
  * punchline: z.string().describe("The punchline to the joke"),
256
- * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
257
+ * rating: z.number().nullable().describe("How funny the joke is, from 1 to 10")
257
258
  * }).describe('Joke to tell user.');
258
259
  *
259
260
  * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
@@ -419,6 +420,7 @@ export class AzureChatOpenAI extends ChatOpenAI {
419
420
  }
420
421
  get lc_aliases() {
421
422
  return {
423
+ ...super.lc_aliases,
422
424
  openAIApiKey: "openai_api_key",
423
425
  openAIApiVersion: "openai_api_version",
424
426
  openAIBasePath: "openai_api_base",
@@ -429,18 +431,82 @@ export class AzureChatOpenAI extends ChatOpenAI {
429
431
  azureOpenAIApiDeploymentName: "deployment_name",
430
432
  };
431
433
  }
434
+ get lc_secrets() {
435
+ return {
436
+ ...super.lc_secrets,
437
+ azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
438
+ };
439
+ }
432
440
  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;
441
+ super(fields);
442
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
443
+ enumerable: true,
444
+ configurable: true,
445
+ writable: true,
446
+ value: void 0
447
+ });
448
+ Object.defineProperty(this, "azureOpenAIApiKey", {
449
+ enumerable: true,
450
+ configurable: true,
451
+ writable: true,
452
+ value: void 0
453
+ });
454
+ Object.defineProperty(this, "azureADTokenProvider", {
455
+ enumerable: true,
456
+ configurable: true,
457
+ writable: true,
458
+ value: void 0
459
+ });
460
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
461
+ enumerable: true,
462
+ configurable: true,
463
+ writable: true,
464
+ value: void 0
465
+ });
466
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
467
+ enumerable: true,
468
+ configurable: true,
469
+ writable: true,
470
+ value: void 0
471
+ });
472
+ Object.defineProperty(this, "azureOpenAIBasePath", {
473
+ enumerable: true,
474
+ configurable: true,
475
+ writable: true,
476
+ value: void 0
477
+ });
478
+ Object.defineProperty(this, "azureOpenAIEndpoint", {
479
+ enumerable: true,
480
+ configurable: true,
481
+ writable: true,
482
+ value: void 0
483
+ });
484
+ this.azureOpenAIApiKey =
485
+ fields?.azureOpenAIApiKey ??
486
+ fields?.openAIApiKey ??
487
+ fields?.apiKey ??
488
+ getEnvironmentVariable("AZURE_OPENAI_API_KEY");
489
+ this.azureOpenAIApiInstanceName =
490
+ fields?.azureOpenAIApiInstanceName ??
491
+ getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
492
+ this.azureOpenAIApiDeploymentName =
493
+ fields?.azureOpenAIApiDeploymentName ??
494
+ fields?.deploymentName ??
495
+ getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME");
496
+ this.azureOpenAIApiVersion =
497
+ fields?.azureOpenAIApiVersion ??
498
+ fields?.openAIApiVersion ??
499
+ getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
500
+ this.azureOpenAIBasePath =
501
+ fields?.azureOpenAIBasePath ??
502
+ getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
503
+ this.azureOpenAIEndpoint =
504
+ fields?.azureOpenAIEndpoint ??
505
+ getEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
506
+ this.azureADTokenProvider = fields?.azureADTokenProvider;
507
+ if (!this.azureOpenAIApiKey && !this.apiKey && !this.azureADTokenProvider) {
508
+ throw new Error("Azure OpenAI API key or Token Provider not found");
442
509
  }
443
- super(newFields);
444
510
  }
445
511
  getLsParams(options) {
446
512
  const params = super.getLsParams(options);
@@ -2,22 +2,70 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AzureOpenAIEmbeddings = void 0;
4
4
  const openai_1 = require("openai");
5
+ const env_1 = require("@langchain/core/utils/env");
5
6
  const embeddings_js_1 = require("../embeddings.cjs");
6
7
  const azure_js_1 = require("../utils/azure.cjs");
7
8
  const openai_js_1 = require("../utils/openai.cjs");
8
9
  class AzureOpenAIEmbeddings extends embeddings_js_1.OpenAIEmbeddings {
9
- constructor(fields, configuration) {
10
- const newFields = { ...fields };
11
- if (Object.entries(newFields).length) {
12
- // don't rewrite the fields if they are already set
13
- newFields.azureOpenAIApiDeploymentName =
14
- newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
15
- newFields.azureOpenAIApiKey =
16
- newFields.azureOpenAIApiKey ?? newFields.apiKey;
17
- newFields.azureOpenAIApiVersion =
18
- newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
19
- }
20
- super(newFields, configuration);
10
+ constructor(fields) {
11
+ super(fields);
12
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "azureOpenAIApiKey", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "azureADTokenProvider", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "azureOpenAIBasePath", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ this.batchSize = fields?.batchSize ?? 1;
49
+ this.azureOpenAIApiKey =
50
+ fields?.azureOpenAIApiKey ??
51
+ fields?.apiKey ??
52
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
53
+ this.azureOpenAIApiVersion =
54
+ fields?.azureOpenAIApiVersion ??
55
+ fields?.openAIApiVersion ??
56
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
57
+ this.azureOpenAIBasePath =
58
+ fields?.azureOpenAIBasePath ??
59
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
60
+ this.azureOpenAIApiInstanceName =
61
+ fields?.azureOpenAIApiInstanceName ??
62
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
63
+ this.azureOpenAIApiDeploymentName =
64
+ (fields?.azureOpenAIApiEmbeddingsDeploymentName ||
65
+ fields?.azureOpenAIApiDeploymentName) ??
66
+ ((0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME") ||
67
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
68
+ this.azureADTokenProvider = fields?.azureADTokenProvider;
21
69
  }
22
70
  async embeddingWithRetry(request) {
23
71
  if (!this.client) {
@@ -1,7 +1,13 @@
1
1
  import { type ClientOptions, OpenAI as OpenAIClient } from "openai";
2
2
  import { OpenAIEmbeddings, OpenAIEmbeddingsParams } from "../embeddings.js";
3
- import { AzureOpenAIInput, LegacyOpenAIInput } from "../types.js";
3
+ import { AzureOpenAIInput } from "../types.js";
4
4
  export declare class AzureOpenAIEmbeddings extends OpenAIEmbeddings {
5
+ azureOpenAIApiVersion?: string;
6
+ azureOpenAIApiKey?: string;
7
+ azureADTokenProvider?: () => Promise<string>;
8
+ azureOpenAIApiInstanceName?: string;
9
+ azureOpenAIApiDeploymentName?: string;
10
+ azureOpenAIBasePath?: string;
5
11
  constructor(fields?: Partial<OpenAIEmbeddingsParams> & Partial<AzureOpenAIInput> & {
6
12
  verbose?: boolean;
7
13
  /** The OpenAI API key to use. */
@@ -9,7 +15,7 @@ export declare class AzureOpenAIEmbeddings extends OpenAIEmbeddings {
9
15
  configuration?: ClientOptions;
10
16
  deploymentName?: string;
11
17
  openAIApiVersion?: string;
12
- }, configuration?: ClientOptions & LegacyOpenAIInput);
18
+ });
13
19
  protected embeddingWithRetry(request: OpenAIClient.EmbeddingCreateParams): Promise<OpenAIClient.Embeddings.CreateEmbeddingResponse & {
14
20
  _request_id?: string | null | undefined;
15
21
  }>;
@@ -1,20 +1,68 @@
1
1
  import { AzureOpenAI as AzureOpenAIClient, } from "openai";
2
+ import { getEnvironmentVariable } from "@langchain/core/utils/env";
2
3
  import { OpenAIEmbeddings } from "../embeddings.js";
3
4
  import { getEndpoint } from "../utils/azure.js";
4
5
  import { wrapOpenAIClientError } from "../utils/openai.js";
5
6
  export class AzureOpenAIEmbeddings extends OpenAIEmbeddings {
6
- constructor(fields, configuration) {
7
- const newFields = { ...fields };
8
- if (Object.entries(newFields).length) {
9
- // don't rewrite the fields if they are already set
10
- newFields.azureOpenAIApiDeploymentName =
11
- newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
12
- newFields.azureOpenAIApiKey =
13
- newFields.azureOpenAIApiKey ?? newFields.apiKey;
14
- newFields.azureOpenAIApiVersion =
15
- newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
16
- }
17
- super(newFields, configuration);
7
+ constructor(fields) {
8
+ super(fields);
9
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "azureOpenAIApiKey", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "azureADTokenProvider", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "azureOpenAIBasePath", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ this.batchSize = fields?.batchSize ?? 1;
46
+ this.azureOpenAIApiKey =
47
+ fields?.azureOpenAIApiKey ??
48
+ fields?.apiKey ??
49
+ getEnvironmentVariable("AZURE_OPENAI_API_KEY");
50
+ this.azureOpenAIApiVersion =
51
+ fields?.azureOpenAIApiVersion ??
52
+ fields?.openAIApiVersion ??
53
+ getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
54
+ this.azureOpenAIBasePath =
55
+ fields?.azureOpenAIBasePath ??
56
+ getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
57
+ this.azureOpenAIApiInstanceName =
58
+ fields?.azureOpenAIApiInstanceName ??
59
+ getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
60
+ this.azureOpenAIApiDeploymentName =
61
+ (fields?.azureOpenAIApiEmbeddingsDeploymentName ||
62
+ fields?.azureOpenAIApiDeploymentName) ??
63
+ (getEnvironmentVariable("AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME") ||
64
+ getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
65
+ this.azureADTokenProvider = fields?.azureADTokenProvider;
18
66
  }
19
67
  async embeddingWithRetry(request) {
20
68
  if (!this.client) {
@@ -2,28 +2,100 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AzureOpenAI = void 0;
4
4
  const openai_1 = require("openai");
5
+ const env_1 = require("@langchain/core/utils/env");
5
6
  const llms_js_1 = require("../llms.cjs");
6
7
  const azure_js_1 = require("../utils/azure.cjs");
7
8
  class AzureOpenAI extends llms_js_1.OpenAI {
8
9
  get lc_aliases() {
9
10
  return {
11
+ ...super.lc_aliases,
10
12
  openAIApiKey: "openai_api_key",
11
13
  openAIApiVersion: "openai_api_version",
12
14
  openAIBasePath: "openai_api_base",
15
+ deploymentName: "deployment_name",
16
+ azureOpenAIEndpoint: "azure_endpoint",
17
+ azureOpenAIApiVersion: "openai_api_version",
18
+ azureOpenAIBasePath: "openai_api_base",
19
+ azureOpenAIApiDeploymentName: "deployment_name",
20
+ };
21
+ }
22
+ get lc_secrets() {
23
+ return {
24
+ ...super.lc_secrets,
25
+ azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
13
26
  };
14
27
  }
15
28
  constructor(fields) {
16
- const newFields = fields ? { ...fields } : fields;
17
- if (newFields) {
18
- // don't rewrite the fields if they are already set
19
- newFields.azureOpenAIApiDeploymentName =
20
- newFields.azureOpenAIApiDeploymentName ?? newFields.deploymentName;
21
- newFields.azureOpenAIApiKey =
22
- newFields.azureOpenAIApiKey ?? newFields.openAIApiKey;
23
- newFields.azureOpenAIApiVersion =
24
- newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
29
+ super(fields);
30
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "azureOpenAIApiKey", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "azureADTokenProvider", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "azureOpenAIBasePath", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "azureOpenAIEndpoint", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ this.azureOpenAIApiDeploymentName =
73
+ (fields?.azureOpenAIApiCompletionsDeploymentName ||
74
+ fields?.azureOpenAIApiDeploymentName) ??
75
+ ((0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME") ||
76
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
77
+ this.azureOpenAIApiKey =
78
+ fields?.azureOpenAIApiKey ??
79
+ fields?.openAIApiKey ??
80
+ fields?.apiKey ??
81
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
82
+ this.azureOpenAIApiInstanceName =
83
+ fields?.azureOpenAIApiInstanceName ??
84
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
85
+ this.azureOpenAIApiVersion =
86
+ fields?.azureOpenAIApiVersion ??
87
+ fields?.openAIApiVersion ??
88
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
89
+ this.azureOpenAIBasePath =
90
+ fields?.azureOpenAIBasePath ??
91
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
92
+ this.azureOpenAIEndpoint =
93
+ fields?.azureOpenAIEndpoint ??
94
+ (0, env_1.getEnvironmentVariable)("AZURE_OPENAI_ENDPOINT");
95
+ this.azureADTokenProvider = fields?.azureADTokenProvider;
96
+ if (!this.azureOpenAIApiKey && !this.apiKey && !this.azureADTokenProvider) {
97
+ throw new Error("Azure OpenAI API key or Token Provider not found");
25
98
  }
26
- super(newFields);
27
99
  }
28
100
  _getClientOptions(options) {
29
101
  if (!this.client) {
@@ -1,16 +1,26 @@
1
1
  import { type ClientOptions } from "openai";
2
2
  import { type BaseLLMParams } from "@langchain/core/language_models/llms";
3
3
  import { OpenAI } from "../llms.js";
4
- import type { OpenAIInput, AzureOpenAIInput, OpenAICoreRequestOptions, LegacyOpenAIInput } from "../types.js";
4
+ import type { OpenAIInput, AzureOpenAIInput, OpenAICoreRequestOptions } from "../types.js";
5
5
  export declare class AzureOpenAI extends OpenAI {
6
+ azureOpenAIApiVersion?: string;
7
+ azureOpenAIApiKey?: string;
8
+ azureADTokenProvider?: () => Promise<string>;
9
+ azureOpenAIApiInstanceName?: string;
10
+ azureOpenAIApiDeploymentName?: string;
11
+ azureOpenAIBasePath?: string;
12
+ azureOpenAIEndpoint?: string;
6
13
  get lc_aliases(): Record<string, string>;
14
+ get lc_secrets(): {
15
+ [key: string]: string;
16
+ } | undefined;
7
17
  constructor(fields?: Partial<OpenAIInput> & {
8
18
  openAIApiKey?: string;
9
19
  openAIApiVersion?: string;
10
20
  openAIBasePath?: string;
11
21
  deploymentName?: string;
12
22
  } & Partial<AzureOpenAIInput> & BaseLLMParams & {
13
- configuration?: ClientOptions & LegacyOpenAIInput;
23
+ configuration?: ClientOptions;
14
24
  });
15
25
  protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
16
26
  toJSON(): any;