@langchain/openai 0.0.30 → 0.0.32
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 +12 -0
- package/dist/azure/chat_models.d.ts +2 -1
- package/dist/azure/chat_models.js +12 -0
- package/dist/azure/embeddings.cjs +7 -0
- package/dist/azure/embeddings.js +7 -0
- package/dist/azure/llms.cjs +7 -0
- package/dist/azure/llms.js +7 -0
- package/dist/chat_models.cjs +11 -0
- package/dist/chat_models.d.ts +2 -1
- package/dist/chat_models.js +11 -0
- package/dist/utils/azure.cjs +2 -2
- package/dist/utils/azure.d.ts +1 -0
- package/dist/utils/azure.js +2 -2
- package/package.json +2 -2
|
@@ -24,6 +24,11 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
24
24
|
}
|
|
25
25
|
super(newFields);
|
|
26
26
|
}
|
|
27
|
+
getLsParams(options) {
|
|
28
|
+
const params = super.getLsParams(options);
|
|
29
|
+
params.ls_provider = "azure";
|
|
30
|
+
return params;
|
|
31
|
+
}
|
|
27
32
|
_getClientOptions(options) {
|
|
28
33
|
if (!this.client) {
|
|
29
34
|
const openAIEndpointConfig = {
|
|
@@ -31,6 +36,7 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
31
36
|
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
32
37
|
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
33
38
|
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
39
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
34
40
|
baseURL: this.clientConfig.baseURL,
|
|
35
41
|
};
|
|
36
42
|
const endpoint = (0, azure_js_1.getEndpoint)(openAIEndpointConfig);
|
|
@@ -46,6 +52,12 @@ class AzureChatOpenAI extends chat_models_js_1.ChatOpenAI {
|
|
|
46
52
|
if (!params.baseURL) {
|
|
47
53
|
delete params.baseURL;
|
|
48
54
|
}
|
|
55
|
+
params.defaultHeaders = {
|
|
56
|
+
...params.defaultHeaders,
|
|
57
|
+
"User-Agent": params.defaultHeaders?.["User-Agent"]
|
|
58
|
+
? `${params.defaultHeaders["User-Agent"]}: langchainjs-azure-openai-v2`
|
|
59
|
+
: `langchainjs-azure-openai-v2`,
|
|
60
|
+
};
|
|
49
61
|
this.client = new openai_1.AzureOpenAI({
|
|
50
62
|
apiVersion: this.azureOpenAIApiVersion,
|
|
51
63
|
azureADTokenProvider: this.azureADTokenProvider,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ClientOptions } from "openai";
|
|
2
|
-
import { type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
2
|
+
import { LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
3
3
|
import { ChatOpenAI } from "../chat_models.js";
|
|
4
4
|
import { AzureOpenAIInput, LegacyOpenAIInput, OpenAIChatInput, OpenAICoreRequestOptions } from "../types.js";
|
|
5
5
|
export declare class AzureChatOpenAI extends ChatOpenAI {
|
|
@@ -13,6 +13,7 @@ export declare class AzureChatOpenAI extends ChatOpenAI {
|
|
|
13
13
|
} & BaseChatModelParams & {
|
|
14
14
|
configuration?: ClientOptions & LegacyOpenAIInput;
|
|
15
15
|
});
|
|
16
|
+
protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
16
17
|
protected _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;
|
|
17
18
|
toJSON(): any;
|
|
18
19
|
}
|
|
@@ -21,6 +21,11 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
21
21
|
}
|
|
22
22
|
super(newFields);
|
|
23
23
|
}
|
|
24
|
+
getLsParams(options) {
|
|
25
|
+
const params = super.getLsParams(options);
|
|
26
|
+
params.ls_provider = "azure";
|
|
27
|
+
return params;
|
|
28
|
+
}
|
|
24
29
|
_getClientOptions(options) {
|
|
25
30
|
if (!this.client) {
|
|
26
31
|
const openAIEndpointConfig = {
|
|
@@ -28,6 +33,7 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
28
33
|
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
29
34
|
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
30
35
|
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
36
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
31
37
|
baseURL: this.clientConfig.baseURL,
|
|
32
38
|
};
|
|
33
39
|
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
@@ -43,6 +49,12 @@ export class AzureChatOpenAI extends ChatOpenAI {
|
|
|
43
49
|
if (!params.baseURL) {
|
|
44
50
|
delete params.baseURL;
|
|
45
51
|
}
|
|
52
|
+
params.defaultHeaders = {
|
|
53
|
+
...params.defaultHeaders,
|
|
54
|
+
"User-Agent": params.defaultHeaders?.["User-Agent"]
|
|
55
|
+
? `${params.defaultHeaders["User-Agent"]}: langchainjs-azure-openai-v2`
|
|
56
|
+
: `langchainjs-azure-openai-v2`,
|
|
57
|
+
};
|
|
46
58
|
this.client = new AzureOpenAIClient({
|
|
47
59
|
apiVersion: this.azureOpenAIApiVersion,
|
|
48
60
|
azureADTokenProvider: this.azureADTokenProvider,
|
|
@@ -22,6 +22,7 @@ class AzureOpenAIEmbeddings extends embeddings_js_1.OpenAIEmbeddings {
|
|
|
22
22
|
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
23
23
|
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
24
24
|
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
25
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
25
26
|
baseURL: this.clientConfig.baseURL,
|
|
26
27
|
};
|
|
27
28
|
const endpoint = (0, azure_js_1.getEndpoint)(openAIEndpointConfig);
|
|
@@ -37,6 +38,12 @@ class AzureOpenAIEmbeddings extends embeddings_js_1.OpenAIEmbeddings {
|
|
|
37
38
|
if (!params.baseURL) {
|
|
38
39
|
delete params.baseURL;
|
|
39
40
|
}
|
|
41
|
+
params.defaultHeaders = {
|
|
42
|
+
...params.defaultHeaders,
|
|
43
|
+
"User-Agent": params.defaultHeaders?.["User-Agent"]
|
|
44
|
+
? `${params.defaultHeaders["User-Agent"]}: langchainjs-azure-openai-v2`
|
|
45
|
+
: `langchainjs-azure-openai-v2`,
|
|
46
|
+
};
|
|
40
47
|
this.client = new openai_1.AzureOpenAI({
|
|
41
48
|
apiVersion: this.azureOpenAIApiVersion,
|
|
42
49
|
azureADTokenProvider: this.azureADTokenProvider,
|
package/dist/azure/embeddings.js
CHANGED
|
@@ -19,6 +19,7 @@ export class AzureOpenAIEmbeddings extends OpenAIEmbeddings {
|
|
|
19
19
|
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
20
20
|
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
21
21
|
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
22
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
22
23
|
baseURL: this.clientConfig.baseURL,
|
|
23
24
|
};
|
|
24
25
|
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
@@ -34,6 +35,12 @@ export class AzureOpenAIEmbeddings extends OpenAIEmbeddings {
|
|
|
34
35
|
if (!params.baseURL) {
|
|
35
36
|
delete params.baseURL;
|
|
36
37
|
}
|
|
38
|
+
params.defaultHeaders = {
|
|
39
|
+
...params.defaultHeaders,
|
|
40
|
+
"User-Agent": params.defaultHeaders?.["User-Agent"]
|
|
41
|
+
? `${params.defaultHeaders["User-Agent"]}: langchainjs-azure-openai-v2`
|
|
42
|
+
: `langchainjs-azure-openai-v2`,
|
|
43
|
+
};
|
|
37
44
|
this.client = new AzureOpenAIClient({
|
|
38
45
|
apiVersion: this.azureOpenAIApiVersion,
|
|
39
46
|
azureADTokenProvider: this.azureADTokenProvider,
|
package/dist/azure/llms.cjs
CHANGED
|
@@ -28,6 +28,7 @@ class AzureOpenAI extends llms_js_1.OpenAI {
|
|
|
28
28
|
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
29
29
|
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
30
30
|
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
31
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
31
32
|
baseURL: this.clientConfig.baseURL,
|
|
32
33
|
};
|
|
33
34
|
const endpoint = (0, azure_js_1.getEndpoint)(openAIEndpointConfig);
|
|
@@ -43,6 +44,12 @@ class AzureOpenAI extends llms_js_1.OpenAI {
|
|
|
43
44
|
if (!params.baseURL) {
|
|
44
45
|
delete params.baseURL;
|
|
45
46
|
}
|
|
47
|
+
params.defaultHeaders = {
|
|
48
|
+
...params.defaultHeaders,
|
|
49
|
+
"User-Agent": params.defaultHeaders?.["User-Agent"]
|
|
50
|
+
? `${params.defaultHeaders["User-Agent"]}: langchainjs-azure-openai-v2`
|
|
51
|
+
: `langchainjs-azure-openai-v2`,
|
|
52
|
+
};
|
|
46
53
|
this.client = new openai_1.AzureOpenAI({
|
|
47
54
|
apiVersion: this.azureOpenAIApiVersion,
|
|
48
55
|
azureADTokenProvider: this.azureADTokenProvider,
|
package/dist/azure/llms.js
CHANGED
|
@@ -25,6 +25,7 @@ export class AzureOpenAI extends OpenAI {
|
|
|
25
25
|
azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
|
|
26
26
|
azureOpenAIApiKey: this.azureOpenAIApiKey,
|
|
27
27
|
azureOpenAIBasePath: this.azureOpenAIBasePath,
|
|
28
|
+
azureADTokenProvider: this.azureADTokenProvider,
|
|
28
29
|
baseURL: this.clientConfig.baseURL,
|
|
29
30
|
};
|
|
30
31
|
const endpoint = getEndpoint(openAIEndpointConfig);
|
|
@@ -40,6 +41,12 @@ export class AzureOpenAI extends OpenAI {
|
|
|
40
41
|
if (!params.baseURL) {
|
|
41
42
|
delete params.baseURL;
|
|
42
43
|
}
|
|
44
|
+
params.defaultHeaders = {
|
|
45
|
+
...params.defaultHeaders,
|
|
46
|
+
"User-Agent": params.defaultHeaders?.["User-Agent"]
|
|
47
|
+
? `${params.defaultHeaders["User-Agent"]}: langchainjs-azure-openai-v2`
|
|
48
|
+
: `langchainjs-azure-openai-v2`,
|
|
49
|
+
};
|
|
43
50
|
this.client = new AzureOpenAIClient({
|
|
44
51
|
apiVersion: this.azureOpenAIApiVersion,
|
|
45
52
|
azureADTokenProvider: this.azureADTokenProvider,
|
package/dist/chat_models.cjs
CHANGED
|
@@ -482,6 +482,17 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
482
482
|
...fields?.configuration,
|
|
483
483
|
};
|
|
484
484
|
}
|
|
485
|
+
getLsParams(options) {
|
|
486
|
+
const params = this.invocationParams(options);
|
|
487
|
+
return {
|
|
488
|
+
ls_provider: "openai",
|
|
489
|
+
ls_model_name: this.model,
|
|
490
|
+
ls_model_type: "chat",
|
|
491
|
+
ls_temperature: params.temperature ?? undefined,
|
|
492
|
+
ls_max_tokens: params.max_tokens ?? undefined,
|
|
493
|
+
ls_stop: options.stop,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
485
496
|
bindTools(tools, kwargs) {
|
|
486
497
|
return this.bind({
|
|
487
498
|
tools: tools.map(function_calling_1.convertToOpenAITool),
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
|
3
3
|
import { AIMessageChunk, type BaseMessage } from "@langchain/core/messages";
|
|
4
4
|
import { ChatGenerationChunk, type ChatResult } from "@langchain/core/outputs";
|
|
5
5
|
import { type StructuredToolInterface } from "@langchain/core/tools";
|
|
6
|
-
import { BaseChatModel, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
6
|
+
import { BaseChatModel, LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
7
7
|
import type { BaseFunctionCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, StructuredOutputMethodParams } from "@langchain/core/language_models/base";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { Runnable, RunnableInterface } from "@langchain/core/runnables";
|
|
@@ -103,6 +103,7 @@ export declare class ChatOpenAI<CallOptions extends ChatOpenAICallOptions = Chat
|
|
|
103
103
|
},
|
|
104
104
|
/** @deprecated */
|
|
105
105
|
configuration?: ClientOptions & LegacyOpenAIInput);
|
|
106
|
+
protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
106
107
|
bindTools(tools: (Record<string, unknown> | StructuredToolInterface)[], kwargs?: Partial<CallOptions>): RunnableInterface<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
|
|
107
108
|
/**
|
|
108
109
|
* Get the parameters used to invoke the model
|
package/dist/chat_models.js
CHANGED
|
@@ -478,6 +478,17 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
478
478
|
...fields?.configuration,
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
|
+
getLsParams(options) {
|
|
482
|
+
const params = this.invocationParams(options);
|
|
483
|
+
return {
|
|
484
|
+
ls_provider: "openai",
|
|
485
|
+
ls_model_name: this.model,
|
|
486
|
+
ls_model_type: "chat",
|
|
487
|
+
ls_temperature: params.temperature ?? undefined,
|
|
488
|
+
ls_max_tokens: params.max_tokens ?? undefined,
|
|
489
|
+
ls_stop: options.stop,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
481
492
|
bindTools(tools, kwargs) {
|
|
482
493
|
return this.bind({
|
|
483
494
|
tools: tools.map(convertToOpenAITool),
|
package/dist/utils/azure.cjs
CHANGED
|
@@ -24,13 +24,13 @@ exports.getEndpoint = void 0;
|
|
|
24
24
|
* @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
|
|
25
25
|
*/
|
|
26
26
|
function getEndpoint(config) {
|
|
27
|
-
const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, } = config;
|
|
27
|
+
const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, } = config;
|
|
28
28
|
if (azureOpenAIApiKey &&
|
|
29
29
|
azureOpenAIBasePath &&
|
|
30
30
|
azureOpenAIApiDeploymentName) {
|
|
31
31
|
return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
|
|
32
32
|
}
|
|
33
|
-
if (azureOpenAIApiKey) {
|
|
33
|
+
if (azureOpenAIApiKey || azureADTokenProvider) {
|
|
34
34
|
if (!azureOpenAIApiInstanceName) {
|
|
35
35
|
throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");
|
|
36
36
|
}
|
package/dist/utils/azure.d.ts
CHANGED
package/dist/utils/azure.js
CHANGED
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
* @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
|
|
22
22
|
*/
|
|
23
23
|
export function getEndpoint(config) {
|
|
24
|
-
const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, } = config;
|
|
24
|
+
const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, } = config;
|
|
25
25
|
if (azureOpenAIApiKey &&
|
|
26
26
|
azureOpenAIBasePath &&
|
|
27
27
|
azureOpenAIApiDeploymentName) {
|
|
28
28
|
return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
|
|
29
29
|
}
|
|
30
|
-
if (azureOpenAIApiKey) {
|
|
30
|
+
if (azureOpenAIApiKey || azureADTokenProvider) {
|
|
31
31
|
if (!azureOpenAIApiInstanceName) {
|
|
32
32
|
throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");
|
|
33
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"author": "LangChain",
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@langchain/core": "
|
|
42
|
+
"@langchain/core": ">0.1.56 <0.3.0",
|
|
43
43
|
"js-tiktoken": "^1.0.12",
|
|
44
44
|
"openai": "^4.41.1",
|
|
45
45
|
"zod": "^3.22.4",
|