@langchain/openai 0.4.0-rc.0 → 0.4.1
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.
- package/dist/azure/chat_models.cjs +77 -16
- package/dist/azure/chat_models.d.ts +28 -4
- package/dist/azure/chat_models.js +78 -17
- package/dist/azure/embeddings.cjs +60 -12
- package/dist/azure/embeddings.d.ts +8 -2
- package/dist/azure/embeddings.js +60 -12
- package/dist/azure/llms.cjs +82 -10
- package/dist/azure/llms.d.ts +12 -2
- package/dist/azure/llms.js +82 -10
- package/dist/chat_models.cjs +22 -112
- package/dist/chat_models.d.ts +18 -20
- package/dist/chat_models.js +22 -112
- package/dist/embeddings.cjs +13 -99
- package/dist/embeddings.d.ts +11 -18
- package/dist/embeddings.js +13 -99
- package/dist/llms.cjs +28 -131
- package/dist/llms.d.ts +14 -27
- package/dist/llms.js +27 -130
- package/dist/types.d.ts +1 -12
- package/package.json +1 -1
- package/dist/legacy.cjs +0 -458
- package/dist/legacy.d.ts +0 -127
- package/dist/legacy.js +0 -454
|
@@ -2,9 +2,9 @@
|
|
|
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
|
-
const env_1 = require("@langchain/core/utils/env");
|
|
8
8
|
/**
|
|
9
9
|
* Azure OpenAI chat model integration.
|
|
10
10
|
*
|
|
@@ -257,7 +257,7 @@ const env_1 = require("@langchain/core/utils/env");
|
|
|
257
257
|
* const Joke = z.object({
|
|
258
258
|
* setup: z.string().describe("The setup of the joke"),
|
|
259
259
|
* punchline: z.string().describe("The punchline to the joke"),
|
|
260
|
-
* rating: z.number().
|
|
260
|
+
* rating: z.number().nullable().describe("How funny the joke is, from 1 to 10")
|
|
261
261
|
* }).describe('Joke to tell user.');
|
|
262
262
|
*
|
|
263
263
|
* const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
|
|
@@ -423,6 +423,7 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
423
423
|
}
|
|
424
424
|
get lc_aliases() {
|
|
425
425
|
return {
|
|
426
|
+
...super.lc_aliases,
|
|
426
427
|
openAIApiKey: "openai_api_key",
|
|
427
428
|
openAIApiVersion: "openai_api_version",
|
|
428
429
|
openAIBasePath: "openai_api_base",
|
|
@@ -433,32 +434,82 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
433
434
|
azureOpenAIApiDeploymentName: "deployment_name",
|
|
434
435
|
};
|
|
435
436
|
}
|
|
437
|
+
get lc_secrets() {
|
|
438
|
+
return {
|
|
439
|
+
...super.lc_secrets,
|
|
440
|
+
azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
|
|
441
|
+
};
|
|
442
|
+
}
|
|
436
443
|
constructor(fields) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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 ??
|
|
443
491
|
(0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_KEY");
|
|
444
|
-
|
|
445
|
-
newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
|
|
446
|
-
newFields.azureOpenAIApiInstanceName =
|
|
492
|
+
this.azureOpenAIApiInstanceName =
|
|
447
493
|
fields?.azureOpenAIApiInstanceName ??
|
|
448
494
|
(0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_INSTANCE_NAME");
|
|
449
|
-
|
|
495
|
+
this.azureOpenAIApiDeploymentName =
|
|
450
496
|
fields?.azureOpenAIApiDeploymentName ??
|
|
497
|
+
fields?.deploymentName ??
|
|
451
498
|
(0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_DEPLOYMENT_NAME");
|
|
452
|
-
|
|
499
|
+
this.azureOpenAIApiVersion =
|
|
453
500
|
fields?.azureOpenAIApiVersion ??
|
|
501
|
+
fields?.openAIApiVersion ??
|
|
454
502
|
(0, env_1.getEnvironmentVariable)("AZURE_OPENAI_API_VERSION");
|
|
455
|
-
|
|
503
|
+
this.azureOpenAIBasePath =
|
|
456
504
|
fields?.azureOpenAIBasePath ??
|
|
457
505
|
(0, env_1.getEnvironmentVariable)("AZURE_OPENAI_BASE_PATH");
|
|
458
|
-
|
|
506
|
+
this.azureOpenAIEndpoint =
|
|
459
507
|
fields?.azureOpenAIEndpoint ??
|
|
460
508
|
(0, env_1.getEnvironmentVariable)("AZURE_OPENAI_ENDPOINT");
|
|
461
|
-
|
|
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");
|
|
512
|
+
}
|
|
462
513
|
}
|
|
463
514
|
getLsParams(options) {
|
|
464
515
|
const params = super.getLsParams(options);
|
|
@@ -565,5 +616,15 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
565
616
|
}
|
|
566
617
|
return json;
|
|
567
618
|
}
|
|
619
|
+
withStructuredOutput(outputSchema, config) {
|
|
620
|
+
const ensuredConfig = { ...config };
|
|
621
|
+
// Not all Azure gpt-4o deployments models support jsonSchema yet
|
|
622
|
+
if (this.model.startsWith("gpt-4o")) {
|
|
623
|
+
if (ensuredConfig?.method === undefined) {
|
|
624
|
+
ensuredConfig.method = "functionCalling";
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return super.withStructuredOutput(outputSchema, ensuredConfig);
|
|
628
|
+
}
|
|
568
629
|
}
|
|
569
630
|
exports.AzureChatOpenAI = AzureChatOpenAI;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type ClientOptions } from "openai";
|
|
2
2
|
import { LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { BaseLanguageModelInput } from "@langchain/core/language_models/base";
|
|
4
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
5
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { ChatOpenAI, ChatOpenAIStructuredOutputMethodOptions } from "../chat_models.js";
|
|
8
|
+
import { AzureOpenAIInput, OpenAIChatInput, OpenAICoreRequestOptions } from "../types.js";
|
|
9
|
+
export type { AzureOpenAIInput };
|
|
5
10
|
/**
|
|
6
11
|
* Azure OpenAI chat model integration.
|
|
7
12
|
*
|
|
@@ -254,7 +259,7 @@ import { AzureOpenAIInput, LegacyOpenAIInput, OpenAIChatInput, OpenAICoreRequest
|
|
|
254
259
|
* const Joke = z.object({
|
|
255
260
|
* setup: z.string().describe("The setup of the joke"),
|
|
256
261
|
* punchline: z.string().describe("The punchline to the joke"),
|
|
257
|
-
* rating: z.number().
|
|
262
|
+
* rating: z.number().nullable().describe("How funny the joke is, from 1 to 10")
|
|
258
263
|
* }).describe('Joke to tell user.');
|
|
259
264
|
*
|
|
260
265
|
* const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
|
|
@@ -415,17 +420,36 @@ import { AzureOpenAIInput, LegacyOpenAIInput, OpenAIChatInput, OpenAICoreRequest
|
|
|
415
420
|
* </details>
|
|
416
421
|
*/
|
|
417
422
|
export declare class AzureChatOpenAI extends ChatOpenAI {
|
|
423
|
+
azureOpenAIApiVersion?: string;
|
|
424
|
+
azureOpenAIApiKey?: string;
|
|
425
|
+
azureADTokenProvider?: () => Promise<string>;
|
|
426
|
+
azureOpenAIApiInstanceName?: string;
|
|
427
|
+
azureOpenAIApiDeploymentName?: string;
|
|
428
|
+
azureOpenAIBasePath?: string;
|
|
429
|
+
azureOpenAIEndpoint?: string;
|
|
418
430
|
_llmType(): string;
|
|
419
431
|
get lc_aliases(): Record<string, string>;
|
|
432
|
+
get lc_secrets(): {
|
|
433
|
+
[key: string]: string;
|
|
434
|
+
} | undefined;
|
|
420
435
|
constructor(fields?: Partial<OpenAIChatInput> & Partial<AzureOpenAIInput> & {
|
|
421
436
|
openAIApiKey?: string;
|
|
422
437
|
openAIApiVersion?: string;
|
|
423
438
|
openAIBasePath?: string;
|
|
424
439
|
deploymentName?: string;
|
|
425
440
|
} & BaseChatModelParams & {
|
|
426
|
-
configuration?: ClientOptions
|
|
441
|
+
configuration?: ClientOptions;
|
|
427
442
|
});
|
|
428
443
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
429
444
|
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
430
445
|
toJSON(): any;
|
|
446
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
447
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
448
|
+
raw: BaseMessage;
|
|
449
|
+
parsed: RunOutput;
|
|
450
|
+
}>;
|
|
451
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: ChatOpenAIStructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
452
|
+
raw: BaseMessage;
|
|
453
|
+
parsed: RunOutput;
|
|
454
|
+
}>;
|
|
431
455
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AzureOpenAI as AzureOpenAIClient } from "openai";
|
|
2
|
-
import { ChatOpenAI } from "../chat_models.js";
|
|
3
|
-
import { getEndpoint } from "../utils/azure.js";
|
|
4
2
|
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
3
|
+
import { ChatOpenAI, } from "../chat_models.js";
|
|
4
|
+
import { getEndpoint } from "../utils/azure.js";
|
|
5
5
|
/**
|
|
6
6
|
* Azure OpenAI chat model integration.
|
|
7
7
|
*
|
|
@@ -254,7 +254,7 @@ import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
|
254
254
|
* const Joke = z.object({
|
|
255
255
|
* setup: z.string().describe("The setup of the joke"),
|
|
256
256
|
* punchline: z.string().describe("The punchline to the joke"),
|
|
257
|
-
* rating: z.number().
|
|
257
|
+
* rating: z.number().nullable().describe("How funny the joke is, from 1 to 10")
|
|
258
258
|
* }).describe('Joke to tell user.');
|
|
259
259
|
*
|
|
260
260
|
* const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
|
|
@@ -420,6 +420,7 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
420
420
|
}
|
|
421
421
|
get lc_aliases() {
|
|
422
422
|
return {
|
|
423
|
+
...super.lc_aliases,
|
|
423
424
|
openAIApiKey: "openai_api_key",
|
|
424
425
|
openAIApiVersion: "openai_api_version",
|
|
425
426
|
openAIBasePath: "openai_api_base",
|
|
@@ -430,32 +431,82 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
430
431
|
azureOpenAIApiDeploymentName: "deployment_name",
|
|
431
432
|
};
|
|
432
433
|
}
|
|
434
|
+
get lc_secrets() {
|
|
435
|
+
return {
|
|
436
|
+
...super.lc_secrets,
|
|
437
|
+
azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
|
|
438
|
+
};
|
|
439
|
+
}
|
|
433
440
|
constructor(fields) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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 ??
|
|
440
488
|
getEnvironmentVariable("AZURE_OPENAI_API_KEY");
|
|
441
|
-
|
|
442
|
-
newFields.azureOpenAIApiVersion ?? newFields.openAIApiVersion;
|
|
443
|
-
newFields.azureOpenAIApiInstanceName =
|
|
489
|
+
this.azureOpenAIApiInstanceName =
|
|
444
490
|
fields?.azureOpenAIApiInstanceName ??
|
|
445
491
|
getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
|
|
446
|
-
|
|
492
|
+
this.azureOpenAIApiDeploymentName =
|
|
447
493
|
fields?.azureOpenAIApiDeploymentName ??
|
|
494
|
+
fields?.deploymentName ??
|
|
448
495
|
getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME");
|
|
449
|
-
|
|
496
|
+
this.azureOpenAIApiVersion =
|
|
450
497
|
fields?.azureOpenAIApiVersion ??
|
|
498
|
+
fields?.openAIApiVersion ??
|
|
451
499
|
getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
|
|
452
|
-
|
|
500
|
+
this.azureOpenAIBasePath =
|
|
453
501
|
fields?.azureOpenAIBasePath ??
|
|
454
502
|
getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
|
|
455
|
-
|
|
503
|
+
this.azureOpenAIEndpoint =
|
|
456
504
|
fields?.azureOpenAIEndpoint ??
|
|
457
505
|
getEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
|
|
458
|
-
|
|
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");
|
|
509
|
+
}
|
|
459
510
|
}
|
|
460
511
|
getLsParams(options) {
|
|
461
512
|
const params = super.getLsParams(options);
|
|
@@ -562,4 +613,14 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
562
613
|
}
|
|
563
614
|
return json;
|
|
564
615
|
}
|
|
616
|
+
withStructuredOutput(outputSchema, config) {
|
|
617
|
+
const ensuredConfig = { ...config };
|
|
618
|
+
// Not all Azure gpt-4o deployments models support jsonSchema yet
|
|
619
|
+
if (this.model.startsWith("gpt-4o")) {
|
|
620
|
+
if (ensuredConfig?.method === undefined) {
|
|
621
|
+
ensuredConfig.method = "functionCalling";
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return super.withStructuredOutput(outputSchema, ensuredConfig);
|
|
625
|
+
}
|
|
565
626
|
}
|
|
@@ -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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
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
|
-
}
|
|
18
|
+
});
|
|
13
19
|
protected embeddingWithRetry(request: OpenAIClient.EmbeddingCreateParams): Promise<OpenAIClient.Embeddings.CreateEmbeddingResponse & {
|
|
14
20
|
_request_id?: string | null | undefined;
|
|
15
21
|
}>;
|
package/dist/azure/embeddings.js
CHANGED
|
@@ -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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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) {
|
package/dist/azure/llms.cjs
CHANGED
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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) {
|
package/dist/azure/llms.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
23
|
+
configuration?: ClientOptions;
|
|
14
24
|
});
|
|
15
25
|
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
16
26
|
toJSON(): any;
|