@langchain/openai 0.0.24 → 0.0.26
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
CHANGED
|
@@ -817,8 +817,9 @@ class ChatOpenAI extends chat_models_1.BaseChatModel {
|
|
|
817
817
|
functionName = schema.name;
|
|
818
818
|
}
|
|
819
819
|
else {
|
|
820
|
+
functionName = schema.title ?? functionName;
|
|
820
821
|
openAIFunctionDefinition = {
|
|
821
|
-
name:
|
|
822
|
+
name: functionName,
|
|
822
823
|
description: schema.description ?? "",
|
|
823
824
|
parameters: schema,
|
|
824
825
|
};
|
package/dist/chat_models.js
CHANGED
|
@@ -813,8 +813,9 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
813
813
|
functionName = schema.name;
|
|
814
814
|
}
|
|
815
815
|
else {
|
|
816
|
+
functionName = schema.title ?? functionName;
|
|
816
817
|
openAIFunctionDefinition = {
|
|
817
|
-
name:
|
|
818
|
+
name: functionName,
|
|
818
819
|
description: schema.description ?? "",
|
|
819
820
|
parameters: schema,
|
|
820
821
|
};
|
|
@@ -146,6 +146,43 @@ Respond with a JSON object containing three keys:
|
|
|
146
146
|
expect("number1" in result).toBe(true);
|
|
147
147
|
expect("number2" in result).toBe(true);
|
|
148
148
|
});
|
|
149
|
+
test("withStructuredOutput JSON schema", async () => {
|
|
150
|
+
const model = new ChatOpenAI({
|
|
151
|
+
temperature: 0,
|
|
152
|
+
modelName: "gpt-4-turbo-preview",
|
|
153
|
+
});
|
|
154
|
+
const jsonSchema = {
|
|
155
|
+
title: "calculator",
|
|
156
|
+
description: "A simple calculator",
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
operation: {
|
|
160
|
+
type: "string",
|
|
161
|
+
enum: ["add", "subtract", "multiply", "divide"],
|
|
162
|
+
},
|
|
163
|
+
number1: { type: "number" },
|
|
164
|
+
number2: { type: "number" },
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
const modelWithStructuredOutput = model.withStructuredOutput(jsonSchema);
|
|
168
|
+
const prompt = ChatPromptTemplate.fromMessages([
|
|
169
|
+
"system",
|
|
170
|
+
`You are VERY bad at math and must always use a calculator.
|
|
171
|
+
Respond with a JSON object containing three keys:
|
|
172
|
+
'operation': the type of operation to execute, either 'add', 'subtract', 'multiply' or 'divide',
|
|
173
|
+
'number1': the first number to operate on,
|
|
174
|
+
'number2': the second number to operate on.
|
|
175
|
+
`,
|
|
176
|
+
"human",
|
|
177
|
+
"Please help me!! What is 2 + 2?",
|
|
178
|
+
]);
|
|
179
|
+
const chain = prompt.pipe(modelWithStructuredOutput);
|
|
180
|
+
const result = await chain.invoke({});
|
|
181
|
+
console.log(result);
|
|
182
|
+
expect("operation" in result).toBe(true);
|
|
183
|
+
expect("number1" in result).toBe(true);
|
|
184
|
+
expect("number2" in result).toBe(true);
|
|
185
|
+
});
|
|
149
186
|
test("withStructuredOutput includeRaw true", async () => {
|
|
150
187
|
const model = new ChatOpenAI({
|
|
151
188
|
temperature: 0,
|
package/dist/utils/openai.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { type OpenAI as OpenAIClient } from "openai";
|
|
2
1
|
import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
3
2
|
import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
4
3
|
export declare function wrapOpenAIClientError(e: any): any;
|
|
5
4
|
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
6
|
-
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface):
|
|
5
|
+
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): {
|
|
6
|
+
type: string;
|
|
7
|
+
function: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
parameters: import("zod-to-json-schema").JsonSchema7Type & {
|
|
11
|
+
$schema?: string | undefined;
|
|
12
|
+
definitions?: {
|
|
13
|
+
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
14
|
+
} | undefined;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
package/dist/utils/openai.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIConnectionTimeoutError, APIUserAbortError
|
|
1
|
+
import { APIConnectionTimeoutError, APIUserAbortError } from "openai";
|
|
2
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
3
|
import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@langchain/core": "~0.1.45",
|
|
43
43
|
"js-tiktoken": "^1.0.7",
|
|
44
|
-
"openai": "^4.
|
|
44
|
+
"openai": "^4.32.1",
|
|
45
45
|
"zod": "^3.22.4",
|
|
46
46
|
"zod-to-json-schema": "^3.22.3"
|
|
47
47
|
},
|