langchain 0.3.20 → 0.3.22
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/index.cjs +2 -1
- package/dist/chains/index.d.ts +1 -1
- package/dist/chains/index.js +1 -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/chains/openai_functions/openapi.cjs +2 -1
- package/dist/chains/openai_functions/openapi.d.ts +18 -0
- package/dist/chains/openai_functions/openapi.js +1 -1
- package/dist/document_loaders/fs/buffer.d.ts +1 -0
- 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/sql_db.cjs +1 -1
- package/dist/sql_db.js +1 -1
- 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 +3 -3
|
@@ -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
|
/**
|
package/dist/chains/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOpenAPIChain = exports.createTaggingChainFromZod = exports.createTaggingChain = exports.createExtractionChainFromZod = exports.createExtractionChain = exports.TransformChain = exports.MultiRetrievalQAChain = exports.MultiPromptChain = exports.LLMRouterChain = exports.RouterChain = exports.MultiRouteChain = exports.OpenAIModerationChain = exports.PRINCIPLES = exports.ConstitutionalPrinciple = exports.ConstitutionalChain = exports.RetrievalQAChain = exports.ConversationalRetrievalQAChain = exports.loadSummarizationChain = exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = exports.VectorDBQAChain = exports.AnalyzeDocumentChain = exports.ChatVectorDBQAChain = exports.RefineDocumentsChain = exports.MapReduceDocumentsChain = exports.StuffDocumentsChain = exports.SimpleSequentialChain = exports.SequentialChain = exports.ConversationChain = exports.APIChain = exports.LLMChain = exports.BaseChain = void 0;
|
|
3
|
+
exports.convertOpenAPISpecToOpenAIFunctions = exports.createOpenAPIChain = exports.createTaggingChainFromZod = exports.createTaggingChain = exports.createExtractionChainFromZod = exports.createExtractionChain = exports.TransformChain = exports.MultiRetrievalQAChain = exports.MultiPromptChain = exports.LLMRouterChain = exports.RouterChain = exports.MultiRouteChain = exports.OpenAIModerationChain = exports.PRINCIPLES = exports.ConstitutionalPrinciple = exports.ConstitutionalChain = exports.RetrievalQAChain = exports.ConversationalRetrievalQAChain = exports.loadSummarizationChain = exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = exports.VectorDBQAChain = exports.AnalyzeDocumentChain = exports.ChatVectorDBQAChain = exports.RefineDocumentsChain = exports.MapReduceDocumentsChain = exports.StuffDocumentsChain = exports.SimpleSequentialChain = exports.SequentialChain = exports.ConversationChain = exports.APIChain = exports.LLMChain = exports.BaseChain = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseChain", { enumerable: true, get: function () { return base_js_1.BaseChain; } });
|
|
6
6
|
var llm_chain_js_1 = require("./llm_chain.cjs");
|
|
@@ -59,3 +59,4 @@ Object.defineProperty(exports, "createTaggingChain", { enumerable: true, get: fu
|
|
|
59
59
|
Object.defineProperty(exports, "createTaggingChainFromZod", { enumerable: true, get: function () { return tagging_js_1.createTaggingChainFromZod; } });
|
|
60
60
|
var openapi_js_1 = require("./openai_functions/openapi.cjs");
|
|
61
61
|
Object.defineProperty(exports, "createOpenAPIChain", { enumerable: true, get: function () { return openapi_js_1.createOpenAPIChain; } });
|
|
62
|
+
Object.defineProperty(exports, "convertOpenAPISpecToOpenAIFunctions", { enumerable: true, get: function () { return openapi_js_1.convertOpenAPISpecToOpenAIFunctions; } });
|
package/dist/chains/index.d.ts
CHANGED
|
@@ -22,4 +22,4 @@ export { MultiRetrievalQAChain } from "./router/multi_retrieval_qa.js";
|
|
|
22
22
|
export { TransformChain, type TransformChainFields } from "./transform.js";
|
|
23
23
|
export { createExtractionChain, createExtractionChainFromZod, } from "./openai_functions/extraction.js";
|
|
24
24
|
export { type TaggingChainOptions, createTaggingChain, createTaggingChainFromZod, } from "./openai_functions/tagging.js";
|
|
25
|
-
export { type OpenAPIChainOptions, createOpenAPIChain, } from "./openai_functions/openapi.js";
|
|
25
|
+
export { type OpenAPIChainOptions, createOpenAPIChain, convertOpenAPISpecToOpenAIFunctions, } from "./openai_functions/openapi.js";
|
package/dist/chains/index.js
CHANGED
|
@@ -21,4 +21,4 @@ export { MultiRetrievalQAChain } from "./router/multi_retrieval_qa.js";
|
|
|
21
21
|
export { TransformChain } from "./transform.js";
|
|
22
22
|
export { createExtractionChain, createExtractionChainFromZod, } from "./openai_functions/extraction.js";
|
|
23
23
|
export { createTaggingChain, createTaggingChainFromZod, } from "./openai_functions/tagging.js";
|
|
24
|
-
export { createOpenAPIChain, } from "./openai_functions/openapi.js";
|
|
24
|
+
export { createOpenAPIChain, convertOpenAPISpecToOpenAIFunctions, } from "./openai_functions/openapi.js";
|
|
@@ -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,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOpenAPIChain = exports.convertOpenAPISchemaToJSONSchema = void 0;
|
|
3
|
+
exports.createOpenAPIChain = exports.convertOpenAPISpecToOpenAIFunctions = exports.convertOpenAPISchemaToJSONSchema = void 0;
|
|
4
4
|
const openai_1 = require("@langchain/openai");
|
|
5
5
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
6
|
const openapi_js_1 = require("../../util/openapi.cjs");
|
|
@@ -302,6 +302,7 @@ function convertOpenAPISpecToOpenAIFunctions(spec) {
|
|
|
302
302
|
},
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
|
+
exports.convertOpenAPISpecToOpenAIFunctions = convertOpenAPISpecToOpenAIFunctions;
|
|
305
306
|
/**
|
|
306
307
|
* A chain for making simple API requests.
|
|
307
308
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OpenAIClient } from "@langchain/openai";
|
|
1
2
|
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
2
3
|
import type { OpenAPIV3_1 } from "openapi-types";
|
|
3
4
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
@@ -7,6 +8,13 @@ import { OpenAPISpec } from "../../util/openapi.js";
|
|
|
7
8
|
import { BaseChain } from "../base.js";
|
|
8
9
|
import { LLMChainInput } from "../llm_chain.js";
|
|
9
10
|
import { SequentialChain } from "../sequential_chain.js";
|
|
11
|
+
/**
|
|
12
|
+
* Type representing a function for executing OpenAPI requests.
|
|
13
|
+
*/
|
|
14
|
+
type OpenAPIExecutionMethod = (name: string, requestArgs: Record<string, any>, options?: {
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
params?: Record<string, string>;
|
|
17
|
+
}) => Promise<string>;
|
|
10
18
|
/**
|
|
11
19
|
* Converts OpenAPI schemas to JSON schema format.
|
|
12
20
|
* @param schema The OpenAPI schema to convert.
|
|
@@ -14,6 +22,15 @@ import { SequentialChain } from "../sequential_chain.js";
|
|
|
14
22
|
* @returns The JSON schema representation of the OpenAPI schema.
|
|
15
23
|
*/
|
|
16
24
|
export declare function convertOpenAPISchemaToJSONSchema(schema: OpenAPIV3_1.SchemaObject, spec: OpenAPISpec): JsonSchema7Type;
|
|
25
|
+
/**
|
|
26
|
+
* Converts an OpenAPI specification to OpenAI functions.
|
|
27
|
+
* @param spec The OpenAPI specification to convert.
|
|
28
|
+
* @returns An object containing the OpenAI functions derived from the OpenAPI specification and a default execution method.
|
|
29
|
+
*/
|
|
30
|
+
export declare function convertOpenAPISpecToOpenAIFunctions(spec: OpenAPISpec): {
|
|
31
|
+
openAIFunctions: OpenAIClient.Chat.ChatCompletionCreateParams.Function[];
|
|
32
|
+
defaultExecutionMethod?: OpenAPIExecutionMethod;
|
|
33
|
+
};
|
|
17
34
|
/**
|
|
18
35
|
* Type representing the options for creating an OpenAPI chain.
|
|
19
36
|
*/
|
|
@@ -33,3 +50,4 @@ export type OpenAPIChainOptions = {
|
|
|
33
50
|
* @returns OpenAPIChain
|
|
34
51
|
*/
|
|
35
52
|
export declare function createOpenAPIChain(spec: OpenAPIV3_1.Document | string, options?: OpenAPIChainOptions): Promise<SequentialChain>;
|
|
53
|
+
export {};
|
|
@@ -160,7 +160,7 @@ export function convertOpenAPISchemaToJSONSchema(schema, spec) {
|
|
|
160
160
|
* @param spec The OpenAPI specification to convert.
|
|
161
161
|
* @returns An object containing the OpenAI functions derived from the OpenAPI specification and a default execution method.
|
|
162
162
|
*/
|
|
163
|
-
function convertOpenAPISpecToOpenAIFunctions(spec) {
|
|
163
|
+
export function convertOpenAPISpecToOpenAIFunctions(spec) {
|
|
164
164
|
if (!spec.document.paths) {
|
|
165
165
|
return { openAIFunctions: [] };
|
|
166
166
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
4
|
import type { readFile as ReadFileT } from "node:fs/promises";
|
|
4
5
|
import { Document } from "@langchain/core/documents";
|
|
5
6
|
import { BaseDocumentLoader } from "../base.js";
|
|
@@ -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
|
package/dist/sql_db.cjs
CHANGED
|
@@ -74,7 +74,7 @@ class SqlDatabase extends serializable_1.Serializable {
|
|
|
74
74
|
this.appDataSource = fields.appDataSource;
|
|
75
75
|
this.appDataSourceOptions = fields.appDataSource.options;
|
|
76
76
|
if (fields?.includesTables && fields?.ignoreTables) {
|
|
77
|
-
throw new Error("Cannot specify both
|
|
77
|
+
throw new Error("Cannot specify both includeTables and ignoreTables");
|
|
78
78
|
}
|
|
79
79
|
this.includesTables = fields?.includesTables ?? [];
|
|
80
80
|
this.ignoreTables = fields?.ignoreTables ?? [];
|
package/dist/sql_db.js
CHANGED
|
@@ -71,7 +71,7 @@ export class SqlDatabase extends Serializable {
|
|
|
71
71
|
this.appDataSource = fields.appDataSource;
|
|
72
72
|
this.appDataSourceOptions = fields.appDataSource.options;
|
|
73
73
|
if (fields?.includesTables && fields?.ignoreTables) {
|
|
74
|
-
throw new Error("Cannot specify both
|
|
74
|
+
throw new Error("Cannot specify both includeTables and ignoreTables");
|
|
75
75
|
}
|
|
76
76
|
this.includesTables = fields?.includesTables ?? [];
|
|
77
77
|
this.ignoreTables = fields?.ignoreTables ?? [];
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -458,7 +458,7 @@
|
|
|
458
458
|
"peggy": "^3.0.2",
|
|
459
459
|
"prettier": "^2.8.3",
|
|
460
460
|
"reflect-metadata": "^0.2.2",
|
|
461
|
-
"release-it": "^
|
|
461
|
+
"release-it": "^18.1.2",
|
|
462
462
|
"rimraf": "^5.0.1",
|
|
463
463
|
"rollup": "^3.19.1",
|
|
464
464
|
"ts-jest": "^29.1.0",
|
|
@@ -545,7 +545,7 @@
|
|
|
545
545
|
"js-tiktoken": "^1.0.12",
|
|
546
546
|
"js-yaml": "^4.1.0",
|
|
547
547
|
"jsonpointer": "^5.0.1",
|
|
548
|
-
"langsmith": "
|
|
548
|
+
"langsmith": "^0.3.16",
|
|
549
549
|
"openapi-types": "^12.1.3",
|
|
550
550
|
"p-retry": "4",
|
|
551
551
|
"uuid": "^10.0.0",
|