@langchain/openai 0.5.3 → 0.5.5
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/chat_models.cjs +25 -27
- package/dist/chat_models.js +25 -27
- package/dist/utils/openai.cjs +5 -2
- package/dist/utils/openai.d.ts +2 -13
- package/dist/utils/openai.js +5 -2
- package/dist/utils/tools.cjs +2 -24
- package/dist/utils/tools.js +3 -25
- package/package.json +1 -1
package/dist/chat_models.cjs
CHANGED
|
@@ -231,34 +231,32 @@ function _convertMessagesToOpenAIResponsesParams(messages, model) {
|
|
|
231
231
|
}
|
|
232
232
|
return input;
|
|
233
233
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return [];
|
|
259
|
-
}),
|
|
260
|
-
};
|
|
234
|
+
const content = typeof lcMsg.content === "string"
|
|
235
|
+
? lcMsg.content
|
|
236
|
+
: lcMsg.content.flatMap((item) => {
|
|
237
|
+
if (item.type === "text") {
|
|
238
|
+
return { type: "input_text", text: item.text };
|
|
239
|
+
}
|
|
240
|
+
if (item.type === "image_url") {
|
|
241
|
+
const image_url = typeof item.image_url === "string"
|
|
242
|
+
? item.image_url
|
|
243
|
+
: item.image_url.url;
|
|
244
|
+
const detail = typeof item.image_url === "string"
|
|
245
|
+
? "auto"
|
|
246
|
+
: item.image_url.detail;
|
|
247
|
+
return { type: "input_image", image_url, detail };
|
|
248
|
+
}
|
|
249
|
+
if (item.type === "input_text" ||
|
|
250
|
+
item.type === "input_image" ||
|
|
251
|
+
item.type === "input_file") {
|
|
252
|
+
return item;
|
|
253
|
+
}
|
|
254
|
+
return [];
|
|
255
|
+
});
|
|
256
|
+
if (role === "user" || role === "system" || role === "developer") {
|
|
257
|
+
return { type: "message", role, content };
|
|
261
258
|
}
|
|
259
|
+
console.warn(`Unsupported role found when converting to OpenAI Responses API: ${role}`);
|
|
262
260
|
return [];
|
|
263
261
|
});
|
|
264
262
|
}
|
package/dist/chat_models.js
CHANGED
|
@@ -226,34 +226,32 @@ function _convertMessagesToOpenAIResponsesParams(messages, model) {
|
|
|
226
226
|
}
|
|
227
227
|
return input;
|
|
228
228
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return [];
|
|
254
|
-
}),
|
|
255
|
-
};
|
|
229
|
+
const content = typeof lcMsg.content === "string"
|
|
230
|
+
? lcMsg.content
|
|
231
|
+
: lcMsg.content.flatMap((item) => {
|
|
232
|
+
if (item.type === "text") {
|
|
233
|
+
return { type: "input_text", text: item.text };
|
|
234
|
+
}
|
|
235
|
+
if (item.type === "image_url") {
|
|
236
|
+
const image_url = typeof item.image_url === "string"
|
|
237
|
+
? item.image_url
|
|
238
|
+
: item.image_url.url;
|
|
239
|
+
const detail = typeof item.image_url === "string"
|
|
240
|
+
? "auto"
|
|
241
|
+
: item.image_url.detail;
|
|
242
|
+
return { type: "input_image", image_url, detail };
|
|
243
|
+
}
|
|
244
|
+
if (item.type === "input_text" ||
|
|
245
|
+
item.type === "input_image" ||
|
|
246
|
+
item.type === "input_file") {
|
|
247
|
+
return item;
|
|
248
|
+
}
|
|
249
|
+
return [];
|
|
250
|
+
});
|
|
251
|
+
if (role === "user" || role === "system" || role === "developer") {
|
|
252
|
+
return { type: "message", role, content };
|
|
256
253
|
}
|
|
254
|
+
console.warn(`Unsupported role found when converting to OpenAI Responses API: ${role}`);
|
|
257
255
|
return [];
|
|
258
256
|
});
|
|
259
257
|
}
|
package/dist/utils/openai.cjs
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatToOpenAIToolChoice = exports.formatToOpenAIAssistantTool = exports.formatToOpenAITool = exports.formatToOpenAIFunction = exports.wrapOpenAIClientError = void 0;
|
|
4
4
|
const openai_1 = require("openai");
|
|
5
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
5
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
7
6
|
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
|
|
8
7
|
Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
|
|
8
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
9
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
9
10
|
const errors_js_1 = require("./errors.cjs");
|
|
10
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
12
|
function wrapOpenAIClientError(e) {
|
|
@@ -42,7 +43,9 @@ function formatToOpenAIAssistantTool(tool) {
|
|
|
42
43
|
function: {
|
|
43
44
|
name: tool.name,
|
|
44
45
|
description: tool.description,
|
|
45
|
-
parameters: (0,
|
|
46
|
+
parameters: (0, types_1.isZodSchema)(tool.schema)
|
|
47
|
+
? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema)
|
|
48
|
+
: tool.schema,
|
|
46
49
|
},
|
|
47
50
|
};
|
|
48
51
|
}
|
package/dist/utils/openai.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
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
|
+
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
4
5
|
export declare function wrapOpenAIClientError(e: any): any;
|
|
5
6
|
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
6
|
-
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface):
|
|
7
|
-
type: string;
|
|
8
|
-
function: {
|
|
9
|
-
name: string;
|
|
10
|
-
description: string;
|
|
11
|
-
parameters: import("zod-to-json-schema").JsonSchema7Type & {
|
|
12
|
-
$schema?: string | undefined;
|
|
13
|
-
definitions?: {
|
|
14
|
-
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
15
|
-
} | undefined;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
};
|
|
7
|
+
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): ToolDefinition;
|
|
19
8
|
export type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | "any" | string;
|
|
20
9
|
export declare function formatToOpenAIToolChoice(toolChoice?: OpenAIToolChoice): OpenAIClient.ChatCompletionToolChoiceOption | undefined;
|
package/dist/utils/openai.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { APIConnectionTimeoutError, APIUserAbortError, } from "openai";
|
|
2
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
2
|
import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
|
|
3
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
4
5
|
import { addLangChainErrorFields } from "./errors.js";
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
7
|
export function wrapOpenAIClientError(e) {
|
|
@@ -37,7 +38,9 @@ export function formatToOpenAIAssistantTool(tool) {
|
|
|
37
38
|
function: {
|
|
38
39
|
name: tool.name,
|
|
39
40
|
description: tool.description,
|
|
40
|
-
parameters:
|
|
41
|
+
parameters: isZodSchema(tool.schema)
|
|
42
|
+
? zodToJsonSchema(tool.schema)
|
|
43
|
+
: tool.schema,
|
|
41
44
|
},
|
|
42
45
|
};
|
|
43
46
|
}
|
package/dist/utils/tools.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._convertToOpenAITool = void 0;
|
|
4
4
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
5
|
-
const
|
|
5
|
+
const openai_js_1 = require("./openai.cjs");
|
|
6
6
|
/**
|
|
7
7
|
* Formats a tool in either OpenAI format, or LangChain structured tool format
|
|
8
8
|
* into an OpenAI tool format. If the tool is already in OpenAI format, return without
|
|
@@ -19,29 +19,7 @@ function _convertToOpenAITool(
|
|
|
19
19
|
tool, fields) {
|
|
20
20
|
let toolDef;
|
|
21
21
|
if ((0, function_calling_1.isLangChainTool)(tool)) {
|
|
22
|
-
|
|
23
|
-
name: tool.name,
|
|
24
|
-
parameters: tool.schema,
|
|
25
|
-
description: tool.description,
|
|
26
|
-
});
|
|
27
|
-
if (!oaiToolDef.function.parameters) {
|
|
28
|
-
// Fallback to the `convertToOpenAIFunction` util if the parameters are not defined.
|
|
29
|
-
toolDef = {
|
|
30
|
-
type: "function",
|
|
31
|
-
function: (0, function_calling_1.convertToOpenAIFunction)(tool, fields),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
toolDef = {
|
|
36
|
-
type: oaiToolDef.type,
|
|
37
|
-
function: {
|
|
38
|
-
name: oaiToolDef.function.name,
|
|
39
|
-
description: oaiToolDef.function.description,
|
|
40
|
-
parameters: oaiToolDef.function.parameters,
|
|
41
|
-
...(fields?.strict !== undefined ? { strict: fields.strict } : {}),
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
22
|
+
toolDef = (0, openai_js_1.formatToOpenAITool)(tool);
|
|
45
23
|
}
|
|
46
24
|
else {
|
|
47
25
|
toolDef = tool;
|
package/dist/utils/tools.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
2
|
+
import { formatToOpenAITool } from "./openai.js";
|
|
3
3
|
/**
|
|
4
4
|
* Formats a tool in either OpenAI format, or LangChain structured tool format
|
|
5
5
|
* into an OpenAI tool format. If the tool is already in OpenAI format, return without
|
|
@@ -16,29 +16,7 @@ export function _convertToOpenAITool(
|
|
|
16
16
|
tool, fields) {
|
|
17
17
|
let toolDef;
|
|
18
18
|
if (isLangChainTool(tool)) {
|
|
19
|
-
|
|
20
|
-
name: tool.name,
|
|
21
|
-
parameters: tool.schema,
|
|
22
|
-
description: tool.description,
|
|
23
|
-
});
|
|
24
|
-
if (!oaiToolDef.function.parameters) {
|
|
25
|
-
// Fallback to the `convertToOpenAIFunction` util if the parameters are not defined.
|
|
26
|
-
toolDef = {
|
|
27
|
-
type: "function",
|
|
28
|
-
function: convertToOpenAIFunction(tool, fields),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
toolDef = {
|
|
33
|
-
type: oaiToolDef.type,
|
|
34
|
-
function: {
|
|
35
|
-
name: oaiToolDef.function.name,
|
|
36
|
-
description: oaiToolDef.function.description,
|
|
37
|
-
parameters: oaiToolDef.function.parameters,
|
|
38
|
-
...(fields?.strict !== undefined ? { strict: fields.strict } : {}),
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
19
|
+
toolDef = formatToOpenAITool(tool);
|
|
42
20
|
}
|
|
43
21
|
else {
|
|
44
22
|
toolDef = tool;
|