@langchain/openai 0.2.6 → 0.2.7
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 +412 -0
- package/dist/azure/chat_models.d.ts +412 -0
- package/dist/azure/chat_models.js +412 -0
- package/dist/chat_models.cjs +492 -33
- package/dist/chat_models.d.ts +417 -29
- package/dist/chat_models.js +492 -33
- package/dist/types.d.ts +12 -0
- package/dist/utils/tools.cjs +54 -0
- package/dist/utils/tools.d.ts +20 -0
- package/dist/utils/tools.js +50 -0
- package/package.json +3 -3
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { convertToOpenAIFunction, isLangChainTool, } from "@langchain/core/utils/function_calling";
|
|
2
|
+
import { zodFunction } from "openai/helpers/zod";
|
|
3
|
+
/**
|
|
4
|
+
* Formats a tool in either OpenAI format, or LangChain structured tool format
|
|
5
|
+
* into an OpenAI tool format. If the tool is already in OpenAI format, return without
|
|
6
|
+
* any changes. If it is in LangChain structured tool format, convert it to OpenAI tool format
|
|
7
|
+
* using OpenAI's `zodFunction` util, falling back to `convertToOpenAIFunction` if the parameters
|
|
8
|
+
* returned from the `zodFunction` util are not defined.
|
|
9
|
+
*
|
|
10
|
+
* @param {BindToolsInput} tool The tool to convert to an OpenAI tool.
|
|
11
|
+
* @param {Object} [fields] Additional fields to add to the OpenAI tool.
|
|
12
|
+
* @returns {ToolDefinition} The inputted tool in OpenAI tool format.
|
|
13
|
+
*/
|
|
14
|
+
export function _convertToOpenAITool(
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
tool, fields) {
|
|
17
|
+
let toolDef;
|
|
18
|
+
if (isLangChainTool(tool)) {
|
|
19
|
+
const oaiToolDef = zodFunction({
|
|
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
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
toolDef = tool;
|
|
45
|
+
}
|
|
46
|
+
if (fields?.strict !== undefined) {
|
|
47
|
+
toolDef.function.strict = fields.strict;
|
|
48
|
+
}
|
|
49
|
+
return toolDef;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"author": "LangChain",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@langchain/core": ">=0.2.
|
|
38
|
+
"@langchain/core": ">=0.2.26 <0.3.0",
|
|
39
39
|
"js-tiktoken": "^1.0.12",
|
|
40
40
|
"openai": "^4.55.0",
|
|
41
41
|
"zod": "^3.22.4",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@azure/identity": "^4.2.1",
|
|
46
46
|
"@jest/globals": "^29.5.0",
|
|
47
|
-
"@langchain/scripts": "
|
|
47
|
+
"@langchain/scripts": "^0.0.21",
|
|
48
48
|
"@langchain/standard-tests": "0.0.0",
|
|
49
49
|
"@swc/core": "^1.3.90",
|
|
50
50
|
"@swc/jest": "^0.2.29",
|