langchain 0.3.20 → 0.3.21
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/structured_chat/index.cjs +6 -2
- package/dist/agents/structured_chat/index.js +6 -2
- package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +5 -1
- package/dist/chains/openai_functions/base.cjs +2 -4
- package/dist/chains/openai_functions/base.d.ts +2 -2
- package/dist/chains/openai_functions/base.js +1 -3
- package/dist/experimental/autogpt/prompt_generator.cjs +3 -1
- package/dist/experimental/autogpt/prompt_generator.js +3 -1
- package/dist/experimental/autogpt/schema.d.ts +2 -2
- package/dist/tools/convert_to_openai.cjs +5 -2
- package/dist/tools/convert_to_openai.d.ts +2 -13
- package/dist/tools/convert_to_openai.js +5 -2
- package/dist/tools/render.cjs +6 -2
- package/dist/tools/render.js +6 -2
- package/dist/tools/retriever.d.ts +5 -1
- package/package.json +1 -1
- package/schema/document.cjs +0 -1
- package/schema/document.d.cts +0 -1
- package/schema/document.d.ts +0 -1
- package/schema/document.js +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStructuredChatAgent = exports.StructuredChatAgent = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const base_1 = require("@langchain/core/language_models/base");
|
|
6
5
|
const runnables_1 = require("@langchain/core/runnables");
|
|
7
6
|
const prompts_1 = require("@langchain/core/prompts");
|
|
8
7
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
8
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
9
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
9
10
|
const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
|
|
10
11
|
const agent_js_1 = require("../agent.cjs");
|
|
11
12
|
const outputParser_js_1 = require("./outputParser.cjs");
|
|
@@ -93,7 +94,10 @@ class StructuredChatAgent extends agent_js_1.Agent {
|
|
|
93
94
|
*/
|
|
94
95
|
static createToolSchemasString(tools) {
|
|
95
96
|
return tools
|
|
96
|
-
.map((tool) =>
|
|
97
|
+
.map((tool) => {
|
|
98
|
+
const jsonSchema = ((0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema);
|
|
99
|
+
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
100
|
+
})
|
|
97
101
|
.join("\n");
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
3
2
|
import { RunnablePassthrough } from "@langchain/core/runnables";
|
|
4
3
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, PromptTemplate, } from "@langchain/core/prompts";
|
|
5
4
|
import { isStructuredTool } from "@langchain/core/utils/function_calling";
|
|
5
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
6
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
6
7
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
7
8
|
import { Agent, AgentRunnableSequence, } from "../agent.js";
|
|
8
9
|
import { StructuredChatOutputParserWithRetries } from "./outputParser.js";
|
|
@@ -90,7 +91,10 @@ export class StructuredChatAgent extends Agent {
|
|
|
90
91
|
*/
|
|
91
92
|
static createToolSchemasString(tools) {
|
|
92
93
|
return tools
|
|
93
|
-
.map((tool) =>
|
|
94
|
+
.map((tool) => {
|
|
95
|
+
const jsonSchema = (isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema);
|
|
96
|
+
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
97
|
+
})
|
|
94
98
|
.join("\n");
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStructuredOutputRunnable = exports.createOpenAIFnRunnable = void 0;
|
|
4
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
4
5
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
6
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
6
7
|
/**
|
|
@@ -67,9 +68,6 @@ function createOpenAIFnRunnable(config) {
|
|
|
67
68
|
return prompt.pipe(llmWithKwargs).pipe(outputParser);
|
|
68
69
|
}
|
|
69
70
|
exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
|
|
70
|
-
function isZodSchema(schema) {
|
|
71
|
-
return typeof schema.safeParse === "function";
|
|
72
|
-
}
|
|
73
71
|
/**
|
|
74
72
|
* @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
|
|
75
73
|
*
|
|
@@ -127,7 +125,7 @@ function isZodSchema(schema) {
|
|
|
127
125
|
*/
|
|
128
126
|
function createStructuredOutputRunnable(config) {
|
|
129
127
|
const { outputSchema, llm, prompt, outputParser } = config;
|
|
130
|
-
const jsonSchema = isZodSchema(outputSchema)
|
|
128
|
+
const jsonSchema = (0, types_1.isZodSchema)(outputSchema)
|
|
131
129
|
? (0, zod_to_json_schema_1.zodToJsonSchema)(outputSchema)
|
|
132
130
|
: outputSchema;
|
|
133
131
|
const oaiFunction = {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
2
|
import type { BaseOutputParser } from "@langchain/core/output_parsers";
|
|
4
3
|
import type { BasePromptTemplate } from "@langchain/core/prompts";
|
|
5
4
|
import type { Runnable, RunnableInterface } from "@langchain/core/runnables";
|
|
6
5
|
import type { BaseFunctionCallOptions, BaseLanguageModelInput, FunctionDefinition } from "@langchain/core/language_models/base";
|
|
7
|
-
import type
|
|
6
|
+
import { type InputValues } from "@langchain/core/utils/types";
|
|
8
7
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
8
|
+
import { type JsonSchema7Type } from "zod-to-json-schema";
|
|
9
9
|
/**
|
|
10
10
|
* Configuration params for the createOpenAIFnRunnable method.
|
|
11
11
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
1
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
3
|
import { JsonOutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
3
4
|
/**
|
|
@@ -63,9 +64,6 @@ export function createOpenAIFnRunnable(config) {
|
|
|
63
64
|
const llmWithKwargs = llm.bind(llmKwargs);
|
|
64
65
|
return prompt.pipe(llmWithKwargs).pipe(outputParser);
|
|
65
66
|
}
|
|
66
|
-
function isZodSchema(schema) {
|
|
67
|
-
return typeof schema.safeParse === "function";
|
|
68
|
-
}
|
|
69
67
|
/**
|
|
70
68
|
* @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
|
|
71
69
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPrompt = exports.PromptGenerator = void 0;
|
|
4
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
4
5
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
6
|
const schema_js_1 = require("./schema.cjs");
|
|
6
7
|
/**
|
|
@@ -72,7 +73,8 @@ class PromptGenerator {
|
|
|
72
73
|
}
|
|
73
74
|
_generate_command_string(tool) {
|
|
74
75
|
let output = `"${tool.name}": ${tool.description}`;
|
|
75
|
-
|
|
76
|
+
const jsonSchema = ((0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema);
|
|
77
|
+
output += `, args json schema: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
76
78
|
return output;
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
1
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
3
|
import { FINISH_NAME } from "./schema.js";
|
|
3
4
|
/**
|
|
@@ -69,7 +70,8 @@ export class PromptGenerator {
|
|
|
69
70
|
}
|
|
70
71
|
_generate_command_string(tool) {
|
|
71
72
|
let output = `"${tool.name}": ${tool.description}`;
|
|
72
|
-
|
|
73
|
+
const jsonSchema = (isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema);
|
|
74
|
+
output += `, args json schema: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
73
75
|
return output;
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { StructuredTool } from "@langchain/core/tools";
|
|
1
|
+
import { StructuredTool, ToolInterface } from "@langchain/core/tools";
|
|
2
2
|
/**
|
|
3
3
|
* Type alias for StructuredTool. It is part of the tools module in
|
|
4
4
|
* LangChain, which includes a variety of tools used for different
|
|
5
5
|
* purposes.
|
|
6
6
|
*/
|
|
7
|
-
export type ObjectTool = StructuredTool;
|
|
7
|
+
export type ObjectTool = StructuredTool | ToolInterface;
|
|
8
8
|
export declare const FINISH_NAME = "finish";
|
|
9
9
|
/**
|
|
10
10
|
* Interface that describes an action that can be performed by the AutoGPT
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatToOpenAIAssistantTool = exports.formatToOpenAITool = exports.formatToOpenAIFunction = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
5
|
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
|
|
7
6
|
Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
|
|
7
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
8
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
8
9
|
function formatToOpenAIAssistantTool(tool) {
|
|
9
10
|
return {
|
|
10
11
|
type: "function",
|
|
11
12
|
function: {
|
|
12
13
|
name: tool.name,
|
|
13
14
|
description: tool.description,
|
|
14
|
-
parameters: (0,
|
|
15
|
+
parameters: (0, types_1.isZodSchema)(tool.schema)
|
|
16
|
+
? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema)
|
|
17
|
+
: tool.schema,
|
|
15
18
|
},
|
|
16
19
|
};
|
|
17
20
|
}
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
+
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
1
2
|
import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
2
3
|
import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
3
4
|
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
4
|
-
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface):
|
|
5
|
-
type: string;
|
|
6
|
-
function: {
|
|
7
|
-
name: string;
|
|
8
|
-
description: string;
|
|
9
|
-
parameters: import("zod-to-json-schema").JsonSchema7Type & {
|
|
10
|
-
$schema?: string | undefined;
|
|
11
|
-
definitions?: {
|
|
12
|
-
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
13
|
-
} | undefined;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
5
|
+
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): ToolDefinition;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
|
|
2
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
3
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
4
|
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
4
5
|
export function formatToOpenAIAssistantTool(tool) {
|
|
5
6
|
return {
|
|
@@ -7,7 +8,9 @@ export function formatToOpenAIAssistantTool(tool) {
|
|
|
7
8
|
function: {
|
|
8
9
|
name: tool.name,
|
|
9
10
|
description: tool.description,
|
|
10
|
-
parameters:
|
|
11
|
+
parameters: isZodSchema(tool.schema)
|
|
12
|
+
? zodToJsonSchema(tool.schema)
|
|
13
|
+
: tool.schema,
|
|
11
14
|
},
|
|
12
15
|
};
|
|
13
16
|
}
|
package/dist/tools/render.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
|
|
4
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
4
|
const base_1 = require("@langchain/core/language_models/base");
|
|
5
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
6
7
|
/**
|
|
7
8
|
* Render the tool name and description in plain text.
|
|
8
9
|
*
|
|
@@ -43,7 +44,10 @@ function renderTextDescriptionAndArgs(tools) {
|
|
|
43
44
|
.join("\n");
|
|
44
45
|
}
|
|
45
46
|
return tools
|
|
46
|
-
.map((tool) =>
|
|
47
|
+
.map((tool) => {
|
|
48
|
+
const jsonSchema = ((0, types_1.isZodSchema)(tool.schema) ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema) : tool.schema);
|
|
49
|
+
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
50
|
+
})
|
|
47
51
|
.join("\n");
|
|
48
52
|
}
|
|
49
53
|
exports.renderTextDescriptionAndArgs = renderTextDescriptionAndArgs;
|
package/dist/tools/render.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
2
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
+
import { isZodSchema } from "@langchain/core/utils/types";
|
|
3
4
|
/**
|
|
4
5
|
* Render the tool name and description in plain text.
|
|
5
6
|
*
|
|
@@ -39,6 +40,9 @@ export function renderTextDescriptionAndArgs(tools) {
|
|
|
39
40
|
.join("\n");
|
|
40
41
|
}
|
|
41
42
|
return tools
|
|
42
|
-
.map((tool) =>
|
|
43
|
+
.map((tool) => {
|
|
44
|
+
const jsonSchema = (isZodSchema(tool.schema) ? zodToJsonSchema(tool.schema) : tool.schema);
|
|
45
|
+
return `${tool.name}: ${tool.description}, args: ${JSON.stringify(jsonSchema?.properties)}`;
|
|
46
|
+
})
|
|
43
47
|
.join("\n");
|
|
44
48
|
}
|
package/package.json
CHANGED
package/schema/document.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../dist/schema/document.cjs');
|
package/schema/document.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/schema/document.js'
|
package/schema/document.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/schema/document.js'
|
package/schema/document.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/schema/document.js'
|