@langchain/openai 0.5.16 → 0.5.17

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/types.d.ts CHANGED
@@ -135,13 +135,6 @@ export interface OpenAIChatInput extends OpenAIBaseInput {
135
135
  * [Learn more](https://platform.openai.com/docs/guides/audio).
136
136
  */
137
137
  audio?: OpenAIClient.Chat.ChatCompletionAudioParam;
138
- /**
139
- * Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high.
140
- * Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
141
- *
142
- * @deprecated Use the {@link reasoning} object instead.
143
- */
144
- reasoningEffort?: OpenAIClient.Chat.ChatCompletionReasoningEffort;
145
138
  /**
146
139
  * Options for reasoning models.
147
140
  *
@@ -4,12 +4,15 @@ exports.formatToOpenAITool = exports.formatToOpenAIFunction = void 0;
4
4
  exports.wrapOpenAIClientError = wrapOpenAIClientError;
5
5
  exports.formatToOpenAIAssistantTool = formatToOpenAIAssistantTool;
6
6
  exports.formatToOpenAIToolChoice = formatToOpenAIToolChoice;
7
+ exports.interopZodResponseFormat = interopZodResponseFormat;
7
8
  const openai_1 = require("openai");
8
9
  const function_calling_1 = require("@langchain/core/utils/function_calling");
9
10
  Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
10
11
  Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
11
12
  const types_1 = require("@langchain/core/utils/types");
12
13
  const json_schema_1 = require("@langchain/core/utils/json_schema");
14
+ const core_1 = require("zod/v4/core");
15
+ const zod_1 = require("openai/helpers/zod");
13
16
  const errors_js_1 = require("./errors.cjs");
14
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
18
  function wrapOpenAIClientError(e) {
@@ -76,3 +79,49 @@ function formatToOpenAIToolChoice(toolChoice) {
76
79
  return toolChoice;
77
80
  }
78
81
  }
82
+ // inlined from openai/lib/parser.ts
83
+ function makeParseableResponseFormat(response_format, parser) {
84
+ const obj = { ...response_format };
85
+ Object.defineProperties(obj, {
86
+ $brand: {
87
+ value: "auto-parseable-response-format",
88
+ enumerable: false,
89
+ },
90
+ $parseRaw: {
91
+ value: parser,
92
+ enumerable: false,
93
+ },
94
+ });
95
+ return obj;
96
+ }
97
+ function interopZodResponseFormat(zodSchema, name, props) {
98
+ if ((0, types_1.isZodSchemaV3)(zodSchema)) {
99
+ return (0, zod_1.zodResponseFormat)(zodSchema, name, props);
100
+ }
101
+ if ((0, types_1.isZodSchemaV4)(zodSchema)) {
102
+ return makeParseableResponseFormat({
103
+ type: "json_schema",
104
+ json_schema: {
105
+ ...props,
106
+ name,
107
+ strict: true,
108
+ schema: (0, core_1.toJSONSchema)(zodSchema, {
109
+ cycles: "ref", // equivalent to nameStrategy: 'duplicate-ref'
110
+ reused: "ref", // equivalent to $refStrategy: 'extract-to-root'
111
+ override(ctx) {
112
+ ctx.jsonSchema.title = name; // equivalent to `name` property
113
+ // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)
114
+ // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)
115
+ },
116
+ /// property equivalents from native `zodResponseFormat` fn
117
+ // openaiStrictMode: true,
118
+ // name,
119
+ // nameStrategy: 'duplicate-ref',
120
+ // $refStrategy: 'extract-to-root',
121
+ // nullableStrategy: 'property',
122
+ }),
123
+ },
124
+ }, (content) => (0, core_1.parse)(zodSchema, JSON.parse(content)));
125
+ }
126
+ throw new Error("Unsupported schema response format");
127
+ }
@@ -2,8 +2,14 @@ import { OpenAI as OpenAIClient } from "openai";
2
2
  import type { StructuredToolInterface } from "@langchain/core/tools";
3
3
  import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
4
4
  import { ToolDefinition } from "@langchain/core/language_models/base";
5
+ import { InteropZodType } from "@langchain/core/utils/types";
6
+ import { ResponseFormatJSONSchema } from "openai/resources";
5
7
  export declare function wrapOpenAIClientError(e: any): any;
6
8
  export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
7
9
  export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): ToolDefinition;
8
10
  export type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | "any" | string;
9
11
  export declare function formatToOpenAIToolChoice(toolChoice?: OpenAIToolChoice): OpenAIClient.ChatCompletionToolChoiceOption | undefined;
12
+ export declare function interopZodResponseFormat(zodSchema: InteropZodType, name: string, props: Omit<ResponseFormatJSONSchema.JSONSchema, "schema" | "strict" | "name">): {
13
+ json_schema: ResponseFormatJSONSchema.JSONSchema;
14
+ type: "json_schema";
15
+ };
@@ -1,7 +1,9 @@
1
1
  import { APIConnectionTimeoutError, APIUserAbortError, } from "openai";
2
2
  import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
3
- import { isInteropZodSchema } from "@langchain/core/utils/types";
3
+ import { isInteropZodSchema, isZodSchemaV3, isZodSchemaV4, } from "@langchain/core/utils/types";
4
4
  import { toJsonSchema } from "@langchain/core/utils/json_schema";
5
+ import { toJSONSchema as toJSONSchemaV4, parse as parseV4 } from "zod/v4/core";
6
+ import { zodResponseFormat } from "openai/helpers/zod";
5
7
  import { addLangChainErrorFields } from "./errors.js";
6
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
9
  export function wrapOpenAIClientError(e) {
@@ -69,3 +71,49 @@ export function formatToOpenAIToolChoice(toolChoice) {
69
71
  return toolChoice;
70
72
  }
71
73
  }
74
+ // inlined from openai/lib/parser.ts
75
+ function makeParseableResponseFormat(response_format, parser) {
76
+ const obj = { ...response_format };
77
+ Object.defineProperties(obj, {
78
+ $brand: {
79
+ value: "auto-parseable-response-format",
80
+ enumerable: false,
81
+ },
82
+ $parseRaw: {
83
+ value: parser,
84
+ enumerable: false,
85
+ },
86
+ });
87
+ return obj;
88
+ }
89
+ export function interopZodResponseFormat(zodSchema, name, props) {
90
+ if (isZodSchemaV3(zodSchema)) {
91
+ return zodResponseFormat(zodSchema, name, props);
92
+ }
93
+ if (isZodSchemaV4(zodSchema)) {
94
+ return makeParseableResponseFormat({
95
+ type: "json_schema",
96
+ json_schema: {
97
+ ...props,
98
+ name,
99
+ strict: true,
100
+ schema: toJSONSchemaV4(zodSchema, {
101
+ cycles: "ref", // equivalent to nameStrategy: 'duplicate-ref'
102
+ reused: "ref", // equivalent to $refStrategy: 'extract-to-root'
103
+ override(ctx) {
104
+ ctx.jsonSchema.title = name; // equivalent to `name` property
105
+ // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)
106
+ // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)
107
+ },
108
+ /// property equivalents from native `zodResponseFormat` fn
109
+ // openaiStrictMode: true,
110
+ // name,
111
+ // nameStrategy: 'duplicate-ref',
112
+ // $refStrategy: 'extract-to-root',
113
+ // nullableStrategy: 'property',
114
+ }),
115
+ },
116
+ }, (content) => parseV4(zodSchema, JSON.parse(content)));
117
+ }
118
+ throw new Error("Unsupported schema response format");
119
+ }
@@ -26,7 +26,7 @@ const chat_models_js_1 = require("../chat_models.cjs");
26
26
  * const openAIClient = new OpenAI();
27
27
  *
28
28
  * const openaiResponse = await openAIClient.chat.completions.create({
29
- * model: "gpt-4o",
29
+ * model: "gpt-4o-mini",
30
30
  * messages,
31
31
  * });
32
32
  * ```
@@ -24,7 +24,7 @@ import type { OpenAI } from "openai";
24
24
  * const openAIClient = new OpenAI();
25
25
  *
26
26
  * const openaiResponse = await openAIClient.chat.completions.create({
27
- * model: "gpt-4o",
27
+ * model: "gpt-4o-mini",
28
28
  * messages,
29
29
  * });
30
30
  * ```
@@ -23,7 +23,7 @@ import { _convertMessagesToOpenAIParams } from "../chat_models.js";
23
23
  * const openAIClient = new OpenAI();
24
24
  *
25
25
  * const openaiResponse = await openAIClient.chat.completions.create({
26
- * model: "gpt-4o",
26
+ * model: "gpt-4o-mini",
27
27
  * messages,
28
28
  * });
29
29
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "0.5.16",
3
+ "version": "0.5.17",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {