langchain 0.3.26 → 0.3.28
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/agents/openai_functions/index.cjs +5 -3
- package/dist/agents/openai_functions/index.js +5 -3
- package/dist/agents/openai_functions/output_parser.cjs +1 -3
- package/dist/agents/openai_functions/output_parser.d.ts +1 -3
- package/dist/agents/openai_functions/output_parser.js +1 -3
- package/dist/agents/openai_tools/index.cjs +5 -3
- package/dist/agents/openai_tools/index.js +5 -3
- package/dist/agents/openai_tools/output_parser.cjs +1 -1
- package/dist/agents/openai_tools/output_parser.d.ts +1 -1
- package/dist/agents/openai_tools/output_parser.js +1 -1
- package/dist/agents/react/index.cjs +1 -2
- package/dist/agents/react/index.js +1 -2
- package/dist/agents/structured_chat/index.cjs +5 -3
- package/dist/agents/structured_chat/index.js +6 -4
- package/dist/agents/xml/index.cjs +1 -1
- package/dist/agents/xml/index.js +1 -1
- package/dist/agents/xml/output_parser.cjs +1 -1
- package/dist/agents/xml/output_parser.d.ts +1 -1
- package/dist/agents/xml/output_parser.js +1 -1
- package/dist/chains/openai_functions/base.cjs +4 -4
- package/dist/chains/openai_functions/base.d.ts +3 -4
- package/dist/chains/openai_functions/base.js +5 -5
- package/dist/chains/openai_functions/extraction.cjs +4 -4
- package/dist/chains/openai_functions/extraction.d.ts +4 -4
- package/dist/chains/openai_functions/extraction.js +4 -4
- package/dist/chains/openai_functions/openapi.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +4 -4
- package/dist/chains/openai_functions/structured_output.d.ts +7 -8
- package/dist/chains/openai_functions/structured_output.js +5 -5
- package/dist/chains/openai_functions/tagging.cjs +2 -2
- package/dist/chains/openai_functions/tagging.d.ts +2 -2
- package/dist/chains/openai_functions/tagging.js +2 -2
- package/dist/chains/query_constructor/index.d.ts +2 -2
- package/dist/chains/sql_db/sql_db_chain.cjs +1 -1
- package/dist/chains/sql_db/sql_db_chain.js +1 -1
- package/dist/chat_models/universal.cjs +4 -3
- package/dist/chat_models/universal.js +4 -3
- package/dist/document_transformers/openai_functions.cjs +2 -2
- package/dist/document_transformers/openai_functions.d.ts +3 -3
- package/dist/document_transformers/openai_functions.js +2 -2
- package/dist/experimental/autogpt/prompt_generator.cjs +2 -2
- package/dist/experimental/autogpt/prompt_generator.js +3 -3
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.cjs +6 -4
- package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.js +6 -4
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/router.d.ts +3 -3
- package/dist/output_parsers/structured.cjs +6 -5
- package/dist/output_parsers/structured.d.ts +9 -8
- package/dist/output_parsers/structured.js +6 -5
- package/dist/tools/convert_to_openai.cjs +3 -3
- package/dist/tools/convert_to_openai.js +4 -4
- package/dist/tools/fs.d.ts +3 -2
- package/dist/tools/render.cjs +4 -2
- package/dist/tools/render.js +5 -3
- package/package.json +3 -4
|
@@ -226,9 +226,11 @@ async function createOpenAIFunctionsAgent({ llm, tools, prompt, streamRunnable,
|
|
|
226
226
|
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
227
227
|
].join("\n"));
|
|
228
228
|
}
|
|
229
|
-
const llmWithTools = llm.
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
const llmWithTools = llm.bindTools
|
|
230
|
+
? llm.bindTools(tools)
|
|
231
|
+
: llm.withConfig({
|
|
232
|
+
functions: tools.map((tool) => (0, function_calling_1.convertToOpenAIFunction)(tool)),
|
|
233
|
+
});
|
|
232
234
|
const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
|
|
233
235
|
runnables_1.RunnablePassthrough.assign({
|
|
234
236
|
agent_scratchpad: (input) => (0, openai_functions_js_1.formatToOpenAIFunctionMessages)(input.steps),
|
|
@@ -221,9 +221,11 @@ export async function createOpenAIFunctionsAgent({ llm, tools, prompt, streamRun
|
|
|
221
221
|
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
222
222
|
].join("\n"));
|
|
223
223
|
}
|
|
224
|
-
const llmWithTools = llm.
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
const llmWithTools = llm.bindTools
|
|
225
|
+
? llm.bindTools(tools)
|
|
226
|
+
: llm.withConfig({
|
|
227
|
+
functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
228
|
+
});
|
|
227
229
|
const agent = AgentRunnableSequence.fromRunnables([
|
|
228
230
|
RunnablePassthrough.assign({
|
|
229
231
|
agent_scratchpad: (input) => formatToOpenAIFunctionMessages(input.steps),
|
|
@@ -17,9 +17,7 @@ const types_js_1 = require("../types.cjs");
|
|
|
17
17
|
* const modelWithFunctions = new ChatOpenAI({
|
|
18
18
|
* modelName: "gpt-4",
|
|
19
19
|
* temperature: 0,
|
|
20
|
-
* }).
|
|
21
|
-
* functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
22
|
-
* });
|
|
20
|
+
* }).bindTools(tools);
|
|
23
21
|
*
|
|
24
22
|
* const runnableAgent = RunnableSequence.from([
|
|
25
23
|
* {
|
|
@@ -21,9 +21,7 @@ export type FunctionsAgentAction = AgentAction & {
|
|
|
21
21
|
* const modelWithFunctions = new ChatOpenAI({
|
|
22
22
|
* modelName: "gpt-4",
|
|
23
23
|
* temperature: 0,
|
|
24
|
-
* }).
|
|
25
|
-
* functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
26
|
-
* });
|
|
24
|
+
* }).bindTools(tools);
|
|
27
25
|
*
|
|
28
26
|
* const runnableAgent = RunnableSequence.from([
|
|
29
27
|
* {
|
|
@@ -14,9 +14,7 @@ import { AgentActionOutputParser } from "../types.js";
|
|
|
14
14
|
* const modelWithFunctions = new ChatOpenAI({
|
|
15
15
|
* modelName: "gpt-4",
|
|
16
16
|
* temperature: 0,
|
|
17
|
-
* }).
|
|
18
|
-
* functions: tools.map((tool) => convertToOpenAIFunction(tool)),
|
|
19
|
-
* });
|
|
17
|
+
* }).bindTools(tools);
|
|
20
18
|
*
|
|
21
19
|
* const runnableAgent = RunnableSequence.from([
|
|
22
20
|
* {
|
|
@@ -70,9 +70,11 @@ async function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnable, }) {
|
|
|
70
70
|
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
71
71
|
].join("\n"));
|
|
72
72
|
}
|
|
73
|
-
const modelWithTools = llm.
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
const modelWithTools = llm.bindTools
|
|
74
|
+
? llm.bindTools(tools)
|
|
75
|
+
: llm.withConfig({
|
|
76
|
+
tools: tools.map((tool) => (0, function_calling_1.convertToOpenAITool)(tool)),
|
|
77
|
+
});
|
|
76
78
|
const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
|
|
77
79
|
runnables_1.RunnablePassthrough.assign({
|
|
78
80
|
agent_scratchpad: (input) => (0, openai_tools_js_1.formatToOpenAIToolMessages)(input.steps),
|
|
@@ -67,9 +67,11 @@ export async function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnabl
|
|
|
67
67
|
`Found ${JSON.stringify(prompt.inputVariables)} instead.`,
|
|
68
68
|
].join("\n"));
|
|
69
69
|
}
|
|
70
|
-
const modelWithTools = llm.
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const modelWithTools = llm.bindTools
|
|
71
|
+
? llm.bindTools(tools)
|
|
72
|
+
: llm.withConfig({
|
|
73
|
+
tools: tools.map((tool) => convertToOpenAITool(tool)),
|
|
74
|
+
});
|
|
73
75
|
const agent = AgentRunnableSequence.fromRunnables([
|
|
74
76
|
RunnablePassthrough.assign({
|
|
75
77
|
agent_scratchpad: (input) => formatToOpenAIToolMessages(input.steps),
|
|
@@ -23,7 +23,7 @@ const types_js_1 = require("../types.cjs");
|
|
|
23
23
|
* new ChatOpenAI({
|
|
24
24
|
* modelName: "gpt-3.5-turbo-1106",
|
|
25
25
|
* temperature: 0,
|
|
26
|
-
* }).
|
|
26
|
+
* }).bindTools(tools),
|
|
27
27
|
* new OpenAIToolsAgentOutputParser(),
|
|
28
28
|
* ]).withConfig({ runName: "OpenAIToolsAgent" });
|
|
29
29
|
*
|
|
@@ -23,7 +23,7 @@ export type { ToolsAgentAction, ToolsAgentStep };
|
|
|
23
23
|
* new ChatOpenAI({
|
|
24
24
|
* modelName: "gpt-3.5-turbo-1106",
|
|
25
25
|
* temperature: 0,
|
|
26
|
-
* }).
|
|
26
|
+
* }).bindTools(tools),
|
|
27
27
|
* new OpenAIToolsAgentOutputParser(),
|
|
28
28
|
* ]).withConfig({ runName: "OpenAIToolsAgent" });
|
|
29
29
|
*
|
|
@@ -20,7 +20,7 @@ import { AgentMultiActionOutputParser } from "../types.js";
|
|
|
20
20
|
* new ChatOpenAI({
|
|
21
21
|
* modelName: "gpt-3.5-turbo-1106",
|
|
22
22
|
* temperature: 0,
|
|
23
|
-
* }).
|
|
23
|
+
* }).bindTools(tools),
|
|
24
24
|
* new OpenAIToolsAgentOutputParser(),
|
|
25
25
|
* ]).withConfig({ runName: "OpenAIToolsAgent" });
|
|
26
26
|
*
|
|
@@ -59,8 +59,7 @@ async function createReactAgent({ llm, tools, prompt, streamRunnable, }) {
|
|
|
59
59
|
tools: (0, render_js_1.renderTextDescription)(tools),
|
|
60
60
|
tool_names: toolNames.join(", "),
|
|
61
61
|
});
|
|
62
|
-
|
|
63
|
-
const llmWithStop = llm.bind({
|
|
62
|
+
const llmWithStop = llm.withConfig({
|
|
64
63
|
stop: ["\nObservation:"],
|
|
65
64
|
});
|
|
66
65
|
const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
|
|
@@ -56,8 +56,7 @@ export async function createReactAgent({ llm, tools, prompt, streamRunnable, })
|
|
|
56
56
|
tools: renderTextDescription(tools),
|
|
57
57
|
tool_names: toolNames.join(", "),
|
|
58
58
|
});
|
|
59
|
-
|
|
60
|
-
const llmWithStop = llm.bind({
|
|
59
|
+
const llmWithStop = llm.withConfig({
|
|
61
60
|
stop: ["\nObservation:"],
|
|
62
61
|
});
|
|
63
62
|
const agent = AgentRunnableSequence.fromRunnables([
|
|
@@ -5,8 +5,8 @@ const base_1 = require("@langchain/core/language_models/base");
|
|
|
5
5
|
const runnables_1 = require("@langchain/core/runnables");
|
|
6
6
|
const prompts_1 = require("@langchain/core/prompts");
|
|
7
7
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
8
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
9
8
|
const types_1 = require("@langchain/core/utils/types");
|
|
9
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
10
10
|
const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
|
|
11
11
|
const agent_js_1 = require("../agent.cjs");
|
|
12
12
|
const outputParser_js_1 = require("./outputParser.cjs");
|
|
@@ -95,7 +95,9 @@ class StructuredChatAgent extends agent_js_1.Agent {
|
|
|
95
95
|
static createToolSchemasString(tools) {
|
|
96
96
|
return tools
|
|
97
97
|
.map((tool) => {
|
|
98
|
-
const jsonSchema = ((0, types_1.
|
|
98
|
+
const jsonSchema = ((0, types_1.isInteropZodSchema)(tool.schema)
|
|
99
|
+
? (0, json_schema_1.toJsonSchema)(tool.schema)
|
|
100
|
+
: tool.schema);
|
|
99
101
|
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
100
102
|
})
|
|
101
103
|
.join("\n");
|
|
@@ -236,7 +238,7 @@ async function createStructuredChatAgent({ llm, tools, prompt, streamRunnable, }
|
|
|
236
238
|
tool_names: toolNames.join(", "),
|
|
237
239
|
});
|
|
238
240
|
// TODO: Add .bind to core runnable interface.
|
|
239
|
-
const llmWithStop = llm.
|
|
241
|
+
const llmWithStop = llm.withConfig({
|
|
240
242
|
stop: ["Observation"],
|
|
241
243
|
});
|
|
242
244
|
const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
|
|
@@ -2,8 +2,8 @@ import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
|
2
2
|
import { RunnablePassthrough } from "@langchain/core/runnables";
|
|
3
3
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, PromptTemplate, } from "@langchain/core/prompts";
|
|
4
4
|
import { isStructuredTool } from "@langchain/core/utils/function_calling";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { isInteropZodSchema } from "@langchain/core/utils/types";
|
|
6
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
7
7
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
8
8
|
import { Agent, AgentRunnableSequence, } from "../agent.js";
|
|
9
9
|
import { StructuredChatOutputParserWithRetries } from "./outputParser.js";
|
|
@@ -92,7 +92,9 @@ export class StructuredChatAgent extends Agent {
|
|
|
92
92
|
static createToolSchemasString(tools) {
|
|
93
93
|
return tools
|
|
94
94
|
.map((tool) => {
|
|
95
|
-
const jsonSchema = (
|
|
95
|
+
const jsonSchema = (isInteropZodSchema(tool.schema)
|
|
96
|
+
? toJsonSchema(tool.schema)
|
|
97
|
+
: tool.schema);
|
|
96
98
|
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
97
99
|
})
|
|
98
100
|
.join("\n");
|
|
@@ -232,7 +234,7 @@ export async function createStructuredChatAgent({ llm, tools, prompt, streamRunn
|
|
|
232
234
|
tool_names: toolNames.join(", "),
|
|
233
235
|
});
|
|
234
236
|
// TODO: Add .bind to core runnable interface.
|
|
235
|
-
const llmWithStop = llm.
|
|
237
|
+
const llmWithStop = llm.withConfig({
|
|
236
238
|
stop: ["Observation"],
|
|
237
239
|
});
|
|
238
240
|
const agent = AgentRunnableSequence.fromRunnables([
|
|
@@ -165,7 +165,7 @@ async function createXmlAgent({ llm, tools, prompt, streamRunnable, }) {
|
|
|
165
165
|
tools: (0, render_js_1.renderTextDescription)(tools),
|
|
166
166
|
});
|
|
167
167
|
// TODO: Add .bind to core runnable interface.
|
|
168
|
-
const llmWithStop = llm.
|
|
168
|
+
const llmWithStop = llm.withConfig({
|
|
169
169
|
stop: ["</tool_input>", "</final_answer>"],
|
|
170
170
|
});
|
|
171
171
|
const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
|
package/dist/agents/xml/index.js
CHANGED
|
@@ -161,7 +161,7 @@ export async function createXmlAgent({ llm, tools, prompt, streamRunnable, }) {
|
|
|
161
161
|
tools: renderTextDescription(tools),
|
|
162
162
|
});
|
|
163
163
|
// TODO: Add .bind to core runnable interface.
|
|
164
|
-
const llmWithStop = llm.
|
|
164
|
+
const llmWithStop = llm.withConfig({
|
|
165
165
|
stop: ["</tool_input>", "</final_answer>"],
|
|
166
166
|
});
|
|
167
167
|
const agent = AgentRunnableSequence.fromRunnables([
|
|
@@ -13,7 +13,7 @@ const types_js_1 = require("../types.cjs");
|
|
|
13
13
|
* const runnableAgent = RunnableSequence.from([
|
|
14
14
|
* ...rest of runnable
|
|
15
15
|
* prompt,
|
|
16
|
-
* new ChatAnthropic({ modelName: "claude-2", temperature: 0 }).
|
|
16
|
+
* new ChatAnthropic({ modelName: "claude-2", temperature: 0 }).withConfig({
|
|
17
17
|
* stop: ["</tool_input>", "</final_answer>"],
|
|
18
18
|
* }),
|
|
19
19
|
* new XMLAgentOutputParser(),
|
|
@@ -10,7 +10,7 @@ import { AgentActionOutputParser } from "../types.js";
|
|
|
10
10
|
* const runnableAgent = RunnableSequence.from([
|
|
11
11
|
* ...rest of runnable
|
|
12
12
|
* prompt,
|
|
13
|
-
* new ChatAnthropic({ modelName: "claude-2", temperature: 0 }).
|
|
13
|
+
* new ChatAnthropic({ modelName: "claude-2", temperature: 0 }).withConfig({
|
|
14
14
|
* stop: ["</tool_input>", "</final_answer>"],
|
|
15
15
|
* }),
|
|
16
16
|
* new XMLAgentOutputParser(),
|
|
@@ -10,7 +10,7 @@ import { AgentActionOutputParser } from "../types.js";
|
|
|
10
10
|
* const runnableAgent = RunnableSequence.from([
|
|
11
11
|
* ...rest of runnable
|
|
12
12
|
* prompt,
|
|
13
|
-
* new ChatAnthropic({ modelName: "claude-2", temperature: 0 }).
|
|
13
|
+
* new ChatAnthropic({ modelName: "claude-2", temperature: 0 }).withConfig({
|
|
14
14
|
* stop: ["</tool_input>", "</final_answer>"],
|
|
15
15
|
* }),
|
|
16
16
|
* new XMLAgentOutputParser(),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStructuredOutputRunnable = exports.createOpenAIFnRunnable = void 0;
|
|
4
4
|
const types_1 = require("@langchain/core/utils/types");
|
|
5
|
-
const
|
|
5
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
6
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
7
7
|
/**
|
|
8
8
|
* Creates a runnable sequence that calls OpenAI functions.
|
|
@@ -64,7 +64,7 @@ function createOpenAIFnRunnable(config) {
|
|
|
64
64
|
name: functions[0].name,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
const llmWithKwargs = llm.
|
|
67
|
+
const llmWithKwargs = llm.withConfig(llmKwargs);
|
|
68
68
|
return prompt.pipe(llmWithKwargs).pipe(outputParser);
|
|
69
69
|
}
|
|
70
70
|
exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
|
|
@@ -125,8 +125,8 @@ exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
|
|
|
125
125
|
*/
|
|
126
126
|
function createStructuredOutputRunnable(config) {
|
|
127
127
|
const { outputSchema, llm, prompt, outputParser } = config;
|
|
128
|
-
const jsonSchema = (0, types_1.
|
|
129
|
-
? (0,
|
|
128
|
+
const jsonSchema = (0, types_1.isInteropZodSchema)(outputSchema)
|
|
129
|
+
? (0, json_schema_1.toJsonSchema)(outputSchema)
|
|
130
130
|
: outputSchema;
|
|
131
131
|
const oaiFunction = {
|
|
132
132
|
name: "outputFormatter",
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
1
|
import type { BaseOutputParser } from "@langchain/core/output_parsers";
|
|
3
2
|
import type { BasePromptTemplate } from "@langchain/core/prompts";
|
|
4
3
|
import type { Runnable, RunnableInterface } from "@langchain/core/runnables";
|
|
5
4
|
import type { BaseFunctionCallOptions, BaseLanguageModelInput, FunctionDefinition } from "@langchain/core/language_models/base";
|
|
6
|
-
import { type InputValues } from "@langchain/core/utils/types";
|
|
5
|
+
import { type InputValues, InteropZodObject } from "@langchain/core/utils/types";
|
|
7
6
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
8
|
-
import { type JsonSchema7Type } from "
|
|
7
|
+
import { type JsonSchema7Type } from "@langchain/core/utils/json_schema";
|
|
9
8
|
/**
|
|
10
9
|
* Configuration params for the createOpenAIFnRunnable method.
|
|
11
10
|
*/
|
|
@@ -85,7 +84,7 @@ export type CreateStructuredOutputRunnableConfig<RunInput extends Record<string,
|
|
|
85
84
|
/**
|
|
86
85
|
* Schema to output. Must be either valid JSONSchema or a Zod schema.
|
|
87
86
|
*/
|
|
88
|
-
outputSchema:
|
|
87
|
+
outputSchema: InteropZodObject | JsonSchema7Type;
|
|
89
88
|
/**
|
|
90
89
|
* Language model to use, assumed to support the OpenAI function-calling API.
|
|
91
90
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isInteropZodSchema, } from "@langchain/core/utils/types";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { JsonOutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a runnable sequence that calls OpenAI functions.
|
|
@@ -61,7 +61,7 @@ export function createOpenAIFnRunnable(config) {
|
|
|
61
61
|
name: functions[0].name,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
const llmWithKwargs = llm.
|
|
64
|
+
const llmWithKwargs = llm.withConfig(llmKwargs);
|
|
65
65
|
return prompt.pipe(llmWithKwargs).pipe(outputParser);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
@@ -121,8 +121,8 @@ export function createOpenAIFnRunnable(config) {
|
|
|
121
121
|
*/
|
|
122
122
|
export function createStructuredOutputRunnable(config) {
|
|
123
123
|
const { outputSchema, llm, prompt, outputParser } = config;
|
|
124
|
-
const jsonSchema =
|
|
125
|
-
?
|
|
124
|
+
const jsonSchema = isInteropZodSchema(outputSchema)
|
|
125
|
+
? toJsonSchema(outputSchema)
|
|
126
126
|
: outputSchema;
|
|
127
127
|
const oaiFunction = {
|
|
128
128
|
name: "outputFormatter",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtractionChainFromZod = exports.createExtractionChain = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const prompts_1 = require("@langchain/core/prompts");
|
|
5
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
6
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
7
7
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
8
8
|
/**
|
|
@@ -60,8 +60,8 @@ function createExtractionChain(schema, llm) {
|
|
|
60
60
|
exports.createExtractionChain = createExtractionChain;
|
|
61
61
|
/**
|
|
62
62
|
* Function that creates an extraction chain from a Zod schema. It
|
|
63
|
-
* converts the Zod schema to a JSON schema using
|
|
64
|
-
*
|
|
63
|
+
* converts the Zod schema to a JSON schema using before creating
|
|
64
|
+
* the extraction chain.
|
|
65
65
|
* @param schema The Zod schema which extracted data should match
|
|
66
66
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
67
67
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
@@ -69,6 +69,6 @@ exports.createExtractionChain = createExtractionChain;
|
|
|
69
69
|
function createExtractionChainFromZod(
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
71
|
schema, llm) {
|
|
72
|
-
return createExtractionChain((0,
|
|
72
|
+
return createExtractionChain((0, json_schema_1.toJsonSchema)(schema), llm);
|
|
73
73
|
}
|
|
74
74
|
exports.createExtractionChainFromZod = createExtractionChainFromZod;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
3
2
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
3
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
4
4
|
import { FunctionParameters } from "../../output_parsers/openai_functions.js";
|
|
5
5
|
import { LLMChain } from "../llm_chain.js";
|
|
6
6
|
/**
|
|
@@ -13,10 +13,10 @@ import { LLMChain } from "../llm_chain.js";
|
|
|
13
13
|
export declare function createExtractionChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
|
|
14
14
|
/**
|
|
15
15
|
* Function that creates an extraction chain from a Zod schema. It
|
|
16
|
-
* converts the Zod schema to a JSON schema using
|
|
17
|
-
*
|
|
16
|
+
* converts the Zod schema to a JSON schema using before creating
|
|
17
|
+
* the extraction chain.
|
|
18
18
|
* @param schema The Zod schema which extracted data should match
|
|
19
19
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
20
20
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
21
21
|
*/
|
|
22
|
-
export declare function createExtractionChainFromZod(schema:
|
|
22
|
+
export declare function createExtractionChainFromZod(schema: InteropZodObject, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { JsonKeyOutputFunctionsParser, } from "../../output_parsers/openai_functions.js";
|
|
4
4
|
import { LLMChain } from "../llm_chain.js";
|
|
5
5
|
/**
|
|
@@ -56,8 +56,8 @@ export function createExtractionChain(schema, llm) {
|
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Function that creates an extraction chain from a Zod schema. It
|
|
59
|
-
* converts the Zod schema to a JSON schema using
|
|
60
|
-
*
|
|
59
|
+
* converts the Zod schema to a JSON schema using before creating
|
|
60
|
+
* the extraction chain.
|
|
61
61
|
* @param schema The Zod schema which extracted data should match
|
|
62
62
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
63
63
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
@@ -65,5 +65,5 @@ export function createExtractionChain(schema, llm) {
|
|
|
65
65
|
export function createExtractionChainFromZod(
|
|
66
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
67
|
schema, llm) {
|
|
68
|
-
return createExtractionChain(
|
|
68
|
+
return createExtractionChain(toJsonSchema(schema), llm);
|
|
69
69
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenAIClient } from "@langchain/openai";
|
|
2
|
-
import { JsonSchema7Type } from "
|
|
2
|
+
import { type JsonSchema7Type } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import type { OpenAPIV3_1 } from "openapi-types";
|
|
4
4
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
5
5
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStructuredOutputChainFromZod = exports.createStructuredOutputChain = exports.FunctionCallStructuredOutputParser = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
5
|
const openai_1 = require("@langchain/openai");
|
|
7
6
|
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
7
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
8
8
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
9
9
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
10
10
|
function isJsonSchema7Type(x) {
|
|
@@ -78,12 +78,12 @@ class FunctionCallStructuredOutputParser extends output_parsers_1.BaseLLMOutputP
|
|
|
78
78
|
return value;
|
|
79
79
|
});
|
|
80
80
|
if (this.zodSchema) {
|
|
81
|
-
const zodParsedResult = this.zodSchema
|
|
81
|
+
const zodParsedResult = await (0, types_1.interopSafeParseAsync)(this.zodSchema, parsedResult);
|
|
82
82
|
if (zodParsedResult.success) {
|
|
83
83
|
return zodParsedResult.data;
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.
|
|
86
|
+
throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, initialResult);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
else if (this.jsonSchemaValidator !== undefined) {
|
|
@@ -142,7 +142,7 @@ exports.createStructuredOutputChain = createStructuredOutputChain;
|
|
|
142
142
|
function createStructuredOutputChainFromZod(zodSchema, input) {
|
|
143
143
|
return createStructuredOutputChain({
|
|
144
144
|
...input,
|
|
145
|
-
outputSchema: (0,
|
|
145
|
+
outputSchema: (0, json_schema_1.toJsonSchema)(zodSchema),
|
|
146
146
|
zodSchema,
|
|
147
147
|
});
|
|
148
148
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
|
-
import { Validator } from "@langchain/core/utils/json_schema";
|
|
1
|
+
import { type JsonSchema7Type, Validator } from "@langchain/core/utils/json_schema";
|
|
4
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
3
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
6
4
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
7
5
|
import { ChatGeneration } from "@langchain/core/outputs";
|
|
8
6
|
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
9
7
|
import type { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
8
|
+
import { InferInteropZodOutput, InteropZodObject } from "@langchain/core/utils/types";
|
|
10
9
|
import { LLMChain, type LLMChainInput } from "../llm_chain.js";
|
|
11
10
|
import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
12
11
|
/**
|
|
@@ -15,13 +14,13 @@ import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js"
|
|
|
15
14
|
* 'outputSchema' field representing the JSON schema for the expected
|
|
16
15
|
* output.
|
|
17
16
|
*/
|
|
18
|
-
export type StructuredOutputChainInput<T extends
|
|
17
|
+
export type StructuredOutputChainInput<T extends InteropZodObject = InteropZodObject> = Omit<LLMChainInput, "outputParser" | "llm"> & {
|
|
19
18
|
outputSchema?: JsonSchema7Type;
|
|
20
19
|
prompt: BasePromptTemplate;
|
|
21
20
|
llm?: BaseChatModel<BaseFunctionCallOptions>;
|
|
22
21
|
zodSchema?: T;
|
|
23
22
|
};
|
|
24
|
-
export type FunctionCallStructuredOutputParserFields<T extends
|
|
23
|
+
export type FunctionCallStructuredOutputParserFields<T extends InteropZodObject = InteropZodObject> = {
|
|
25
24
|
jsonSchema?: JsonSchema7Type;
|
|
26
25
|
zodSchema?: T;
|
|
27
26
|
};
|
|
@@ -29,7 +28,7 @@ export type FunctionCallStructuredOutputParserFields<T extends z.AnyZodObject =
|
|
|
29
28
|
* Class that extends the BaseLLMOutputParser class. It provides
|
|
30
29
|
* functionality for parsing the structured output based on a JSON schema.
|
|
31
30
|
*/
|
|
32
|
-
export declare class FunctionCallStructuredOutputParser<T extends
|
|
31
|
+
export declare class FunctionCallStructuredOutputParser<T extends InteropZodObject> extends BaseLLMOutputParser<InferInteropZodOutput<T>> {
|
|
33
32
|
lc_namespace: string[];
|
|
34
33
|
protected functionOutputParser: OutputFunctionsParser;
|
|
35
34
|
protected jsonSchemaValidator?: Validator;
|
|
@@ -55,6 +54,6 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
|
|
|
55
54
|
* as well as an additional required "outputSchema" JSON Schema object.
|
|
56
55
|
* @returns OpenAPIChain
|
|
57
56
|
*/
|
|
58
|
-
export declare function createStructuredOutputChain<T extends
|
|
57
|
+
export declare function createStructuredOutputChain<T extends InteropZodObject = InteropZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
59
58
|
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
60
|
-
export declare function createStructuredOutputChainFromZod<T extends
|
|
59
|
+
export declare function createStructuredOutputChainFromZod<T extends InteropZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Validator } from "@langchain/core/utils/json_schema";
|
|
1
|
+
import { Validator, toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
4
3
|
import { BaseLLMOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
|
|
4
|
+
import { interopSafeParseAsync, } from "@langchain/core/utils/types";
|
|
5
5
|
import { LLMChain } from "../llm_chain.js";
|
|
6
6
|
import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
7
7
|
function isJsonSchema7Type(x) {
|
|
@@ -75,12 +75,12 @@ export class FunctionCallStructuredOutputParser extends BaseLLMOutputParser {
|
|
|
75
75
|
return value;
|
|
76
76
|
});
|
|
77
77
|
if (this.zodSchema) {
|
|
78
|
-
const zodParsedResult = this.zodSchema
|
|
78
|
+
const zodParsedResult = await interopSafeParseAsync(this.zodSchema, parsedResult);
|
|
79
79
|
if (zodParsedResult.success) {
|
|
80
80
|
return zodParsedResult.data;
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
throw new OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.
|
|
83
|
+
throw new OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, initialResult);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
else if (this.jsonSchemaValidator !== undefined) {
|
|
@@ -137,7 +137,7 @@ export function createStructuredOutputChain(input) {
|
|
|
137
137
|
export function createStructuredOutputChainFromZod(zodSchema, input) {
|
|
138
138
|
return createStructuredOutputChain({
|
|
139
139
|
...input,
|
|
140
|
-
outputSchema:
|
|
140
|
+
outputSchema: toJsonSchema(zodSchema),
|
|
141
141
|
zodSchema,
|
|
142
142
|
});
|
|
143
143
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTaggingChainFromZod = exports.createTaggingChain = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const prompts_1 = require("@langchain/core/prompts");
|
|
5
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
6
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
7
7
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
8
8
|
/**
|
|
@@ -68,6 +68,6 @@ exports.createTaggingChain = createTaggingChain;
|
|
|
68
68
|
function createTaggingChainFromZod(
|
|
69
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
70
|
schema, llm, options) {
|
|
71
|
-
return createTaggingChain((0,
|
|
71
|
+
return createTaggingChain((0, json_schema_1.toJsonSchema)(schema), llm, options);
|
|
72
72
|
}
|
|
73
73
|
exports.createTaggingChainFromZod = createTaggingChainFromZod;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
3
2
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
4
3
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
5
5
|
import { FunctionParameters } from "../../output_parsers/openai_functions.js";
|
|
6
6
|
import { LLMChain, LLMChainInput } from "../llm_chain.js";
|
|
7
7
|
/**
|
|
@@ -37,4 +37,4 @@ export declare function createTaggingChain(schema: FunctionParameters, llm: Base
|
|
|
37
37
|
* Switch to expression language: https://js.langchain.com/docs/expression_language/
|
|
38
38
|
* Will be removed in 0.2.0
|
|
39
39
|
*/
|
|
40
|
-
export declare function createTaggingChainFromZod(schema:
|
|
40
|
+
export declare function createTaggingChainFromZod(schema: InteropZodObject, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { JsonOutputFunctionsParser, } from "../../output_parsers/openai_functions.js";
|
|
4
4
|
import { LLMChain } from "../llm_chain.js";
|
|
5
5
|
/**
|
|
@@ -64,5 +64,5 @@ export function createTaggingChain(schema, llm, options = {}) {
|
|
|
64
64
|
export function createTaggingChainFromZod(
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
66
|
schema, llm, options) {
|
|
67
|
-
return createTaggingChain(
|
|
67
|
+
return createTaggingChain(toJsonSchema(schema), llm, options);
|
|
68
68
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
3
|
-
import { InputValues } from "@langchain/core/utils/types";
|
|
3
|
+
import { InferInteropZodOutput, InputValues } from "@langchain/core/utils/types";
|
|
4
4
|
import { QueryTransformer, TraverseType } from "./parser.js";
|
|
5
5
|
import { Comparator, Operator, StructuredQuery } from "./ir.js";
|
|
6
6
|
import { DEFAULT_EXAMPLES, DEFAULT_PREFIX, DEFAULT_SCHEMA, DEFAULT_SUFFIX, EXAMPLE_PROMPT } from "./prompt.js";
|
|
@@ -45,7 +45,7 @@ export declare class StructuredQueryOutputParser extends AsymmetricStructuredOut
|
|
|
45
45
|
* @param filter The filter condition.
|
|
46
46
|
* @returns A Promise that resolves to a StructuredQuery instance.
|
|
47
47
|
*/
|
|
48
|
-
outputProcessor({ query, filter, }:
|
|
48
|
+
outputProcessor({ query, filter, }: InferInteropZodOutput<typeof queryInputSchema>): Promise<StructuredQuery>;
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new StructuredQueryOutputParser instance from the provided
|
|
51
51
|
* components.
|
|
@@ -262,7 +262,7 @@ async function createSqlQueryChain({ llm, db, prompt, k = 5, dialect, }) {
|
|
|
262
262
|
return newInputs;
|
|
263
263
|
},
|
|
264
264
|
promptToUse,
|
|
265
|
-
llm.
|
|
265
|
+
llm.withConfig({ stop: ["\nSQLResult:"] }),
|
|
266
266
|
new output_parsers_1.StringOutputParser(),
|
|
267
267
|
strip,
|
|
268
268
|
]);
|
|
@@ -258,7 +258,7 @@ export async function createSqlQueryChain({ llm, db, prompt, k = 5, dialect, })
|
|
|
258
258
|
return newInputs;
|
|
259
259
|
},
|
|
260
260
|
promptToUse,
|
|
261
|
-
llm.
|
|
261
|
+
llm.withConfig({ stop: ["\nSQLResult:"] }),
|
|
262
262
|
new StringOutputParser(),
|
|
263
263
|
strip,
|
|
264
264
|
]);
|
|
@@ -553,9 +553,10 @@ exports.ConfigurableModel = ConfigurableModel;
|
|
|
553
553
|
* temperature: 0,
|
|
554
554
|
* });
|
|
555
555
|
*
|
|
556
|
-
* const configurableModelWithTools = configurableModel.
|
|
557
|
-
*
|
|
558
|
-
*
|
|
556
|
+
* const configurableModelWithTools = configurableModel.bindTools([
|
|
557
|
+
* getWeatherTool,
|
|
558
|
+
* getPopulationTool,
|
|
559
|
+
* ]);
|
|
559
560
|
*
|
|
560
561
|
* const configurableToolResult = await configurableModelWithTools.invoke(
|
|
561
562
|
* "Which city is hotter today and which is bigger: LA or NY?",
|
|
@@ -548,9 +548,10 @@ export class ConfigurableModel extends BaseChatModel {
|
|
|
548
548
|
* temperature: 0,
|
|
549
549
|
* });
|
|
550
550
|
*
|
|
551
|
-
* const configurableModelWithTools = configurableModel.
|
|
552
|
-
*
|
|
553
|
-
*
|
|
551
|
+
* const configurableModelWithTools = configurableModel.bindTools([
|
|
552
|
+
* getWeatherTool,
|
|
553
|
+
* getPopulationTool,
|
|
554
|
+
* ]);
|
|
554
555
|
*
|
|
555
556
|
* const configurableToolResult = await configurableModelWithTools.invoke(
|
|
556
557
|
* "Which city is hotter today and which is bigger: LA or NY?",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMetadataTaggerFromZod = exports.createMetadataTagger = exports.MetadataTagger = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const documents_1 = require("@langchain/core/documents");
|
|
6
5
|
const openai_1 = require("@langchain/openai");
|
|
6
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
7
7
|
const index_js_1 = require("../chains/openai_functions/index.cjs");
|
|
8
8
|
/**
|
|
9
9
|
* A transformer that tags metadata to a document using a tagging chain.
|
|
@@ -47,6 +47,6 @@ function createMetadataTagger(schema, options) {
|
|
|
47
47
|
}
|
|
48
48
|
exports.createMetadataTagger = createMetadataTagger;
|
|
49
49
|
function createMetadataTaggerFromZod(schema, options) {
|
|
50
|
-
return createMetadataTagger((0,
|
|
50
|
+
return createMetadataTagger((0, json_schema_1.toJsonSchema)(schema), options);
|
|
51
51
|
}
|
|
52
52
|
exports.createMetadataTaggerFromZod = createMetadataTaggerFromZod;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { type JsonSchema7ObjectType } from "zod-to-json-schema";
|
|
3
1
|
import { Document, MappingDocumentTransformer } from "@langchain/core/documents";
|
|
4
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
4
|
+
import { type JsonSchema7ObjectType } from "@langchain/core/utils/json_schema";
|
|
5
5
|
import { BaseChain } from "../chains/base.js";
|
|
6
6
|
import { TaggingChainOptions } from "../chains/openai_functions/index.js";
|
|
7
7
|
/**
|
|
@@ -18,6 +18,6 @@ export declare class MetadataTagger extends MappingDocumentTransformer {
|
|
|
18
18
|
export declare function createMetadataTagger(schema: JsonSchema7ObjectType, options: TaggingChainOptions & {
|
|
19
19
|
llm?: ChatOpenAI;
|
|
20
20
|
}): MetadataTagger;
|
|
21
|
-
export declare function createMetadataTaggerFromZod(schema:
|
|
21
|
+
export declare function createMetadataTaggerFromZod(schema: InteropZodObject, options: TaggingChainOptions & {
|
|
22
22
|
llm?: ChatOpenAI;
|
|
23
23
|
}): MetadataTagger;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { zodToJsonSchema, } from "zod-to-json-schema";
|
|
2
1
|
import { Document, MappingDocumentTransformer, } from "@langchain/core/documents";
|
|
3
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
4
4
|
import { createTaggingChain, } from "../chains/openai_functions/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* A transformer that tags metadata to a document using a tagging chain.
|
|
@@ -42,5 +42,5 @@ export function createMetadataTagger(schema, options) {
|
|
|
42
42
|
return new MetadataTagger({ taggingChain });
|
|
43
43
|
}
|
|
44
44
|
export function createMetadataTaggerFromZod(schema, options) {
|
|
45
|
-
return createMetadataTagger(
|
|
45
|
+
return createMetadataTagger(toJsonSchema(schema), options);
|
|
46
46
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPrompt = exports.PromptGenerator = void 0;
|
|
4
4
|
const types_1 = require("@langchain/core/utils/types");
|
|
5
|
-
const
|
|
5
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
6
|
const schema_js_1 = require("./schema.cjs");
|
|
7
7
|
/**
|
|
8
8
|
* Class that generates prompts for generative agents. It maintains a list
|
|
@@ -73,7 +73,7 @@ class PromptGenerator {
|
|
|
73
73
|
}
|
|
74
74
|
_generate_command_string(tool) {
|
|
75
75
|
let output = `"${tool.name}": ${tool.description}`;
|
|
76
|
-
const jsonSchema = ((0, types_1.
|
|
76
|
+
const jsonSchema = ((0, types_1.isInteropZodSchema)(tool.schema) ? (0, json_schema_1.toJsonSchema)(tool.schema) : tool.schema);
|
|
77
77
|
output += `, args json schema: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
78
78
|
return output;
|
|
79
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isInteropZodSchema } from "@langchain/core/utils/types";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { FINISH_NAME } from "./schema.js";
|
|
4
4
|
/**
|
|
5
5
|
* Class that generates prompts for generative agents. It maintains a list
|
|
@@ -70,7 +70,7 @@ export class PromptGenerator {
|
|
|
70
70
|
}
|
|
71
71
|
_generate_command_string(tool) {
|
|
72
72
|
let output = `"${tool.name}": ${tool.description}`;
|
|
73
|
-
const jsonSchema = (
|
|
73
|
+
const jsonSchema = (isInteropZodSchema(tool.schema) ? toJsonSchema(tool.schema) : tool.schema);
|
|
74
74
|
output += `, args json schema: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
75
75
|
return output;
|
|
76
76
|
}
|
package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.cjs
CHANGED
|
@@ -187,8 +187,9 @@ class ViolationOfExpectationsChain extends base_js_1.BaseChain {
|
|
|
187
187
|
*/
|
|
188
188
|
async predictNextUserMessage(chatHistory, runManager) {
|
|
189
189
|
const messageString = this.getChatHistoryString(chatHistory);
|
|
190
|
-
const llmWithFunctions = this.llm
|
|
191
|
-
|
|
190
|
+
const llmWithFunctions = this.llm
|
|
191
|
+
.bindTools([types_js_1.PREDICT_NEXT_USER_MESSAGE_FUNCTION])
|
|
192
|
+
.withConfig({
|
|
192
193
|
function_call: { name: types_js_1.PREDICT_NEXT_USER_MESSAGE_FUNCTION.name },
|
|
193
194
|
});
|
|
194
195
|
const chain = violation_of_expectations_prompt_js_1.PREDICT_NEXT_USER_MESSAGE_PROMPT.pipe(llmWithFunctions).pipe(this.jsonOutputParser);
|
|
@@ -242,8 +243,9 @@ class ViolationOfExpectationsChain extends base_js_1.BaseChain {
|
|
|
242
243
|
* @throws {Error} If the response from the language model does not contain the expected keys: 'violationExplanation', 'explainedPredictionErrors', and 'accuratePrediction'.
|
|
243
244
|
*/
|
|
244
245
|
async getPredictionViolations({ userPredictions, userResponse, runManager, }) {
|
|
245
|
-
const llmWithFunctions = this.llm
|
|
246
|
-
|
|
246
|
+
const llmWithFunctions = this.llm
|
|
247
|
+
.bindTools([types_js_1.PREDICTION_VIOLATIONS_FUNCTION])
|
|
248
|
+
.withConfig({
|
|
247
249
|
function_call: { name: types_js_1.PREDICTION_VIOLATIONS_FUNCTION.name },
|
|
248
250
|
});
|
|
249
251
|
const chain = violation_of_expectations_prompt_js_1.PREDICTION_VIOLATIONS_PROMPT.pipe(llmWithFunctions).pipe(this.jsonOutputParser);
|
package/dist/experimental/chains/violation_of_expectations/violation_of_expectations_chain.js
CHANGED
|
@@ -184,8 +184,9 @@ export class ViolationOfExpectationsChain extends BaseChain {
|
|
|
184
184
|
*/
|
|
185
185
|
async predictNextUserMessage(chatHistory, runManager) {
|
|
186
186
|
const messageString = this.getChatHistoryString(chatHistory);
|
|
187
|
-
const llmWithFunctions = this.llm
|
|
188
|
-
|
|
187
|
+
const llmWithFunctions = this.llm
|
|
188
|
+
.bindTools([PREDICT_NEXT_USER_MESSAGE_FUNCTION])
|
|
189
|
+
.withConfig({
|
|
189
190
|
function_call: { name: PREDICT_NEXT_USER_MESSAGE_FUNCTION.name },
|
|
190
191
|
});
|
|
191
192
|
const chain = PREDICT_NEXT_USER_MESSAGE_PROMPT.pipe(llmWithFunctions).pipe(this.jsonOutputParser);
|
|
@@ -239,8 +240,9 @@ export class ViolationOfExpectationsChain extends BaseChain {
|
|
|
239
240
|
* @throws {Error} If the response from the language model does not contain the expected keys: 'violationExplanation', 'explainedPredictionErrors', and 'accuratePrediction'.
|
|
240
241
|
*/
|
|
241
242
|
async getPredictionViolations({ userPredictions, userResponse, runManager, }) {
|
|
242
|
-
const llmWithFunctions = this.llm
|
|
243
|
-
|
|
243
|
+
const llmWithFunctions = this.llm
|
|
244
|
+
.bindTools([PREDICTION_VIOLATIONS_FUNCTION])
|
|
245
|
+
.withConfig({
|
|
244
246
|
function_call: { name: PREDICTION_VIOLATIONS_FUNCTION.name },
|
|
245
247
|
});
|
|
246
248
|
const chain = PREDICTION_VIOLATIONS_PROMPT.pipe(llmWithFunctions).pipe(this.jsonOutputParser);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema7ObjectType } from "
|
|
1
|
+
import { type JsonSchema7ObjectType } from "@langchain/core/utils/json_schema";
|
|
2
2
|
import { type Operation as JSONPatchOperation } from "@langchain/core/utils/json_patch";
|
|
3
3
|
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
4
4
|
import { BaseCumulativeTransformOutputParser, type BaseCumulativeTransformOutputParserInput, BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type InferInteropZodOutput, type InteropZodType } from "@langchain/core/utils/types";
|
|
2
2
|
import { JsonMarkdownStructuredOutputParser } from "./structured.js";
|
|
3
3
|
/**
|
|
4
4
|
* Defines the input parameters for the RouterOutputParser class. It can
|
|
@@ -14,7 +14,7 @@ export type RouterOutputParserInput = {
|
|
|
14
14
|
* router in LangChain. The class takes a schema and an optional
|
|
15
15
|
* RouterOutputParserInput object as parameters.
|
|
16
16
|
*/
|
|
17
|
-
export declare class RouterOutputParser<Y extends
|
|
17
|
+
export declare class RouterOutputParser<Y extends InteropZodType> extends JsonMarkdownStructuredOutputParser<Y> {
|
|
18
18
|
defaultDestination: string;
|
|
19
19
|
constructor(schema: Y, options?: RouterOutputParserInput);
|
|
20
20
|
/**
|
|
@@ -26,5 +26,5 @@ export declare class RouterOutputParser<Y extends z.ZodTypeAny> extends JsonMark
|
|
|
26
26
|
* @param text The text to be parsed.
|
|
27
27
|
* @returns The parsed text as a Promise.
|
|
28
28
|
*/
|
|
29
|
-
parse(text: string): Promise<
|
|
29
|
+
parse(text: string): Promise<InferInteropZodOutput<Y>>;
|
|
30
30
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsymmetricStructuredOutputParser = exports.JsonMarkdownStructuredOutputParser = exports.StructuredOutputParser = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
5
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
6
|
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
7
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
7
8
|
class StructuredOutputParser extends output_parsers_1.BaseOutputParser {
|
|
8
9
|
static lc_name() {
|
|
9
10
|
return "StructuredOutputParser";
|
|
@@ -63,7 +64,7 @@ Your output will be parsed and type-checked according to the provided schema ins
|
|
|
63
64
|
|
|
64
65
|
Here is the JSON Schema instance your output must adhere to. Include the enclosing markdown codeblock:
|
|
65
66
|
\`\`\`json
|
|
66
|
-
${JSON.stringify((0,
|
|
67
|
+
${JSON.stringify((0, json_schema_1.toJsonSchema)(this.schema))}
|
|
67
68
|
\`\`\`
|
|
68
69
|
`;
|
|
69
70
|
}
|
|
@@ -77,11 +78,11 @@ ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(this.schema))}
|
|
|
77
78
|
const json = text.includes("```")
|
|
78
79
|
? text.trim().split(/```(?:json)?/)[1]
|
|
79
80
|
: text.trim();
|
|
80
|
-
return await this.schema
|
|
81
|
+
return await (0, types_1.interopParseAsync)(this.schema, JSON.parse(json));
|
|
81
82
|
}
|
|
82
83
|
catch (e) {
|
|
83
84
|
try {
|
|
84
|
-
return await this.schema
|
|
85
|
+
return await (0, types_1.interopParseAsync)(this.schema, JSON.parse(text.trim()));
|
|
85
86
|
}
|
|
86
87
|
catch (e2) {
|
|
87
88
|
throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${text}". Error: ${e2}`, text);
|
|
@@ -103,7 +104,7 @@ class JsonMarkdownStructuredOutputParser extends StructuredOutputParser {
|
|
|
103
104
|
if (interpolationDepth < 1) {
|
|
104
105
|
throw new Error("f string interpolation depth must be at least 1");
|
|
105
106
|
}
|
|
106
|
-
return `Return a markdown code snippet with a JSON object formatted to look like:\n\`\`\`json\n${this._schemaToInstruction((0,
|
|
107
|
+
return `Return a markdown code snippet with a JSON object formatted to look like:\n\`\`\`json\n${this._schemaToInstruction((0, json_schema_1.toJsonSchema)(this.schema))
|
|
107
108
|
.replaceAll("{", "{".repeat(interpolationDepth))
|
|
108
109
|
.replaceAll("}", "}".repeat(interpolationDepth))}\n\`\`\``;
|
|
109
110
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseOutputParser, FormatInstructionsOptions } from "@langchain/core/output_parsers";
|
|
3
|
+
import { type InferInteropZodOutput, type InteropZodType } from "@langchain/core/utils/types";
|
|
3
4
|
export type JsonMarkdownStructuredOutputParserInput = {
|
|
4
5
|
interpolationDepth?: number;
|
|
5
6
|
};
|
|
6
7
|
export interface JsonMarkdownFormatInstructionsOptions extends FormatInstructionsOptions {
|
|
7
8
|
interpolationDepth?: number;
|
|
8
9
|
}
|
|
9
|
-
export declare class StructuredOutputParser<T extends
|
|
10
|
+
export declare class StructuredOutputParser<T extends InteropZodType> extends BaseOutputParser<InferInteropZodOutput<T>> {
|
|
10
11
|
schema: T;
|
|
11
12
|
static lc_name(): string;
|
|
12
13
|
lc_namespace: string[];
|
|
@@ -17,7 +18,7 @@ export declare class StructuredOutputParser<T extends z.ZodTypeAny> extends Base
|
|
|
17
18
|
* @param schema The Zod schema which the output should match
|
|
18
19
|
* @returns A new instance of StructuredOutputParser.
|
|
19
20
|
*/
|
|
20
|
-
static fromZodSchema<T extends
|
|
21
|
+
static fromZodSchema<T extends InteropZodType>(schema: T): StructuredOutputParser<T>;
|
|
21
22
|
/**
|
|
22
23
|
* Creates a new StructuredOutputParser from a set of names and
|
|
23
24
|
* descriptions.
|
|
@@ -45,17 +46,17 @@ export declare class StructuredOutputParser<T extends z.ZodTypeAny> extends Base
|
|
|
45
46
|
* @param text The text to parse
|
|
46
47
|
* @returns The parsed output.
|
|
47
48
|
*/
|
|
48
|
-
parse(text: string): Promise<
|
|
49
|
+
parse(text: string): Promise<InferInteropZodOutput<T>>;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* A specific type of `StructuredOutputParser` that parses JSON data
|
|
52
53
|
* formatted as a markdown code snippet.
|
|
53
54
|
*/
|
|
54
|
-
export declare class JsonMarkdownStructuredOutputParser<T extends
|
|
55
|
+
export declare class JsonMarkdownStructuredOutputParser<T extends InteropZodType> extends StructuredOutputParser<T> {
|
|
55
56
|
static lc_name(): string;
|
|
56
57
|
getFormatInstructions(options?: JsonMarkdownFormatInstructionsOptions): string;
|
|
57
58
|
private _schemaToInstruction;
|
|
58
|
-
static fromZodSchema<T extends
|
|
59
|
+
static fromZodSchema<T extends InteropZodType>(schema: T): JsonMarkdownStructuredOutputParser<T>;
|
|
59
60
|
static fromNamesAndDescriptions<S extends {
|
|
60
61
|
[key: string]: string;
|
|
61
62
|
}>(schemas: S): JsonMarkdownStructuredOutputParser<z.ZodObject<{
|
|
@@ -66,14 +67,14 @@ export declare class JsonMarkdownStructuredOutputParser<T extends z.ZodTypeAny>
|
|
|
66
67
|
[x: string]: string;
|
|
67
68
|
}>>;
|
|
68
69
|
}
|
|
69
|
-
export interface AsymmetricStructuredOutputParserFields<T extends
|
|
70
|
+
export interface AsymmetricStructuredOutputParserFields<T extends InteropZodType> {
|
|
70
71
|
inputSchema: T;
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
* A type of `StructuredOutputParser` that handles asymmetric input and
|
|
74
75
|
* output schemas.
|
|
75
76
|
*/
|
|
76
|
-
export declare abstract class AsymmetricStructuredOutputParser<T extends
|
|
77
|
+
export declare abstract class AsymmetricStructuredOutputParser<T extends InteropZodType, Y = unknown> extends BaseOutputParser<Y> {
|
|
77
78
|
private structuredInputParser;
|
|
78
79
|
constructor({ inputSchema }: AsymmetricStructuredOutputParserFields<T>);
|
|
79
80
|
/**
|
|
@@ -82,7 +83,7 @@ export declare abstract class AsymmetricStructuredOutputParser<T extends z.ZodTy
|
|
|
82
83
|
* @param input The parsed input
|
|
83
84
|
* @returns The processed output.
|
|
84
85
|
*/
|
|
85
|
-
abstract outputProcessor(input:
|
|
86
|
+
abstract outputProcessor(input: InferInteropZodOutput<T>): Promise<Y>;
|
|
86
87
|
parse(text: string): Promise<Y>;
|
|
87
88
|
getFormatInstructions(): string;
|
|
88
89
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { BaseOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
|
|
4
|
+
import { interopParseAsync, } from "@langchain/core/utils/types";
|
|
4
5
|
export class StructuredOutputParser extends BaseOutputParser {
|
|
5
6
|
static lc_name() {
|
|
6
7
|
return "StructuredOutputParser";
|
|
@@ -60,7 +61,7 @@ Your output will be parsed and type-checked according to the provided schema ins
|
|
|
60
61
|
|
|
61
62
|
Here is the JSON Schema instance your output must adhere to. Include the enclosing markdown codeblock:
|
|
62
63
|
\`\`\`json
|
|
63
|
-
${JSON.stringify(
|
|
64
|
+
${JSON.stringify(toJsonSchema(this.schema))}
|
|
64
65
|
\`\`\`
|
|
65
66
|
`;
|
|
66
67
|
}
|
|
@@ -74,11 +75,11 @@ ${JSON.stringify(zodToJsonSchema(this.schema))}
|
|
|
74
75
|
const json = text.includes("```")
|
|
75
76
|
? text.trim().split(/```(?:json)?/)[1]
|
|
76
77
|
: text.trim();
|
|
77
|
-
return await this.schema
|
|
78
|
+
return await interopParseAsync(this.schema, JSON.parse(json));
|
|
78
79
|
}
|
|
79
80
|
catch (e) {
|
|
80
81
|
try {
|
|
81
|
-
return await this.schema
|
|
82
|
+
return await interopParseAsync(this.schema, JSON.parse(text.trim()));
|
|
82
83
|
}
|
|
83
84
|
catch (e2) {
|
|
84
85
|
throw new OutputParserException(`Failed to parse. Text: "${text}". Error: ${e2}`, text);
|
|
@@ -99,7 +100,7 @@ export class JsonMarkdownStructuredOutputParser extends StructuredOutputParser {
|
|
|
99
100
|
if (interpolationDepth < 1) {
|
|
100
101
|
throw new Error("f string interpolation depth must be at least 1");
|
|
101
102
|
}
|
|
102
|
-
return `Return a markdown code snippet with a JSON object formatted to look like:\n\`\`\`json\n${this._schemaToInstruction(
|
|
103
|
+
return `Return a markdown code snippet with a JSON object formatted to look like:\n\`\`\`json\n${this._schemaToInstruction(toJsonSchema(this.schema))
|
|
103
104
|
.replaceAll("{", "{".repeat(interpolationDepth))
|
|
104
105
|
.replaceAll("}", "}".repeat(interpolationDepth))}\n\`\`\``;
|
|
105
106
|
}
|
|
@@ -5,15 +5,15 @@ const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
|
5
5
|
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
|
|
6
6
|
Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
|
|
7
7
|
const types_1 = require("@langchain/core/utils/types");
|
|
8
|
-
const
|
|
8
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
9
9
|
function formatToOpenAIAssistantTool(tool) {
|
|
10
10
|
return {
|
|
11
11
|
type: "function",
|
|
12
12
|
function: {
|
|
13
13
|
name: tool.name,
|
|
14
14
|
description: tool.description,
|
|
15
|
-
parameters: (0, types_1.
|
|
16
|
-
? (0,
|
|
15
|
+
parameters: (0, types_1.isInteropZodSchema)(tool.schema)
|
|
16
|
+
? (0, json_schema_1.toJsonSchema)(tool.schema)
|
|
17
17
|
: tool.schema,
|
|
18
18
|
},
|
|
19
19
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { isInteropZodSchema } from "@langchain/core/utils/types";
|
|
3
|
+
import { toJsonSchema } from "@langchain/core/utils/json_schema";
|
|
4
4
|
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
5
5
|
export function formatToOpenAIAssistantTool(tool) {
|
|
6
6
|
return {
|
|
@@ -8,8 +8,8 @@ export function formatToOpenAIAssistantTool(tool) {
|
|
|
8
8
|
function: {
|
|
9
9
|
name: tool.name,
|
|
10
10
|
description: tool.description,
|
|
11
|
-
parameters:
|
|
12
|
-
?
|
|
11
|
+
parameters: isInteropZodSchema(tool.schema)
|
|
12
|
+
? toJsonSchema(tool.schema)
|
|
13
13
|
: tool.schema,
|
|
14
14
|
},
|
|
15
15
|
};
|
package/dist/tools/fs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { StructuredTool, ToolParams } from "@langchain/core/tools";
|
|
3
|
+
import { InferInteropZodOutput } from "@langchain/core/utils/types";
|
|
3
4
|
import { BaseFileStore } from "../stores/file/base.js";
|
|
4
5
|
/**
|
|
5
6
|
* Interface for parameters required by the ReadFileTool class.
|
|
@@ -24,7 +25,7 @@ export declare class ReadFileTool extends StructuredTool {
|
|
|
24
25
|
description: string;
|
|
25
26
|
store: BaseFileStore;
|
|
26
27
|
constructor({ store }: ReadFileParams);
|
|
27
|
-
_call({ file_path }:
|
|
28
|
+
_call({ file_path }: InferInteropZodOutput<typeof this.schema>): Promise<string>;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
31
|
* Interface for parameters required by the WriteFileTool class.
|
|
@@ -52,6 +53,6 @@ export declare class WriteFileTool extends StructuredTool {
|
|
|
52
53
|
description: string;
|
|
53
54
|
store: BaseFileStore;
|
|
54
55
|
constructor({ store, ...rest }: WriteFileParams);
|
|
55
|
-
_call({ file_path, text }:
|
|
56
|
+
_call({ file_path, text }: InferInteropZodOutput<typeof this.schema>): Promise<string>;
|
|
56
57
|
}
|
|
57
58
|
export {};
|
package/dist/tools/render.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
|
|
4
4
|
const base_1 = require("@langchain/core/language_models/base");
|
|
5
|
-
const
|
|
5
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
6
|
const types_1 = require("@langchain/core/utils/types");
|
|
7
7
|
/**
|
|
8
8
|
* Render the tool name and description in plain text.
|
|
@@ -45,7 +45,9 @@ function renderTextDescriptionAndArgs(tools) {
|
|
|
45
45
|
}
|
|
46
46
|
return tools
|
|
47
47
|
.map((tool) => {
|
|
48
|
-
const jsonSchema = ((0, types_1.
|
|
48
|
+
const jsonSchema = ((0, types_1.isInteropZodSchema)(tool.schema)
|
|
49
|
+
? (0, json_schema_1.toJsonSchema)(tool.schema)
|
|
50
|
+
: tool.schema);
|
|
49
51
|
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
50
52
|
})
|
|
51
53
|
.join("\n");
|
package/dist/tools/render.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
|
+
import { isInteropZodSchema } from "@langchain/core/utils/types";
|
|
4
4
|
/**
|
|
5
5
|
* Render the tool name and description in plain text.
|
|
6
6
|
*
|
|
@@ -41,7 +41,9 @@ export function renderTextDescriptionAndArgs(tools) {
|
|
|
41
41
|
}
|
|
42
42
|
return tools
|
|
43
43
|
.map((tool) => {
|
|
44
|
-
const jsonSchema = (
|
|
44
|
+
const jsonSchema = (isInteropZodSchema(tool.schema)
|
|
45
|
+
? toJsonSchema(tool.schema)
|
|
46
|
+
: tool.schema);
|
|
45
47
|
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
46
48
|
})
|
|
47
49
|
.join("\n");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.28",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -471,7 +471,7 @@
|
|
|
471
471
|
"@langchain/aws": "*",
|
|
472
472
|
"@langchain/cerebras": "*",
|
|
473
473
|
"@langchain/cohere": "*",
|
|
474
|
-
"@langchain/core": ">=0.
|
|
474
|
+
"@langchain/core": ">=0.3.58 <0.4.0",
|
|
475
475
|
"@langchain/deepseek": "*",
|
|
476
476
|
"@langchain/google-genai": "*",
|
|
477
477
|
"@langchain/google-vertexai": "*",
|
|
@@ -550,8 +550,7 @@
|
|
|
550
550
|
"p-retry": "4",
|
|
551
551
|
"uuid": "^10.0.0",
|
|
552
552
|
"yaml": "^2.2.1",
|
|
553
|
-
"zod": "^3.
|
|
554
|
-
"zod-to-json-schema": "^3.22.3"
|
|
553
|
+
"zod": "^3.25.32"
|
|
555
554
|
},
|
|
556
555
|
"publishConfig": {
|
|
557
556
|
"access": "public"
|