@langchain/openai 0.5.10 → 0.5.12

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.
@@ -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 `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
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 `.bind`, call options should be passed via the first argument
31
- * const llmWithArgsBound = llm.bind({
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.bind({ response_format: { type: "json_object" } });
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 `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
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 `.bind`, call options should be passed via the first argument
33
- * const llmWithArgsBound = llm.bind({
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.bind({ response_format: { type: "json_object" } });
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 `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
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 `.bind`, call options should be passed via the first argument
28
- * const llmWithArgsBound = llm.bind({
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.bind({ response_format: { type: "json_object" } });
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
  * );
@@ -300,7 +300,7 @@ function _convertMessagesToOpenAIResponsesParams(messages, model, zdrEnabled) {
300
300
  return {
301
301
  type: "function_call_output",
302
302
  call_id: toolMessage.tool_call_id,
303
- id: toolMessage.id,
303
+ id: toolMessage.id?.startsWith("fc_") ? toolMessage.id : undefined,
304
304
  output: typeof toolMessage.content !== "string"
305
305
  ? JSON.stringify(toolMessage.content)
306
306
  : toolMessage.content,
@@ -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 `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
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 `.bind`, call options should be passed via the first argument
696
- * const llmWithArgsBound = llm.bind({
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.bind({ response_format: { type: "json_object" } });
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 `.bind` as a call argument.
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 `.bind` as a call argument.
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.bind({
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.bind({
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.bind({
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.bind({
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.bind({
2543
+ llm = this.withConfig({
2546
2544
  tools: [
2547
2545
  {
2548
2546
  type: "function",
@@ -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 `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
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 `.bind`, call options should be passed via the first argument
192
- * const llmWithArgsBound = llm.bind({
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.bind({ response_format: { type: "json_object" } });
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 `.bind` as a call argument.
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 `.bind` as a call argument.
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",
@@ -295,7 +295,7 @@ function _convertMessagesToOpenAIResponsesParams(messages, model, zdrEnabled) {
295
295
  return {
296
296
  type: "function_call_output",
297
297
  call_id: toolMessage.tool_call_id,
298
- id: toolMessage.id,
298
+ id: toolMessage.id?.startsWith("fc_") ? toolMessage.id : undefined,
299
299
  output: typeof toolMessage.content !== "string"
300
300
  ? JSON.stringify(toolMessage.content)
301
301
  : toolMessage.content,
@@ -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 `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
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 `.bind`, call options should be passed via the first argument
691
- * const llmWithArgsBound = llm.bind({
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.bind({ response_format: { type: "json_object" } });
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 `.bind` as a call argument.
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 `.bind` as a call argument.
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.bind({
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.bind({
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.bind({
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.bind({
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.bind({
2538
+ llm = this.withConfig({
2541
2539
  tools: [
2542
2540
  {
2543
2541
  type: "function",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.5.10",
3
+ "version": "0.5.12",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -46,7 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@azure/identity": "^4.2.1",
48
48
  "@jest/globals": "^29.5.0",
49
- "@langchain/core": "workspace:*",
49
+ "@langchain/core": "0.3.57",
50
50
  "@langchain/scripts": ">=0.1.0 <0.2.0",
51
51
  "@langchain/standard-tests": "0.0.0",
52
52
  "@swc/core": "^1.3.90",
@@ -103,4 +103,4 @@
103
103
  "index.d.ts",
104
104
  "index.d.cts"
105
105
  ]
106
- }
106
+ }