@langchain/openai 0.5.9 → 0.5.11
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 +4 -4
- package/dist/azure/chat_models.d.ts +4 -4
- package/dist/azure/chat_models.js +4 -4
- package/dist/chat_models.cjs +12 -14
- package/dist/chat_models.d.ts +6 -6
- package/dist/chat_models.js +12 -14
- package/package.json +1 -1
|
@@ -24,11 +24,11 @@ const azure_js_1 = require("../utils/azure.cjs");
|
|
|
24
24
|
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)
|
|
25
25
|
*
|
|
26
26
|
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
27
|
-
* They can also be passed via `.
|
|
27
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
28
28
|
*
|
|
29
29
|
* ```typescript
|
|
30
|
-
* // When calling `.
|
|
31
|
-
* const llmWithArgsBound = llm.
|
|
30
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
31
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
32
32
|
* stop: ["\n"],
|
|
33
33
|
* tools: [...],
|
|
34
34
|
* });
|
|
@@ -280,7 +280,7 @@ const azure_js_1 = require("../utils/azure.cjs");
|
|
|
280
280
|
* <summary><strong>JSON Object Response Format</strong></summary>
|
|
281
281
|
*
|
|
282
282
|
* ```typescript
|
|
283
|
-
* const jsonLlm = llm.
|
|
283
|
+
* const jsonLlm = llm.withConfig({ response_format: { type: "json_object" } });
|
|
284
284
|
* const jsonLlmAiMsg = await jsonLlm.invoke(
|
|
285
285
|
* "Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]"
|
|
286
286
|
* );
|
|
@@ -26,11 +26,11 @@ export type { AzureOpenAIInput };
|
|
|
26
26
|
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)
|
|
27
27
|
*
|
|
28
28
|
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
29
|
-
* They can also be passed via `.
|
|
29
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
30
30
|
*
|
|
31
31
|
* ```typescript
|
|
32
|
-
* // When calling `.
|
|
33
|
-
* const llmWithArgsBound = llm.
|
|
32
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
33
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
34
34
|
* stop: ["\n"],
|
|
35
35
|
* tools: [...],
|
|
36
36
|
* });
|
|
@@ -282,7 +282,7 @@ export type { AzureOpenAIInput };
|
|
|
282
282
|
* <summary><strong>JSON Object Response Format</strong></summary>
|
|
283
283
|
*
|
|
284
284
|
* ```typescript
|
|
285
|
-
* const jsonLlm = llm.
|
|
285
|
+
* const jsonLlm = llm.withConfig({ response_format: { type: "json_object" } });
|
|
286
286
|
* const jsonLlmAiMsg = await jsonLlm.invoke(
|
|
287
287
|
* "Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]"
|
|
288
288
|
* );
|
|
@@ -21,11 +21,11 @@ import { getEndpoint } from "../utils/azure.js";
|
|
|
21
21
|
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)
|
|
22
22
|
*
|
|
23
23
|
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
24
|
-
* They can also be passed via `.
|
|
24
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
25
25
|
*
|
|
26
26
|
* ```typescript
|
|
27
|
-
* // When calling `.
|
|
28
|
-
* const llmWithArgsBound = llm.
|
|
27
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
28
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
29
29
|
* stop: ["\n"],
|
|
30
30
|
* tools: [...],
|
|
31
31
|
* });
|
|
@@ -277,7 +277,7 @@ import { getEndpoint } from "../utils/azure.js";
|
|
|
277
277
|
* <summary><strong>JSON Object Response Format</strong></summary>
|
|
278
278
|
*
|
|
279
279
|
* ```typescript
|
|
280
|
-
* const jsonLlm = llm.
|
|
280
|
+
* const jsonLlm = llm.withConfig({ response_format: { type: "json_object" } });
|
|
281
281
|
* const jsonLlmAiMsg = await jsonLlm.invoke(
|
|
282
282
|
* "Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]"
|
|
283
283
|
* );
|
package/dist/chat_models.cjs
CHANGED
|
@@ -545,7 +545,7 @@ function _convertOpenAIResponsesDeltaToBaseMessageChunk(chunk) {
|
|
|
545
545
|
type: "tool_call_chunk",
|
|
546
546
|
name: chunk.item.name,
|
|
547
547
|
args: chunk.item.arguments,
|
|
548
|
-
id: chunk.item.
|
|
548
|
+
id: chunk.item.call_id,
|
|
549
549
|
index: chunk.output_index,
|
|
550
550
|
});
|
|
551
551
|
additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY] = {
|
|
@@ -689,11 +689,11 @@ function isReasoningModel(model) {
|
|
|
689
689
|
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)
|
|
690
690
|
*
|
|
691
691
|
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
692
|
-
* They can also be passed via `.
|
|
692
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
693
693
|
*
|
|
694
694
|
* ```typescript
|
|
695
|
-
* // When calling `.
|
|
696
|
-
* const llmWithArgsBound = llm.
|
|
695
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
696
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
697
697
|
* stop: ["\n"],
|
|
698
698
|
* tools: [...],
|
|
699
699
|
* });
|
|
@@ -951,7 +951,7 @@ function isReasoningModel(model) {
|
|
|
951
951
|
* <summary><strong>JSON Object Response Format</strong></summary>
|
|
952
952
|
*
|
|
953
953
|
* ```typescript
|
|
954
|
-
* const jsonLlm = llm.
|
|
954
|
+
* const jsonLlm = llm.withConfig({ response_format: { type: "json_object" } });
|
|
955
955
|
* const jsonLlmAiMsg = await jsonLlm.invoke(
|
|
956
956
|
* "Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]"
|
|
957
957
|
* );
|
|
@@ -1143,7 +1143,7 @@ function isReasoningModel(model) {
|
|
|
1143
1143
|
*
|
|
1144
1144
|
* const modelWithAudioOutput = new ChatOpenAI({
|
|
1145
1145
|
* model: "gpt-4o-audio-preview",
|
|
1146
|
-
* // You may also pass these fields to `.
|
|
1146
|
+
* // You may also pass these fields to `.withConfig` as a call argument.
|
|
1147
1147
|
* modalities: ["text", "audio"], // Specifies that the model should output audio.
|
|
1148
1148
|
* audio: {
|
|
1149
1149
|
* voice: "alloy",
|
|
@@ -1180,7 +1180,7 @@ function isReasoningModel(model) {
|
|
|
1180
1180
|
*
|
|
1181
1181
|
* const modelWithAudioOutput = new ChatOpenAI({
|
|
1182
1182
|
* model: "gpt-4o-audio-preview",
|
|
1183
|
-
* // You may also pass these fields to `.
|
|
1183
|
+
* // You may also pass these fields to `.withConfig` as a call argument.
|
|
1184
1184
|
* modalities: ["text", "audio"], // Specifies that the model should output audio.
|
|
1185
1185
|
* audio: {
|
|
1186
1186
|
* voice: "alloy",
|
|
@@ -1538,8 +1538,6 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
1538
1538
|
this.maxTokens = fields?.maxCompletionTokens ?? fields?.maxTokens;
|
|
1539
1539
|
this.useResponsesApi = fields?.useResponsesApi ?? this.useResponsesApi;
|
|
1540
1540
|
this.disableStreaming = fields?.disableStreaming ?? this.disableStreaming;
|
|
1541
|
-
if (this.model === "o1")
|
|
1542
|
-
this.disableStreaming = true;
|
|
1543
1541
|
this.streaming = fields?.streaming ?? false;
|
|
1544
1542
|
if (this.disableStreaming)
|
|
1545
1543
|
this.streaming = false;
|
|
@@ -1578,7 +1576,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
1578
1576
|
else if (this.supportsStrictToolCalling !== undefined) {
|
|
1579
1577
|
strict = this.supportsStrictToolCalling;
|
|
1580
1578
|
}
|
|
1581
|
-
return this.
|
|
1579
|
+
return this.withConfig({
|
|
1582
1580
|
tools: tools.map((tool) => isBuiltInTool(tool)
|
|
1583
1581
|
? tool
|
|
1584
1582
|
: _convertChatOpenAIToolTypeToOpenAITool(tool, { strict })),
|
|
@@ -2460,7 +2458,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
2460
2458
|
console.warn(`[WARNING]: JSON Schema is not supported for model "${this.model}". Falling back to tool calling.`);
|
|
2461
2459
|
}
|
|
2462
2460
|
if (method === "jsonMode") {
|
|
2463
|
-
llm = this.
|
|
2461
|
+
llm = this.withConfig({
|
|
2464
2462
|
response_format: { type: "json_object" },
|
|
2465
2463
|
});
|
|
2466
2464
|
if (isZodSchema(schema)) {
|
|
@@ -2471,7 +2469,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
2471
2469
|
}
|
|
2472
2470
|
}
|
|
2473
2471
|
else if (method === "jsonSchema") {
|
|
2474
|
-
llm = this.
|
|
2472
|
+
llm = this.withConfig({
|
|
2475
2473
|
response_format: {
|
|
2476
2474
|
type: "json_schema",
|
|
2477
2475
|
json_schema: {
|
|
@@ -2500,7 +2498,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
2500
2498
|
// Is function calling
|
|
2501
2499
|
if (isZodSchema(schema)) {
|
|
2502
2500
|
const asJsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
|
|
2503
|
-
llm = this.
|
|
2501
|
+
llm = this.withConfig({
|
|
2504
2502
|
tools: [
|
|
2505
2503
|
{
|
|
2506
2504
|
type: "function",
|
|
@@ -2542,7 +2540,7 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
2542
2540
|
parameters: schema,
|
|
2543
2541
|
};
|
|
2544
2542
|
}
|
|
2545
|
-
llm = this.
|
|
2543
|
+
llm = this.withConfig({
|
|
2546
2544
|
tools: [
|
|
2547
2545
|
{
|
|
2548
2546
|
type: "function",
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -185,11 +185,11 @@ export interface ChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatMode
|
|
|
185
185
|
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)
|
|
186
186
|
*
|
|
187
187
|
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
188
|
-
* They can also be passed via `.
|
|
188
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
189
189
|
*
|
|
190
190
|
* ```typescript
|
|
191
|
-
* // When calling `.
|
|
192
|
-
* const llmWithArgsBound = llm.
|
|
191
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
192
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
193
193
|
* stop: ["\n"],
|
|
194
194
|
* tools: [...],
|
|
195
195
|
* });
|
|
@@ -447,7 +447,7 @@ export interface ChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatMode
|
|
|
447
447
|
* <summary><strong>JSON Object Response Format</strong></summary>
|
|
448
448
|
*
|
|
449
449
|
* ```typescript
|
|
450
|
-
* const jsonLlm = llm.
|
|
450
|
+
* const jsonLlm = llm.withConfig({ response_format: { type: "json_object" } });
|
|
451
451
|
* const jsonLlmAiMsg = await jsonLlm.invoke(
|
|
452
452
|
* "Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]"
|
|
453
453
|
* );
|
|
@@ -639,7 +639,7 @@ export interface ChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatMode
|
|
|
639
639
|
*
|
|
640
640
|
* const modelWithAudioOutput = new ChatOpenAI({
|
|
641
641
|
* model: "gpt-4o-audio-preview",
|
|
642
|
-
* // You may also pass these fields to `.
|
|
642
|
+
* // You may also pass these fields to `.withConfig` as a call argument.
|
|
643
643
|
* modalities: ["text", "audio"], // Specifies that the model should output audio.
|
|
644
644
|
* audio: {
|
|
645
645
|
* voice: "alloy",
|
|
@@ -676,7 +676,7 @@ export interface ChatOpenAIFields extends Partial<OpenAIChatInput>, BaseChatMode
|
|
|
676
676
|
*
|
|
677
677
|
* const modelWithAudioOutput = new ChatOpenAI({
|
|
678
678
|
* model: "gpt-4o-audio-preview",
|
|
679
|
-
* // You may also pass these fields to `.
|
|
679
|
+
* // You may also pass these fields to `.withConfig` as a call argument.
|
|
680
680
|
* modalities: ["text", "audio"], // Specifies that the model should output audio.
|
|
681
681
|
* audio: {
|
|
682
682
|
* voice: "alloy",
|
package/dist/chat_models.js
CHANGED
|
@@ -540,7 +540,7 @@ function _convertOpenAIResponsesDeltaToBaseMessageChunk(chunk) {
|
|
|
540
540
|
type: "tool_call_chunk",
|
|
541
541
|
name: chunk.item.name,
|
|
542
542
|
args: chunk.item.arguments,
|
|
543
|
-
id: chunk.item.
|
|
543
|
+
id: chunk.item.call_id,
|
|
544
544
|
index: chunk.output_index,
|
|
545
545
|
});
|
|
546
546
|
additional_kwargs[_FUNCTION_CALL_IDS_MAP_KEY] = {
|
|
@@ -684,11 +684,11 @@ function isReasoningModel(model) {
|
|
|
684
684
|
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)
|
|
685
685
|
*
|
|
686
686
|
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
687
|
-
* They can also be passed via `.
|
|
687
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
688
688
|
*
|
|
689
689
|
* ```typescript
|
|
690
|
-
* // When calling `.
|
|
691
|
-
* const llmWithArgsBound = llm.
|
|
690
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
691
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
692
692
|
* stop: ["\n"],
|
|
693
693
|
* tools: [...],
|
|
694
694
|
* });
|
|
@@ -946,7 +946,7 @@ function isReasoningModel(model) {
|
|
|
946
946
|
* <summary><strong>JSON Object Response Format</strong></summary>
|
|
947
947
|
*
|
|
948
948
|
* ```typescript
|
|
949
|
-
* const jsonLlm = llm.
|
|
949
|
+
* const jsonLlm = llm.withConfig({ response_format: { type: "json_object" } });
|
|
950
950
|
* const jsonLlmAiMsg = await jsonLlm.invoke(
|
|
951
951
|
* "Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]"
|
|
952
952
|
* );
|
|
@@ -1138,7 +1138,7 @@ function isReasoningModel(model) {
|
|
|
1138
1138
|
*
|
|
1139
1139
|
* const modelWithAudioOutput = new ChatOpenAI({
|
|
1140
1140
|
* model: "gpt-4o-audio-preview",
|
|
1141
|
-
* // You may also pass these fields to `.
|
|
1141
|
+
* // You may also pass these fields to `.withConfig` as a call argument.
|
|
1142
1142
|
* modalities: ["text", "audio"], // Specifies that the model should output audio.
|
|
1143
1143
|
* audio: {
|
|
1144
1144
|
* voice: "alloy",
|
|
@@ -1175,7 +1175,7 @@ function isReasoningModel(model) {
|
|
|
1175
1175
|
*
|
|
1176
1176
|
* const modelWithAudioOutput = new ChatOpenAI({
|
|
1177
1177
|
* model: "gpt-4o-audio-preview",
|
|
1178
|
-
* // You may also pass these fields to `.
|
|
1178
|
+
* // You may also pass these fields to `.withConfig` as a call argument.
|
|
1179
1179
|
* modalities: ["text", "audio"], // Specifies that the model should output audio.
|
|
1180
1180
|
* audio: {
|
|
1181
1181
|
* voice: "alloy",
|
|
@@ -1533,8 +1533,6 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
1533
1533
|
this.maxTokens = fields?.maxCompletionTokens ?? fields?.maxTokens;
|
|
1534
1534
|
this.useResponsesApi = fields?.useResponsesApi ?? this.useResponsesApi;
|
|
1535
1535
|
this.disableStreaming = fields?.disableStreaming ?? this.disableStreaming;
|
|
1536
|
-
if (this.model === "o1")
|
|
1537
|
-
this.disableStreaming = true;
|
|
1538
1536
|
this.streaming = fields?.streaming ?? false;
|
|
1539
1537
|
if (this.disableStreaming)
|
|
1540
1538
|
this.streaming = false;
|
|
@@ -1573,7 +1571,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
1573
1571
|
else if (this.supportsStrictToolCalling !== undefined) {
|
|
1574
1572
|
strict = this.supportsStrictToolCalling;
|
|
1575
1573
|
}
|
|
1576
|
-
return this.
|
|
1574
|
+
return this.withConfig({
|
|
1577
1575
|
tools: tools.map((tool) => isBuiltInTool(tool)
|
|
1578
1576
|
? tool
|
|
1579
1577
|
: _convertChatOpenAIToolTypeToOpenAITool(tool, { strict })),
|
|
@@ -2455,7 +2453,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
2455
2453
|
console.warn(`[WARNING]: JSON Schema is not supported for model "${this.model}". Falling back to tool calling.`);
|
|
2456
2454
|
}
|
|
2457
2455
|
if (method === "jsonMode") {
|
|
2458
|
-
llm = this.
|
|
2456
|
+
llm = this.withConfig({
|
|
2459
2457
|
response_format: { type: "json_object" },
|
|
2460
2458
|
});
|
|
2461
2459
|
if (isZodSchema(schema)) {
|
|
@@ -2466,7 +2464,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
2466
2464
|
}
|
|
2467
2465
|
}
|
|
2468
2466
|
else if (method === "jsonSchema") {
|
|
2469
|
-
llm = this.
|
|
2467
|
+
llm = this.withConfig({
|
|
2470
2468
|
response_format: {
|
|
2471
2469
|
type: "json_schema",
|
|
2472
2470
|
json_schema: {
|
|
@@ -2495,7 +2493,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
2495
2493
|
// Is function calling
|
|
2496
2494
|
if (isZodSchema(schema)) {
|
|
2497
2495
|
const asJsonSchema = zodToJsonSchema(schema);
|
|
2498
|
-
llm = this.
|
|
2496
|
+
llm = this.withConfig({
|
|
2499
2497
|
tools: [
|
|
2500
2498
|
{
|
|
2501
2499
|
type: "function",
|
|
@@ -2537,7 +2535,7 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
2537
2535
|
parameters: schema,
|
|
2538
2536
|
};
|
|
2539
2537
|
}
|
|
2540
|
-
llm = this.
|
|
2538
|
+
llm = this.withConfig({
|
|
2541
2539
|
tools: [
|
|
2542
2540
|
{
|
|
2543
2541
|
type: "function",
|