langchain 0.1.3 → 0.1.5
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/toolkits/conversational_retrieval/tool.cjs +2 -2
- package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js +1 -1
- package/dist/agents/toolkits/openapi/openapi.cjs +2 -2
- package/dist/agents/toolkits/openapi/openapi.js +1 -1
- package/dist/chains/openai_functions/base.d.ts +1 -1
- package/dist/chains/openai_functions/openapi.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -0
- package/dist/chains/openai_functions/structured_output.d.ts +3 -1
- package/dist/chains/openai_functions/structured_output.js +2 -0
- package/dist/chat_models/anthropic.cjs +2 -0
- package/dist/chat_models/anthropic.js +2 -0
- package/dist/document_transformers/openai_functions.d.ts +1 -1
- package/dist/document_transformers/openai_functions.js +1 -1
- package/dist/experimental/chat_models/anthropic_functions.cjs +11 -2
- package/dist/experimental/chat_models/anthropic_functions.d.ts +3 -0
- package/dist/experimental/chat_models/anthropic_functions.js +11 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +2 -1
- package/dist/experimental/plan_and_execute/agent_executor.d.ts +1 -2
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -2
- package/dist/output_parsers/index.cjs +2 -1
- package/dist/output_parsers/index.d.ts +1 -1
- package/dist/output_parsers/index.js +1 -1
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_tools.cjs +86 -8
- package/dist/output_parsers/openai_tools.d.ts +31 -2
- package/dist/output_parsers/openai_tools.js +84 -7
- package/dist/output_parsers/structured.js +1 -1
- package/dist/retrievers/self_query/pinecone.d.ts +2 -2
- package/dist/runnables/remote.cjs +179 -74
- package/dist/runnables/remote.d.ts +3 -0
- package/dist/runnables/remote.js +180 -75
- package/dist/text_splitter.cjs +6 -5
- package/dist/text_splitter.js +6 -5
- package/dist/tools/chain.cjs +3 -2
- package/dist/tools/chain.d.ts +3 -1
- package/dist/tools/chain.js +2 -1
- package/dist/tools/retriever.cjs +2 -2
- package/dist/tools/retriever.d.ts +1 -1
- package/dist/tools/retriever.js +1 -1
- package/dist/util/sql_utils.cjs +16 -9
- package/dist/util/sql_utils.js +16 -9
- package/dist/vectorstores/pinecone.cjs +2 -0
- package/dist/vectorstores/pinecone.js +2 -0
- package/package.json +7 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRetrieverTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
5
|
+
const tools_1 = require("@langchain/core/tools");
|
|
6
6
|
const document_js_1 = require("../../../util/document.cjs");
|
|
7
7
|
/** @deprecated Use "langchain/tools/retriever" instead. */
|
|
8
8
|
function createRetrieverTool(retriever, input) {
|
|
@@ -15,6 +15,6 @@ function createRetrieverTool(retriever, input) {
|
|
|
15
15
|
.string()
|
|
16
16
|
.describe("Natural language query used as input to the retriever"),
|
|
17
17
|
});
|
|
18
|
-
return new
|
|
18
|
+
return new tools_1.DynamicStructuredTool({ ...input, func, schema });
|
|
19
19
|
}
|
|
20
20
|
exports.createRetrieverTool = createRetrieverTool;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseRetrieverInterface } from "@langchain/core/retrievers";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { DynamicStructuredTool, DynamicStructuredToolInput } from "@langchain/
|
|
3
|
+
import { DynamicStructuredTool, DynamicStructuredToolInput } from "@langchain/core/tools";
|
|
4
4
|
/** @deprecated Use "langchain/tools/retriever" instead. */
|
|
5
5
|
export declare function createRetrieverTool(retriever: BaseRetrieverInterface, input: Omit<DynamicStructuredToolInput, "func" | "schema">): DynamicStructuredTool<z.ZodObject<{
|
|
6
6
|
input: z.ZodString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { DynamicStructuredTool, } from "@langchain/
|
|
2
|
+
import { DynamicStructuredTool, } from "@langchain/core/tools";
|
|
3
3
|
import { formatDocumentsAsString } from "../../../util/document.js";
|
|
4
4
|
/** @deprecated Use "langchain/tools/retriever" instead. */
|
|
5
5
|
export function createRetrieverTool(retriever, input) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOpenApiAgent = exports.OpenApiToolkit = exports.RequestsToolkit = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tools_1 = require("@langchain/core/tools");
|
|
5
5
|
const base_1 = require("@langchain/community/agents/toolkits/base");
|
|
6
6
|
const executor_js_1 = require("../../executor.cjs");
|
|
7
7
|
const prompt_js_1 = require("./prompt.cjs");
|
|
@@ -56,7 +56,7 @@ class OpenApiToolkit extends RequestsToolkit {
|
|
|
56
56
|
const jsonAgent = (0, json_js_1.createJsonAgent)(llm, new json_js_1.JsonToolkit(jsonSpec));
|
|
57
57
|
this.tools = [
|
|
58
58
|
...this.tools,
|
|
59
|
-
new
|
|
59
|
+
new tools_1.DynamicTool({
|
|
60
60
|
name: "json_explorer",
|
|
61
61
|
func: async (input) => {
|
|
62
62
|
const result = await jsonAgent.call({ input });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicTool } from "@langchain/
|
|
1
|
+
import { DynamicTool } from "@langchain/core/tools";
|
|
2
2
|
import { Toolkit } from "@langchain/community/agents/toolkits/base";
|
|
3
3
|
import { AgentExecutor } from "../../executor.js";
|
|
4
4
|
import { OPENAPI_PREFIX, OPENAPI_SUFFIX, JSON_EXPLORER_DESCRIPTION, } from "./prompt.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import { JsonSchema7Type } from "zod-to-json-schema
|
|
2
|
+
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
3
|
import type { BaseOutputParser } from "@langchain/core/output_parsers";
|
|
4
4
|
import type { BasePromptTemplate } from "@langchain/core/prompts";
|
|
5
5
|
import type { RunnableInterface } from "@langchain/core/runnables";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema7Type } from "zod-to-json-schema
|
|
1
|
+
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
2
2
|
import type { OpenAPIV3_1 } from "openapi-types";
|
|
3
3
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
4
4
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
@@ -102,6 +102,7 @@ class FunctionCallStructuredOutputParser extends output_parsers_1.BaseLLMOutputP
|
|
|
102
102
|
}
|
|
103
103
|
exports.FunctionCallStructuredOutputParser = FunctionCallStructuredOutputParser;
|
|
104
104
|
/**
|
|
105
|
+
* @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
|
|
105
106
|
* Create a chain that returns output matching a JSON Schema.
|
|
106
107
|
* @param input Object that includes all LLMChainInput fields except "outputParser"
|
|
107
108
|
* as well as an additional required "outputSchema" JSON Schema object.
|
|
@@ -137,6 +138,7 @@ function createStructuredOutputChain(input) {
|
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
exports.createStructuredOutputChain = createStructuredOutputChain;
|
|
141
|
+
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
140
142
|
function createStructuredOutputChainFromZod(zodSchema, input) {
|
|
141
143
|
return createStructuredOutputChain({
|
|
142
144
|
...input,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { JsonSchema7Type } from "zod-to-json-schema
|
|
2
|
+
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
3
|
import { Validator } from "@langchain/core/utils/json_schema";
|
|
4
4
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
5
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
@@ -49,10 +49,12 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
|
|
|
49
49
|
parseResult(generations: ChatGeneration[]): Promise<any>;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
+
* @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
|
|
52
53
|
* Create a chain that returns output matching a JSON Schema.
|
|
53
54
|
* @param input Object that includes all LLMChainInput fields except "outputParser"
|
|
54
55
|
* as well as an additional required "outputSchema" JSON Schema object.
|
|
55
56
|
* @returns OpenAPIChain
|
|
56
57
|
*/
|
|
57
58
|
export declare function createStructuredOutputChain<T extends z.AnyZodObject = z.AnyZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
59
|
+
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
58
60
|
export declare function createStructuredOutputChainFromZod<T extends z.AnyZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
@@ -98,6 +98,7 @@ export class FunctionCallStructuredOutputParser extends BaseLLMOutputParser {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
+
* @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
|
|
101
102
|
* Create a chain that returns output matching a JSON Schema.
|
|
102
103
|
* @param input Object that includes all LLMChainInput fields except "outputParser"
|
|
103
104
|
* as well as an additional required "outputSchema" JSON Schema object.
|
|
@@ -132,6 +133,7 @@ export function createStructuredOutputChain(input) {
|
|
|
132
133
|
...rest,
|
|
133
134
|
});
|
|
134
135
|
}
|
|
136
|
+
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
135
137
|
export function createStructuredOutputChainFromZod(zodSchema, input) {
|
|
136
138
|
return createStructuredOutputChain({
|
|
137
139
|
...input,
|
|
@@ -36,6 +36,8 @@ function getAnthropicPromptFromMessage(message) {
|
|
|
36
36
|
return sdk_1.HUMAN_PROMPT;
|
|
37
37
|
case "system":
|
|
38
38
|
return "";
|
|
39
|
+
case "function":
|
|
40
|
+
return sdk_1.HUMAN_PROMPT;
|
|
39
41
|
case "generic": {
|
|
40
42
|
if (!messages_1.ChatMessage.isInstance(message))
|
|
41
43
|
throw new Error("Invalid generic chat message");
|
|
@@ -32,6 +32,8 @@ function getAnthropicPromptFromMessage(message) {
|
|
|
32
32
|
return HUMAN_PROMPT;
|
|
33
33
|
case "system":
|
|
34
34
|
return "";
|
|
35
|
+
case "function":
|
|
36
|
+
return HUMAN_PROMPT;
|
|
35
37
|
case "generic": {
|
|
36
38
|
if (!ChatMessage.isInstance(message))
|
|
37
39
|
throw new Error("Invalid generic chat message");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type
|
|
2
|
+
import { type JsonSchema7ObjectType } from "zod-to-json-schema";
|
|
3
3
|
import { Document, MappingDocumentTransformer } from "@langchain/core/documents";
|
|
4
4
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
5
|
import { BaseChain } from "../chains/base.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
1
|
+
import { zodToJsonSchema, } from "zod-to-json-schema";
|
|
2
2
|
import { Document, MappingDocumentTransformer, } from "@langchain/core/documents";
|
|
3
3
|
import { ChatOpenAI } from "@langchain/openai";
|
|
4
4
|
import { createTaggingChain, } from "../chains/openai_functions/index.js";
|
|
@@ -10,7 +10,8 @@ const anthropic_js_1 = require("../../chat_models/anthropic.cjs");
|
|
|
10
10
|
const TOOL_SYSTEM_PROMPT =
|
|
11
11
|
/* #__PURE__ */
|
|
12
12
|
prompts_1.PromptTemplate.fromTemplate(`In addition to responding, you can use tools.
|
|
13
|
-
You
|
|
13
|
+
You should use tools as often as you can, as they return the most accurate information possible.
|
|
14
|
+
You have access to the following tools:
|
|
14
15
|
|
|
15
16
|
{tools}
|
|
16
17
|
|
|
@@ -45,6 +46,12 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
45
46
|
writable: true,
|
|
46
47
|
value: void 0
|
|
47
48
|
});
|
|
49
|
+
Object.defineProperty(this, "systemPromptTemplate", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
48
55
|
Object.defineProperty(this, "lc_namespace", {
|
|
49
56
|
enumerable: true,
|
|
50
57
|
configurable: true,
|
|
@@ -52,6 +59,8 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
52
59
|
value: ["langchain", "experimental", "chat_models"]
|
|
53
60
|
});
|
|
54
61
|
this.llm = fields?.llm ?? new anthropic_js_1.ChatAnthropic(fields);
|
|
62
|
+
this.systemPromptTemplate =
|
|
63
|
+
fields?.systemPromptTemplate ?? TOOL_SYSTEM_PROMPT;
|
|
55
64
|
this.stopSequences =
|
|
56
65
|
fields?.stopSequences ?? this.llm.stopSequences;
|
|
57
66
|
}
|
|
@@ -74,7 +83,7 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
74
83
|
options.functions = (options.functions ?? []).concat(options.tools.map(function_calling_1.convertToOpenAIFunction));
|
|
75
84
|
}
|
|
76
85
|
if (options.functions !== undefined && options.functions.length > 0) {
|
|
77
|
-
const content = await
|
|
86
|
+
const content = await this.systemPromptTemplate.format({
|
|
78
87
|
tools: JSON.stringify(options.functions, null, 2),
|
|
79
88
|
});
|
|
80
89
|
const systemMessage = new messages_1.SystemMessage({ content });
|
|
@@ -4,16 +4,19 @@ import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
|
|
|
4
4
|
import { BaseChatModel, BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
5
5
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
6
6
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
7
|
+
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
7
8
|
import { type AnthropicInput } from "../../chat_models/anthropic.js";
|
|
8
9
|
export interface ChatAnthropicFunctionsCallOptions extends BaseFunctionCallOptions {
|
|
9
10
|
tools?: StructuredToolInterface[];
|
|
10
11
|
}
|
|
11
12
|
export type AnthropicFunctionsInput = Partial<AnthropicInput> & BaseChatModelParams & {
|
|
12
13
|
llm?: BaseChatModel;
|
|
14
|
+
systemPromptTemplate?: BasePromptTemplate;
|
|
13
15
|
};
|
|
14
16
|
export declare class AnthropicFunctions extends BaseChatModel<ChatAnthropicFunctionsCallOptions> {
|
|
15
17
|
llm: BaseChatModel;
|
|
16
18
|
stopSequences?: string[];
|
|
19
|
+
systemPromptTemplate: BasePromptTemplate;
|
|
17
20
|
lc_namespace: string[];
|
|
18
21
|
static lc_name(): string;
|
|
19
22
|
constructor(fields?: AnthropicFunctionsInput);
|
|
@@ -7,7 +7,8 @@ import { ChatAnthropic, DEFAULT_STOP_SEQUENCES, } from "../../chat_models/anthro
|
|
|
7
7
|
const TOOL_SYSTEM_PROMPT =
|
|
8
8
|
/* #__PURE__ */
|
|
9
9
|
PromptTemplate.fromTemplate(`In addition to responding, you can use tools.
|
|
10
|
-
You
|
|
10
|
+
You should use tools as often as you can, as they return the most accurate information possible.
|
|
11
|
+
You have access to the following tools:
|
|
11
12
|
|
|
12
13
|
{tools}
|
|
13
14
|
|
|
@@ -42,6 +43,12 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
42
43
|
writable: true,
|
|
43
44
|
value: void 0
|
|
44
45
|
});
|
|
46
|
+
Object.defineProperty(this, "systemPromptTemplate", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
45
52
|
Object.defineProperty(this, "lc_namespace", {
|
|
46
53
|
enumerable: true,
|
|
47
54
|
configurable: true,
|
|
@@ -49,6 +56,8 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
49
56
|
value: ["langchain", "experimental", "chat_models"]
|
|
50
57
|
});
|
|
51
58
|
this.llm = fields?.llm ?? new ChatAnthropic(fields);
|
|
59
|
+
this.systemPromptTemplate =
|
|
60
|
+
fields?.systemPromptTemplate ?? TOOL_SYSTEM_PROMPT;
|
|
52
61
|
this.stopSequences =
|
|
53
62
|
fields?.stopSequences ?? this.llm.stopSequences;
|
|
54
63
|
}
|
|
@@ -71,7 +80,7 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
71
80
|
options.functions = (options.functions ?? []).concat(options.tools.map(convertToOpenAIFunction));
|
|
72
81
|
}
|
|
73
82
|
if (options.functions !== undefined && options.functions.length > 0) {
|
|
74
|
-
const content = await
|
|
83
|
+
const content = await this.systemPromptTemplate.format({
|
|
75
84
|
tools: JSON.stringify(options.functions, null, 2),
|
|
76
85
|
});
|
|
77
86
|
const systemMessage = new SystemMessage({ content });
|
|
@@ -2,6 +2,7 @@ import type { protos } from "@google-ai/generativelanguage";
|
|
|
2
2
|
import type { google } from "@google-ai/generativelanguage/build/protos/protos.js";
|
|
3
3
|
import { GoogleAuthOptions } from "google-auth-library";
|
|
4
4
|
import type { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
5
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
5
6
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
6
7
|
import { AsyncCaller, AsyncCallerCallOptions } from "@langchain/core/utils/async_caller";
|
|
7
8
|
import { GoogleAbstractedClientOpsMethod, GoogleResponse, GoogleVertexAIConnectionParams } from "../../../types/googlevertexai-types.js";
|
|
@@ -118,7 +119,7 @@ export declare class MakerSuitePrompt {
|
|
|
118
119
|
* will have the parameters (model name, temperature, etc) from those in
|
|
119
120
|
* MakerSuite.
|
|
120
121
|
*/
|
|
121
|
-
toChain(): import("@langchain/core/runnables").
|
|
122
|
+
toChain(): Runnable<any, any, import("@langchain/core/runnables").RunnableConfig>;
|
|
122
123
|
}
|
|
123
124
|
interface DriveFileReadParams extends GoogleVertexAIConnectionParams<GoogleAuthOptions> {
|
|
124
125
|
fileId: string;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
2
2
|
import { ChainValues } from "@langchain/core/utils/types";
|
|
3
|
-
import { Tool } from "@langchain/core/tools";
|
|
3
|
+
import { Tool, DynamicStructuredTool } from "@langchain/core/tools";
|
|
4
4
|
import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
|
|
5
|
-
import { DynamicStructuredTool } from "@langchain/community/tools/dynamic";
|
|
6
5
|
import { BaseChain, ChainInputs } from "../../chains/base.js";
|
|
7
6
|
import { BasePlanner, BaseStepContainer, BaseStepExecutor, LLMPlanner, ChainStepExecutor } from "./base.js";
|
|
8
7
|
import { SerializedLLMChain } from "../../chains/serde.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
2
|
-
import { Tool } from "@langchain/core/tools";
|
|
3
|
-
import { DynamicStructuredTool } from "@langchain/community/tools/dynamic";
|
|
2
|
+
import { Tool, DynamicStructuredTool } from "@langchain/core/tools";
|
|
4
3
|
export declare const PLANNER_SYSTEM_PROMPT_MESSAGE_TEMPLATE: string;
|
|
5
4
|
export declare const DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE = "Previous steps: {previous_steps}\n\nCurrent objective: {current_step}\n\n{agent_scratchpad}\n\nYou may extract and combine relevant data from your previous steps when responding to me.";
|
|
6
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatetimeOutputParser = exports.HttpResponseOutputParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
|
|
3
|
+
exports.DatetimeOutputParser = exports.HttpResponseOutputParser = exports.JsonOutputKeyToolsParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
|
|
4
4
|
var list_js_1 = require("./list.cjs");
|
|
5
5
|
Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return list_js_1.ListOutputParser; } });
|
|
6
6
|
Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return list_js_1.CommaSeparatedListOutputParser; } });
|
|
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "JsonOutputFunctionsParser", { enumerable: true,
|
|
|
24
24
|
Object.defineProperty(exports, "JsonKeyOutputFunctionsParser", { enumerable: true, get: function () { return openai_functions_js_1.JsonKeyOutputFunctionsParser; } });
|
|
25
25
|
var openai_tools_js_1 = require("../output_parsers/openai_tools.cjs");
|
|
26
26
|
Object.defineProperty(exports, "JsonOutputToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputToolsParser; } });
|
|
27
|
+
Object.defineProperty(exports, "JsonOutputKeyToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputKeyToolsParser; } });
|
|
27
28
|
var http_response_js_1 = require("./http_response.cjs");
|
|
28
29
|
Object.defineProperty(exports, "HttpResponseOutputParser", { enumerable: true, get: function () { return http_response_js_1.HttpResponseOutputParser; } });
|
|
29
30
|
var datetime_js_1 = require("./datetime.cjs");
|
|
@@ -6,6 +6,6 @@ export { CombiningOutputParser } from "./combining.js";
|
|
|
6
6
|
export { RouterOutputParser, type RouterOutputParserInput } from "./router.js";
|
|
7
7
|
export { CustomListOutputParser } from "./list.js";
|
|
8
8
|
export { type FunctionParameters, OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
|
|
9
|
-
export { type ParsedToolCall, JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
|
|
9
|
+
export { type ParsedToolCall, JsonOutputToolsParser, type JsonOutputToolsParserParams, JsonOutputKeyToolsParser, type JsonOutputKeyToolsParserParams, } from "../output_parsers/openai_tools.js";
|
|
10
10
|
export { HttpResponseOutputParser, type HttpResponseOutputParserInput, } from "./http_response.js";
|
|
11
11
|
export { DatetimeOutputParser } from "./datetime.js";
|
|
@@ -6,6 +6,6 @@ export { CombiningOutputParser } from "./combining.js";
|
|
|
6
6
|
export { RouterOutputParser } from "./router.js";
|
|
7
7
|
export { CustomListOutputParser } from "./list.js";
|
|
8
8
|
export { OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
|
|
9
|
-
export { JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
|
|
9
|
+
export { JsonOutputToolsParser, JsonOutputKeyToolsParser, } from "../output_parsers/openai_tools.js";
|
|
10
10
|
export { HttpResponseOutputParser, } from "./http_response.js";
|
|
11
11
|
export { DatetimeOutputParser } from "./datetime.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema7ObjectType } from "zod-to-json-schema
|
|
1
|
+
import { JsonSchema7ObjectType } from "zod-to-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,14 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonOutputToolsParser = void 0;
|
|
3
|
+
exports.JsonOutputKeyToolsParser = exports.JsonOutputToolsParser = void 0;
|
|
4
4
|
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
5
5
|
/**
|
|
6
|
-
* Class for parsing the output of
|
|
7
|
-
* instance of `OutputToolsParser` to parse the output.
|
|
6
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object.
|
|
8
7
|
*/
|
|
9
8
|
class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
static lc_name() {
|
|
10
|
+
return "JsonOutputToolsParser";
|
|
11
|
+
}
|
|
12
|
+
constructor(fields) {
|
|
13
|
+
super(fields);
|
|
14
|
+
Object.defineProperty(this, "returnId", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: false
|
|
19
|
+
});
|
|
12
20
|
Object.defineProperty(this, "lc_namespace", {
|
|
13
21
|
enumerable: true,
|
|
14
22
|
configurable: true,
|
|
@@ -21,9 +29,7 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
|
21
29
|
writable: true,
|
|
22
30
|
value: true
|
|
23
31
|
});
|
|
24
|
-
|
|
25
|
-
static lc_name() {
|
|
26
|
-
return "JsonOutputToolsParser";
|
|
32
|
+
this.returnId = fields?.returnId ?? this.returnId;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
35
|
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
@@ -45,6 +51,9 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
|
45
51
|
type: toolCall.function.name,
|
|
46
52
|
args: JSON.parse(toolCall.function.arguments),
|
|
47
53
|
};
|
|
54
|
+
if (this.returnId) {
|
|
55
|
+
parsedToolCall.id = toolCall.id;
|
|
56
|
+
}
|
|
48
57
|
// backward-compatibility with previous
|
|
49
58
|
// versions of Langchain JS, which uses `name` and `arguments`
|
|
50
59
|
Object.defineProperty(parsedToolCall, "name", {
|
|
@@ -64,3 +73,72 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
exports.JsonOutputToolsParser = JsonOutputToolsParser;
|
|
76
|
+
/**
|
|
77
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object if you are
|
|
78
|
+
* expecting only a single tool to be called.
|
|
79
|
+
*/
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
class JsonOutputKeyToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
82
|
+
static lc_name() {
|
|
83
|
+
return "JsonOutputKeyToolsParser";
|
|
84
|
+
}
|
|
85
|
+
constructor(params) {
|
|
86
|
+
super(params);
|
|
87
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: true
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(this, "returnId", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: false
|
|
104
|
+
});
|
|
105
|
+
/** The type of tool calls to return. */
|
|
106
|
+
Object.defineProperty(this, "keyName", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
value: void 0
|
|
111
|
+
});
|
|
112
|
+
/** Whether to return only the first tool call. */
|
|
113
|
+
Object.defineProperty(this, "returnSingle", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: false
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "initialParser", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: void 0
|
|
124
|
+
});
|
|
125
|
+
this.keyName = params.keyName;
|
|
126
|
+
this.returnSingle = params.returnSingle ?? this.returnSingle;
|
|
127
|
+
this.initialParser = new JsonOutputToolsParser(params);
|
|
128
|
+
}
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
async parseResult(generations) {
|
|
131
|
+
const results = await this.initialParser.parseResult(generations);
|
|
132
|
+
const matchingResults = results.filter((result) => result.type === this.keyName);
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
let returnedValues = matchingResults;
|
|
135
|
+
if (!this.returnId) {
|
|
136
|
+
returnedValues = matchingResults.map((result) => result.args);
|
|
137
|
+
}
|
|
138
|
+
if (this.returnSingle) {
|
|
139
|
+
return returnedValues[0];
|
|
140
|
+
}
|
|
141
|
+
return returnedValues;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.JsonOutputKeyToolsParser = JsonOutputKeyToolsParser;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
2
2
|
import type { ChatGeneration } from "@langchain/core/outputs";
|
|
3
3
|
export type ParsedToolCall = {
|
|
4
|
+
id?: string;
|
|
4
5
|
type: string;
|
|
5
6
|
args: Record<string, any>;
|
|
6
7
|
/** @deprecated Use `type` instead. Will be removed in 0.2.0. */
|
|
@@ -8,14 +9,19 @@ export type ParsedToolCall = {
|
|
|
8
9
|
/** @deprecated Use `args` instead. Will be removed in 0.2.0. */
|
|
9
10
|
arguments: Record<string, any>;
|
|
10
11
|
};
|
|
12
|
+
export type JsonOutputToolsParserParams = {
|
|
13
|
+
/** Whether to return the tool call id. */
|
|
14
|
+
returnId?: boolean;
|
|
15
|
+
};
|
|
11
16
|
/**
|
|
12
|
-
* Class for parsing the output of
|
|
13
|
-
* instance of `OutputToolsParser` to parse the output.
|
|
17
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object.
|
|
14
18
|
*/
|
|
15
19
|
export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToolCall[]> {
|
|
16
20
|
static lc_name(): string;
|
|
21
|
+
returnId: boolean;
|
|
17
22
|
lc_namespace: string[];
|
|
18
23
|
lc_serializable: boolean;
|
|
24
|
+
constructor(fields?: JsonOutputToolsParserParams);
|
|
19
25
|
/**
|
|
20
26
|
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
21
27
|
* only the arguments of the function call are returned.
|
|
@@ -24,3 +30,26 @@ export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToo
|
|
|
24
30
|
*/
|
|
25
31
|
parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]>;
|
|
26
32
|
}
|
|
33
|
+
export type JsonOutputKeyToolsParserParams = {
|
|
34
|
+
keyName: string;
|
|
35
|
+
returnSingle?: boolean;
|
|
36
|
+
/** Whether to return the tool call id. */
|
|
37
|
+
returnId?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object if you are
|
|
41
|
+
* expecting only a single tool to be called.
|
|
42
|
+
*/
|
|
43
|
+
export declare class JsonOutputKeyToolsParser extends BaseLLMOutputParser<any> {
|
|
44
|
+
static lc_name(): string;
|
|
45
|
+
lc_namespace: string[];
|
|
46
|
+
lc_serializable: boolean;
|
|
47
|
+
returnId: boolean;
|
|
48
|
+
/** The type of tool calls to return. */
|
|
49
|
+
keyName: string;
|
|
50
|
+
/** Whether to return only the first tool call. */
|
|
51
|
+
returnSingle: boolean;
|
|
52
|
+
initialParser: JsonOutputToolsParser;
|
|
53
|
+
constructor(params: JsonOutputKeyToolsParserParams);
|
|
54
|
+
parseResult(generations: ChatGeneration[]): Promise<any>;
|
|
55
|
+
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
2
2
|
/**
|
|
3
|
-
* Class for parsing the output of
|
|
4
|
-
* instance of `OutputToolsParser` to parse the output.
|
|
3
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object.
|
|
5
4
|
*/
|
|
6
5
|
export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
static lc_name() {
|
|
7
|
+
return "JsonOutputToolsParser";
|
|
8
|
+
}
|
|
9
|
+
constructor(fields) {
|
|
10
|
+
super(fields);
|
|
11
|
+
Object.defineProperty(this, "returnId", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: false
|
|
16
|
+
});
|
|
9
17
|
Object.defineProperty(this, "lc_namespace", {
|
|
10
18
|
enumerable: true,
|
|
11
19
|
configurable: true,
|
|
@@ -18,9 +26,7 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
|
18
26
|
writable: true,
|
|
19
27
|
value: true
|
|
20
28
|
});
|
|
21
|
-
|
|
22
|
-
static lc_name() {
|
|
23
|
-
return "JsonOutputToolsParser";
|
|
29
|
+
this.returnId = fields?.returnId ?? this.returnId;
|
|
24
30
|
}
|
|
25
31
|
/**
|
|
26
32
|
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
@@ -42,6 +48,9 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
|
42
48
|
type: toolCall.function.name,
|
|
43
49
|
args: JSON.parse(toolCall.function.arguments),
|
|
44
50
|
};
|
|
51
|
+
if (this.returnId) {
|
|
52
|
+
parsedToolCall.id = toolCall.id;
|
|
53
|
+
}
|
|
45
54
|
// backward-compatibility with previous
|
|
46
55
|
// versions of Langchain JS, which uses `name` and `arguments`
|
|
47
56
|
Object.defineProperty(parsedToolCall, "name", {
|
|
@@ -60,3 +69,71 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
|
60
69
|
return parsedToolCalls;
|
|
61
70
|
}
|
|
62
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object if you are
|
|
74
|
+
* expecting only a single tool to be called.
|
|
75
|
+
*/
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
|
|
78
|
+
static lc_name() {
|
|
79
|
+
return "JsonOutputKeyToolsParser";
|
|
80
|
+
}
|
|
81
|
+
constructor(params) {
|
|
82
|
+
super(params);
|
|
83
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: true
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "returnId", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: false
|
|
100
|
+
});
|
|
101
|
+
/** The type of tool calls to return. */
|
|
102
|
+
Object.defineProperty(this, "keyName", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
});
|
|
108
|
+
/** Whether to return only the first tool call. */
|
|
109
|
+
Object.defineProperty(this, "returnSingle", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: false
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(this, "initialParser", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: void 0
|
|
120
|
+
});
|
|
121
|
+
this.keyName = params.keyName;
|
|
122
|
+
this.returnSingle = params.returnSingle ?? this.returnSingle;
|
|
123
|
+
this.initialParser = new JsonOutputToolsParser(params);
|
|
124
|
+
}
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
async parseResult(generations) {
|
|
127
|
+
const results = await this.initialParser.parseResult(generations);
|
|
128
|
+
const matchingResults = results.filter((result) => result.type === this.keyName);
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
let returnedValues = matchingResults;
|
|
131
|
+
if (!this.returnId) {
|
|
132
|
+
returnedValues = matchingResults.map((result) => result.args);
|
|
133
|
+
}
|
|
134
|
+
if (this.returnSingle) {
|
|
135
|
+
return returnedValues[0];
|
|
136
|
+
}
|
|
137
|
+
return returnedValues;
|
|
138
|
+
}
|
|
139
|
+
}
|