langchain 0.0.172 → 0.0.174
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/agents/openai/output_parser.cjs +1 -0
- package/agents/openai/output_parser.d.ts +1 -0
- package/agents/openai/output_parser.js +1 -0
- package/agents/xml/output_parser.cjs +1 -0
- package/agents/xml/output_parser.d.ts +1 -0
- package/agents/xml/output_parser.js +1 -0
- package/dist/agents/index.cjs +3 -1
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +1 -0
- package/dist/agents/openai/index.cjs +8 -31
- package/dist/agents/openai/index.d.ts +2 -0
- package/dist/agents/openai/index.js +8 -31
- package/dist/agents/openai/output_parser.cjs +65 -0
- package/dist/agents/openai/output_parser.d.ts +22 -0
- package/dist/agents/openai/output_parser.js +61 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js +2 -1
- package/dist/agents/xml/index.cjs +9 -25
- package/dist/agents/xml/index.d.ts +2 -7
- package/dist/agents/xml/index.js +8 -23
- package/dist/agents/xml/output_parser.cjs +44 -0
- package/dist/agents/xml/output_parser.d.ts +14 -0
- package/dist/agents/xml/output_parser.js +40 -0
- package/dist/callbacks/manager.cjs +2 -1
- package/dist/callbacks/manager.js +2 -1
- package/dist/document_loaders/fs/pdf.cjs +2 -1
- package/dist/document_loaders/fs/pdf.js +2 -1
- package/dist/document_loaders/web/pdf.cjs +2 -1
- package/dist/document_loaders/web/pdf.js +2 -1
- package/dist/load/import_map.cjs +5 -2
- package/dist/load/import_map.d.ts +3 -0
- package/dist/load/import_map.js +3 -0
- package/dist/memory/index.cjs +2 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/vector_store.cjs +2 -1
- package/dist/memory/vector_store.js +2 -1
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -18
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +12 -6
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +15 -18
- package/dist/storage/file_system.cjs +31 -11
- package/dist/storage/file_system.js +9 -9
- package/dist/tools/index.cjs +3 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/render.cjs +19 -1
- package/dist/tools/render.d.ts +12 -0
- package/dist/tools/render.js +17 -0
- package/dist/tools/serpapi.d.ts +2 -2
- package/dist/tools/webbrowser.cjs +2 -1
- package/dist/tools/webbrowser.js +2 -1
- package/dist/util/document.cjs +12 -0
- package/dist/util/document.d.ts +9 -0
- package/dist/util/document.js +8 -0
- package/dist/vectorstores/cassandra.cjs +130 -35
- package/dist/vectorstores/cassandra.d.ts +21 -10
- package/dist/vectorstores/cassandra.js +130 -35
- package/dist/vectorstores/pgvector.cjs +13 -7
- package/dist/vectorstores/pgvector.d.ts +7 -0
- package/dist/vectorstores/pgvector.js +13 -7
- package/dist/vectorstores/pinecone.cjs +46 -9
- package/dist/vectorstores/pinecone.d.ts +20 -2
- package/dist/vectorstores/pinecone.js +46 -9
- package/package.json +27 -3
- package/util/document.cjs +1 -0
- package/util/document.d.ts +1 -0
- package/util/document.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/agents/openai/output_parser.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/agents/openai/output_parser.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/agents/openai/output_parser.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/agents/xml/output_parser.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/agents/xml/output_parser.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/agents/xml/output_parser.js'
|
package/dist/agents/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
|
|
3
|
+
exports.XMLAgent = exports.OpenAIAgent = exports.StructuredChatOutputParserWithRetries = exports.StructuredChatOutputParser = exports.StructuredChatAgent = exports.AgentActionOutputParser = exports.ZeroShotAgentOutputParser = exports.ZeroShotAgent = exports.initializeAgentExecutorWithOptions = exports.initializeAgentExecutor = exports.AgentExecutor = exports.ChatConversationalAgentOutputParserWithRetries = exports.ChatConversationalAgentOutputParser = exports.ChatConversationalAgent = exports.ChatAgentOutputParser = exports.ChatAgent = exports.Toolkit = exports.createVectorStoreRouterAgent = exports.createVectorStoreAgent = exports.createOpenApiAgent = exports.createJsonAgent = exports.ZapierToolKit = exports.VectorStoreToolkit = exports.VectorStoreRouterToolkit = exports.RequestsToolkit = exports.OpenApiToolkit = exports.JsonToolkit = exports.LLMSingleActionAgent = exports.BaseSingleActionAgent = exports.Agent = void 0;
|
|
4
4
|
var agent_js_1 = require("./agent.cjs");
|
|
5
5
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_js_1.Agent; } });
|
|
6
6
|
Object.defineProperty(exports, "BaseSingleActionAgent", { enumerable: true, get: function () { return agent_js_1.BaseSingleActionAgent; } });
|
|
@@ -45,3 +45,5 @@ Object.defineProperty(exports, "StructuredChatOutputParser", { enumerable: true,
|
|
|
45
45
|
Object.defineProperty(exports, "StructuredChatOutputParserWithRetries", { enumerable: true, get: function () { return outputParser_js_4.StructuredChatOutputParserWithRetries; } });
|
|
46
46
|
var index_js_6 = require("./openai/index.cjs");
|
|
47
47
|
Object.defineProperty(exports, "OpenAIAgent", { enumerable: true, get: function () { return index_js_6.OpenAIAgent; } });
|
|
48
|
+
var index_js_7 = require("./xml/index.cjs");
|
|
49
|
+
Object.defineProperty(exports, "XMLAgent", { enumerable: true, get: function () { return index_js_7.XMLAgent; } });
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -13,3 +13,4 @@ export { AgentActionOutputParser, type AgentInput, type SerializedAgent, type Se
|
|
|
13
13
|
export { StructuredChatAgent, type StructuredChatAgentInput, type StructuredChatCreatePromptArgs, } from "./structured_chat/index.js";
|
|
14
14
|
export { StructuredChatOutputParser, type StructuredChatOutputParserArgs, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
|
|
15
15
|
export { OpenAIAgent, type OpenAIAgentInput, type OpenAIAgentCreatePromptArgs, } from "./openai/index.js";
|
|
16
|
+
export { XMLAgent, type XMLAgentInput } from "./xml/index.js";
|
package/dist/agents/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { AgentActionOutputParser, } from "./types.js";
|
|
|
13
13
|
export { StructuredChatAgent, } from "./structured_chat/index.js";
|
|
14
14
|
export { StructuredChatOutputParser, StructuredChatOutputParserWithRetries, } from "./structured_chat/outputParser.js";
|
|
15
15
|
export { OpenAIAgent, } from "./openai/index.js";
|
|
16
|
+
export { XMLAgent } from "./xml/index.js";
|
|
@@ -6,36 +6,7 @@ const agent_js_1 = require("../agent.cjs");
|
|
|
6
6
|
const prompt_js_1 = require("./prompt.cjs");
|
|
7
7
|
const chat_js_1 = require("../../prompts/chat.cjs");
|
|
8
8
|
const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
|
|
9
|
-
const output_parser_js_1 = require("
|
|
10
|
-
/**
|
|
11
|
-
* Parses the output message into a FunctionsAgentAction or AgentFinish
|
|
12
|
-
* object.
|
|
13
|
-
* @param message The BaseMessage to parse.
|
|
14
|
-
* @returns A FunctionsAgentAction or AgentFinish object.
|
|
15
|
-
*/
|
|
16
|
-
function parseOutput(message) {
|
|
17
|
-
if (message.additional_kwargs.function_call) {
|
|
18
|
-
// eslint-disable-next-line prefer-destructuring
|
|
19
|
-
const function_call = message.additional_kwargs.function_call;
|
|
20
|
-
try {
|
|
21
|
-
const toolInput = function_call.arguments
|
|
22
|
-
? JSON.parse(function_call.arguments)
|
|
23
|
-
: {};
|
|
24
|
-
return {
|
|
25
|
-
tool: function_call.name,
|
|
26
|
-
toolInput,
|
|
27
|
-
log: `Invoking "${function_call.name}" with ${function_call.arguments ?? "{}"}\n${message.content}`,
|
|
28
|
-
messageLog: [message],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
throw new output_parser_js_1.OutputParserException(`Failed to parse function arguments from chat model response. Text: "${function_call.arguments}". ${error}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return { returnValues: { output: message.content }, log: message.content };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
9
|
+
const output_parser_js_1 = require("./output_parser.cjs");
|
|
39
10
|
/**
|
|
40
11
|
* Checks if the given action is a FunctionsAgentAction.
|
|
41
12
|
* @param action The action to check.
|
|
@@ -91,6 +62,12 @@ class OpenAIAgent extends agent_js_1.Agent {
|
|
|
91
62
|
writable: true,
|
|
92
63
|
value: void 0
|
|
93
64
|
});
|
|
65
|
+
Object.defineProperty(this, "outputParser", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: new output_parser_js_1.OpenAIFunctionsAgentOutputParser()
|
|
70
|
+
});
|
|
94
71
|
this.tools = input.tools;
|
|
95
72
|
}
|
|
96
73
|
/**
|
|
@@ -173,7 +150,7 @@ class OpenAIAgent extends agent_js_1.Agent {
|
|
|
173
150
|
}
|
|
174
151
|
const promptValue = await this.llmChain.prompt.formatPromptValue(valuesForPrompt);
|
|
175
152
|
const message = await llm.predictMessages(promptValue.toChatMessages(), valuesForLLM, callbackManager);
|
|
176
|
-
return
|
|
153
|
+
return this.outputParser.parseAIMessage(message);
|
|
177
154
|
}
|
|
178
155
|
}
|
|
179
156
|
exports.OpenAIAgent = OpenAIAgent;
|
|
@@ -5,6 +5,7 @@ import { StructuredTool } from "../../tools/base.js";
|
|
|
5
5
|
import { Agent, AgentArgs } from "../agent.js";
|
|
6
6
|
import { AgentInput } from "../types.js";
|
|
7
7
|
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
8
|
+
import { OpenAIFunctionsAgentOutputParser } from "./output_parser.js";
|
|
8
9
|
export declare function _formatIntermediateSteps(intermediateSteps: AgentStep[]): BaseMessage[];
|
|
9
10
|
/**
|
|
10
11
|
* Interface for the input data required to create an OpenAIAgent.
|
|
@@ -33,6 +34,7 @@ export declare class OpenAIAgent extends Agent {
|
|
|
33
34
|
llmPrefix(): string;
|
|
34
35
|
_stop(): string[];
|
|
35
36
|
tools: StructuredTool[];
|
|
37
|
+
outputParser: OpenAIFunctionsAgentOutputParser;
|
|
36
38
|
constructor(input: Omit<OpenAIAgentInput, "outputParser">);
|
|
37
39
|
/**
|
|
38
40
|
* Creates a prompt for the OpenAIAgent using the provided tools and
|
|
@@ -3,36 +3,7 @@ import { Agent } from "../agent.js";
|
|
|
3
3
|
import { PREFIX } from "./prompt.js";
|
|
4
4
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
5
5
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
6
|
-
import {
|
|
7
|
-
/**
|
|
8
|
-
* Parses the output message into a FunctionsAgentAction or AgentFinish
|
|
9
|
-
* object.
|
|
10
|
-
* @param message The BaseMessage to parse.
|
|
11
|
-
* @returns A FunctionsAgentAction or AgentFinish object.
|
|
12
|
-
*/
|
|
13
|
-
function parseOutput(message) {
|
|
14
|
-
if (message.additional_kwargs.function_call) {
|
|
15
|
-
// eslint-disable-next-line prefer-destructuring
|
|
16
|
-
const function_call = message.additional_kwargs.function_call;
|
|
17
|
-
try {
|
|
18
|
-
const toolInput = function_call.arguments
|
|
19
|
-
? JSON.parse(function_call.arguments)
|
|
20
|
-
: {};
|
|
21
|
-
return {
|
|
22
|
-
tool: function_call.name,
|
|
23
|
-
toolInput,
|
|
24
|
-
log: `Invoking "${function_call.name}" with ${function_call.arguments ?? "{}"}\n${message.content}`,
|
|
25
|
-
messageLog: [message],
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
throw new OutputParserException(`Failed to parse function arguments from chat model response. Text: "${function_call.arguments}". ${error}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return { returnValues: { output: message.content }, log: message.content };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
6
|
+
import { OpenAIFunctionsAgentOutputParser, } from "./output_parser.js";
|
|
36
7
|
/**
|
|
37
8
|
* Checks if the given action is a FunctionsAgentAction.
|
|
38
9
|
* @param action The action to check.
|
|
@@ -87,6 +58,12 @@ export class OpenAIAgent extends Agent {
|
|
|
87
58
|
writable: true,
|
|
88
59
|
value: void 0
|
|
89
60
|
});
|
|
61
|
+
Object.defineProperty(this, "outputParser", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: new OpenAIFunctionsAgentOutputParser()
|
|
66
|
+
});
|
|
90
67
|
this.tools = input.tools;
|
|
91
68
|
}
|
|
92
69
|
/**
|
|
@@ -169,6 +146,6 @@ export class OpenAIAgent extends Agent {
|
|
|
169
146
|
}
|
|
170
147
|
const promptValue = await this.llmChain.prompt.formatPromptValue(valuesForPrompt);
|
|
171
148
|
const message = await llm.predictMessages(promptValue.toChatMessages(), valuesForLLM, callbackManager);
|
|
172
|
-
return
|
|
149
|
+
return this.outputParser.parseAIMessage(message);
|
|
173
150
|
}
|
|
174
151
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAIFunctionsAgentOutputParser = void 0;
|
|
4
|
+
const index_js_1 = require("../../schema/index.cjs");
|
|
5
|
+
const types_js_1 = require("../types.cjs");
|
|
6
|
+
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
7
|
+
class OpenAIFunctionsAgentOutputParser extends types_js_1.AgentActionOutputParser {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: ["langchain", "agents", "openai"]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
static lc_name() {
|
|
18
|
+
return "OpenAIFunctionsAgentOutputParser";
|
|
19
|
+
}
|
|
20
|
+
async parse(text) {
|
|
21
|
+
throw new Error(`OpenAIFunctionsAgentOutputParser can only parse messages.\nPassed input: ${text}`);
|
|
22
|
+
}
|
|
23
|
+
async parseResult(generations) {
|
|
24
|
+
if ("message" in generations[0] && (0, index_js_1.isBaseMessage)(generations[0].message)) {
|
|
25
|
+
return this.parseAIMessage(generations[0].message);
|
|
26
|
+
}
|
|
27
|
+
throw new Error("parseResult on OpenAIFunctionsAgentOutputParser only works on ChatGeneration output");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parses the output message into a FunctionsAgentAction or AgentFinish
|
|
31
|
+
* object.
|
|
32
|
+
* @param message The BaseMessage to parse.
|
|
33
|
+
* @returns A FunctionsAgentAction or AgentFinish object.
|
|
34
|
+
*/
|
|
35
|
+
parseAIMessage(message) {
|
|
36
|
+
if (message.additional_kwargs.function_call) {
|
|
37
|
+
// eslint-disable-next-line prefer-destructuring
|
|
38
|
+
const function_call = message.additional_kwargs.function_call;
|
|
39
|
+
try {
|
|
40
|
+
const toolInput = function_call.arguments
|
|
41
|
+
? JSON.parse(function_call.arguments)
|
|
42
|
+
: {};
|
|
43
|
+
return {
|
|
44
|
+
tool: function_call.name,
|
|
45
|
+
toolInput,
|
|
46
|
+
log: `Invoking "${function_call.name}" with ${function_call.arguments ?? "{}"}\n${message.content}`,
|
|
47
|
+
messageLog: [message],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new output_parser_js_1.OutputParserException(`Failed to parse function arguments from chat model response. Text: "${function_call.arguments}". ${error}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return {
|
|
56
|
+
returnValues: { output: message.content },
|
|
57
|
+
log: message.content,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getFormatInstructions() {
|
|
62
|
+
throw new Error("getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.OpenAIFunctionsAgentOutputParser = OpenAIFunctionsAgentOutputParser;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AgentAction, AgentFinish, BaseMessage, ChatGeneration } from "../../schema/index.js";
|
|
2
|
+
import { AgentActionOutputParser } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Type that represents an agent action with an optional message log.
|
|
5
|
+
*/
|
|
6
|
+
export type FunctionsAgentAction = AgentAction & {
|
|
7
|
+
messageLog?: BaseMessage[];
|
|
8
|
+
};
|
|
9
|
+
export declare class OpenAIFunctionsAgentOutputParser extends AgentActionOutputParser {
|
|
10
|
+
lc_namespace: string[];
|
|
11
|
+
static lc_name(): string;
|
|
12
|
+
parse(text: string): Promise<AgentAction | AgentFinish>;
|
|
13
|
+
parseResult(generations: ChatGeneration[]): Promise<AgentFinish | FunctionsAgentAction>;
|
|
14
|
+
/**
|
|
15
|
+
* Parses the output message into a FunctionsAgentAction or AgentFinish
|
|
16
|
+
* object.
|
|
17
|
+
* @param message The BaseMessage to parse.
|
|
18
|
+
* @returns A FunctionsAgentAction or AgentFinish object.
|
|
19
|
+
*/
|
|
20
|
+
parseAIMessage(message: BaseMessage): FunctionsAgentAction | AgentFinish;
|
|
21
|
+
getFormatInstructions(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isBaseMessage, } from "../../schema/index.js";
|
|
2
|
+
import { AgentActionOutputParser } from "../types.js";
|
|
3
|
+
import { OutputParserException } from "../../schema/output_parser.js";
|
|
4
|
+
export class OpenAIFunctionsAgentOutputParser extends AgentActionOutputParser {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: ["langchain", "agents", "openai"]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
static lc_name() {
|
|
15
|
+
return "OpenAIFunctionsAgentOutputParser";
|
|
16
|
+
}
|
|
17
|
+
async parse(text) {
|
|
18
|
+
throw new Error(`OpenAIFunctionsAgentOutputParser can only parse messages.\nPassed input: ${text}`);
|
|
19
|
+
}
|
|
20
|
+
async parseResult(generations) {
|
|
21
|
+
if ("message" in generations[0] && isBaseMessage(generations[0].message)) {
|
|
22
|
+
return this.parseAIMessage(generations[0].message);
|
|
23
|
+
}
|
|
24
|
+
throw new Error("parseResult on OpenAIFunctionsAgentOutputParser only works on ChatGeneration output");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses the output message into a FunctionsAgentAction or AgentFinish
|
|
28
|
+
* object.
|
|
29
|
+
* @param message The BaseMessage to parse.
|
|
30
|
+
* @returns A FunctionsAgentAction or AgentFinish object.
|
|
31
|
+
*/
|
|
32
|
+
parseAIMessage(message) {
|
|
33
|
+
if (message.additional_kwargs.function_call) {
|
|
34
|
+
// eslint-disable-next-line prefer-destructuring
|
|
35
|
+
const function_call = message.additional_kwargs.function_call;
|
|
36
|
+
try {
|
|
37
|
+
const toolInput = function_call.arguments
|
|
38
|
+
? JSON.parse(function_call.arguments)
|
|
39
|
+
: {};
|
|
40
|
+
return {
|
|
41
|
+
tool: function_call.name,
|
|
42
|
+
toolInput,
|
|
43
|
+
log: `Invoking "${function_call.name}" with ${function_call.arguments ?? "{}"}\n${message.content}`,
|
|
44
|
+
messageLog: [message],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new OutputParserException(`Failed to parse function arguments from chat model response. Text: "${function_call.arguments}". ${error}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return {
|
|
53
|
+
returnValues: { output: message.content },
|
|
54
|
+
log: message.content,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getFormatInstructions() {
|
|
59
|
+
throw new Error("getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createRetrieverTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const dynamic_js_1 = require("../../../tools/dynamic.cjs");
|
|
6
|
+
const document_js_1 = require("../../../util/document.cjs");
|
|
6
7
|
function createRetrieverTool(retriever, input) {
|
|
7
8
|
const func = async ({ input }, runManager) => {
|
|
8
9
|
const docs = await retriever.getRelevantDocuments(input, runManager?.getChild("retriever"));
|
|
9
|
-
return
|
|
10
|
+
return (0, document_js_1.formatDocumentsAsString)(docs, "\n");
|
|
10
11
|
};
|
|
11
12
|
const schema = zod_1.z.object({
|
|
12
13
|
input: zod_1.z
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { DynamicStructuredTool, } from "../../../tools/dynamic.js";
|
|
3
|
+
import { formatDocumentsAsString } from "../../../util/document.js";
|
|
3
4
|
export function createRetrieverTool(retriever, input) {
|
|
4
5
|
const func = async ({ input }, runManager) => {
|
|
5
6
|
const docs = await retriever.getRelevantDocuments(input, runManager?.getChild("retriever"));
|
|
6
|
-
return docs
|
|
7
|
+
return formatDocumentsAsString(docs, "\n");
|
|
7
8
|
};
|
|
8
9
|
const schema = z.object({
|
|
9
10
|
input: z
|
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XMLAgent =
|
|
3
|
+
exports.XMLAgent = void 0;
|
|
4
4
|
const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
|
|
5
5
|
const chat_js_1 = require("../../prompts/chat.cjs");
|
|
6
6
|
const agent_js_1 = require("../agent.cjs");
|
|
7
|
-
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
8
7
|
const prompt_js_1 = require("./prompt.cjs");
|
|
9
|
-
|
|
10
|
-
* Parses the output text from the agent and returns an AgentAction or
|
|
11
|
-
* AgentFinish object.
|
|
12
|
-
* @param text The output text from the agent.
|
|
13
|
-
* @returns An AgentAction or AgentFinish object.
|
|
14
|
-
*/
|
|
15
|
-
async function parseOutput(text) {
|
|
16
|
-
if (text.includes("</tool>")) {
|
|
17
|
-
const [tool, toolInput] = text.split("</tool>");
|
|
18
|
-
const _tool = tool.split("<tool>")[1];
|
|
19
|
-
const _toolInput = toolInput.split("<tool_input>")[1];
|
|
20
|
-
return { tool: _tool, toolInput: _toolInput, log: text };
|
|
21
|
-
}
|
|
22
|
-
else if (text.includes("<final_answer>")) {
|
|
23
|
-
const [, answer] = text.split("<final_answer>");
|
|
24
|
-
return { returnValues: { output: answer }, log: text };
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
throw new output_parser_js_1.OutputParserException(`Could not parse LLM output: ${text}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.parseOutput = parseOutput;
|
|
8
|
+
const output_parser_js_1 = require("./output_parser.cjs");
|
|
31
9
|
/**
|
|
32
10
|
* Class that represents an agent that uses XML tags.
|
|
33
11
|
*/
|
|
@@ -58,6 +36,12 @@ class XMLAgent extends agent_js_1.BaseSingleActionAgent {
|
|
|
58
36
|
writable: true,
|
|
59
37
|
value: void 0
|
|
60
38
|
});
|
|
39
|
+
Object.defineProperty(this, "outputParser", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: new output_parser_js_1.XMLAgentOutputParser()
|
|
44
|
+
});
|
|
61
45
|
this.tools = fields.tools;
|
|
62
46
|
this.llmChain = fields.llmChain;
|
|
63
47
|
}
|
|
@@ -94,7 +78,7 @@ class XMLAgent extends agent_js_1.BaseSingleActionAgent {
|
|
|
94
78
|
stop: ["</tool_input>", "</final_answer>"],
|
|
95
79
|
};
|
|
96
80
|
const response = await this.llmChain.call(_inputs, callbackManager);
|
|
97
|
-
return
|
|
81
|
+
return this.outputParser.parse(response[this.llmChain.outputKey]);
|
|
98
82
|
}
|
|
99
83
|
/**
|
|
100
84
|
* Creates an XMLAgent from a BaseLanguageModel and a list of tools.
|
|
@@ -5,6 +5,7 @@ import { ChatPromptTemplate } from "../../prompts/chat.js";
|
|
|
5
5
|
import { AgentArgs, BaseSingleActionAgent } from "../agent.js";
|
|
6
6
|
import { CallbackManager } from "../../callbacks/manager.js";
|
|
7
7
|
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
8
|
+
import { XMLAgentOutputParser } from "./output_parser.js";
|
|
8
9
|
/**
|
|
9
10
|
* Interface for the input to the XMLAgent class.
|
|
10
11
|
*/
|
|
@@ -12,13 +13,6 @@ export interface XMLAgentInput {
|
|
|
12
13
|
tools: Tool[];
|
|
13
14
|
llmChain: LLMChain;
|
|
14
15
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Parses the output text from the agent and returns an AgentAction or
|
|
17
|
-
* AgentFinish object.
|
|
18
|
-
* @param text The output text from the agent.
|
|
19
|
-
* @returns An AgentAction or AgentFinish object.
|
|
20
|
-
*/
|
|
21
|
-
export declare function parseOutput(text: string): Promise<AgentAction | AgentFinish>;
|
|
22
16
|
/**
|
|
23
17
|
* Class that represents an agent that uses XML tags.
|
|
24
18
|
*/
|
|
@@ -27,6 +21,7 @@ export declare class XMLAgent extends BaseSingleActionAgent implements XMLAgentI
|
|
|
27
21
|
lc_namespace: string[];
|
|
28
22
|
tools: Tool[];
|
|
29
23
|
llmChain: LLMChain;
|
|
24
|
+
outputParser: XMLAgentOutputParser;
|
|
30
25
|
_agentType(): "xml";
|
|
31
26
|
constructor(fields: XMLAgentInput);
|
|
32
27
|
get inputKeys(): string[];
|
package/dist/agents/xml/index.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
2
2
|
import { AIMessagePromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
3
3
|
import { BaseSingleActionAgent } from "../agent.js";
|
|
4
|
-
import { OutputParserException } from "../../schema/output_parser.js";
|
|
5
4
|
import { AGENT_INSTRUCTIONS } from "./prompt.js";
|
|
6
|
-
|
|
7
|
-
* Parses the output text from the agent and returns an AgentAction or
|
|
8
|
-
* AgentFinish object.
|
|
9
|
-
* @param text The output text from the agent.
|
|
10
|
-
* @returns An AgentAction or AgentFinish object.
|
|
11
|
-
*/
|
|
12
|
-
export async function parseOutput(text) {
|
|
13
|
-
if (text.includes("</tool>")) {
|
|
14
|
-
const [tool, toolInput] = text.split("</tool>");
|
|
15
|
-
const _tool = tool.split("<tool>")[1];
|
|
16
|
-
const _toolInput = toolInput.split("<tool_input>")[1];
|
|
17
|
-
return { tool: _tool, toolInput: _toolInput, log: text };
|
|
18
|
-
}
|
|
19
|
-
else if (text.includes("<final_answer>")) {
|
|
20
|
-
const [, answer] = text.split("<final_answer>");
|
|
21
|
-
return { returnValues: { output: answer }, log: text };
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new OutputParserException(`Could not parse LLM output: ${text}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
5
|
+
import { XMLAgentOutputParser } from "./output_parser.js";
|
|
27
6
|
/**
|
|
28
7
|
* Class that represents an agent that uses XML tags.
|
|
29
8
|
*/
|
|
@@ -54,6 +33,12 @@ export class XMLAgent extends BaseSingleActionAgent {
|
|
|
54
33
|
writable: true,
|
|
55
34
|
value: void 0
|
|
56
35
|
});
|
|
36
|
+
Object.defineProperty(this, "outputParser", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: new XMLAgentOutputParser()
|
|
41
|
+
});
|
|
57
42
|
this.tools = fields.tools;
|
|
58
43
|
this.llmChain = fields.llmChain;
|
|
59
44
|
}
|
|
@@ -90,7 +75,7 @@ export class XMLAgent extends BaseSingleActionAgent {
|
|
|
90
75
|
stop: ["</tool_input>", "</final_answer>"],
|
|
91
76
|
};
|
|
92
77
|
const response = await this.llmChain.call(_inputs, callbackManager);
|
|
93
|
-
return
|
|
78
|
+
return this.outputParser.parse(response[this.llmChain.outputKey]);
|
|
94
79
|
}
|
|
95
80
|
/**
|
|
96
81
|
* Creates an XMLAgent from a BaseLanguageModel and a list of tools.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XMLAgentOutputParser = void 0;
|
|
4
|
+
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
5
|
+
const types_js_1 = require("../types.cjs");
|
|
6
|
+
class XMLAgentOutputParser extends types_js_1.AgentActionOutputParser {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: ["langchain", "agents", "xml"]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static lc_name() {
|
|
17
|
+
return "XMLAgentOutputParser";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parses the output text from the agent and returns an AgentAction or
|
|
21
|
+
* AgentFinish object.
|
|
22
|
+
* @param text The output text from the agent.
|
|
23
|
+
* @returns An AgentAction or AgentFinish object.
|
|
24
|
+
*/
|
|
25
|
+
async parse(text) {
|
|
26
|
+
if (text.includes("</tool>")) {
|
|
27
|
+
const [tool, toolInput] = text.split("</tool>");
|
|
28
|
+
const _tool = tool.split("<tool>")[1];
|
|
29
|
+
const _toolInput = toolInput.split("<tool_input>")[1];
|
|
30
|
+
return { tool: _tool, toolInput: _toolInput, log: text };
|
|
31
|
+
}
|
|
32
|
+
else if (text.includes("<final_answer>")) {
|
|
33
|
+
const [, answer] = text.split("<final_answer>");
|
|
34
|
+
return { returnValues: { output: answer }, log: text };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new output_parser_js_1.OutputParserException(`Could not parse LLM output: ${text}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getFormatInstructions() {
|
|
41
|
+
throw new Error("getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.XMLAgentOutputParser = XMLAgentOutputParser;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AgentAction, AgentFinish } from "../../schema/index.js";
|
|
2
|
+
import { AgentActionOutputParser } from "../types.js";
|
|
3
|
+
export declare class XMLAgentOutputParser extends AgentActionOutputParser {
|
|
4
|
+
lc_namespace: string[];
|
|
5
|
+
static lc_name(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Parses the output text from the agent and returns an AgentAction or
|
|
8
|
+
* AgentFinish object.
|
|
9
|
+
* @param text The output text from the agent.
|
|
10
|
+
* @returns An AgentAction or AgentFinish object.
|
|
11
|
+
*/
|
|
12
|
+
parse(text: string): Promise<AgentAction | AgentFinish>;
|
|
13
|
+
getFormatInstructions(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { OutputParserException } from "../../schema/output_parser.js";
|
|
2
|
+
import { AgentActionOutputParser } from "../types.js";
|
|
3
|
+
export class XMLAgentOutputParser extends AgentActionOutputParser {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: ["langchain", "agents", "xml"]
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
static lc_name() {
|
|
14
|
+
return "XMLAgentOutputParser";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parses the output text from the agent and returns an AgentAction or
|
|
18
|
+
* AgentFinish object.
|
|
19
|
+
* @param text The output text from the agent.
|
|
20
|
+
* @returns An AgentAction or AgentFinish object.
|
|
21
|
+
*/
|
|
22
|
+
async parse(text) {
|
|
23
|
+
if (text.includes("</tool>")) {
|
|
24
|
+
const [tool, toolInput] = text.split("</tool>");
|
|
25
|
+
const _tool = tool.split("<tool>")[1];
|
|
26
|
+
const _toolInput = toolInput.split("<tool_input>")[1];
|
|
27
|
+
return { tool: _tool, toolInput: _toolInput, log: text };
|
|
28
|
+
}
|
|
29
|
+
else if (text.includes("<final_answer>")) {
|
|
30
|
+
const [, answer] = text.split("<final_answer>");
|
|
31
|
+
return { returnValues: { output: answer }, log: text };
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new OutputParserException(`Could not parse LLM output: ${text}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getFormatInstructions() {
|
|
38
|
+
throw new Error("getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -504,7 +504,8 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
504
504
|
? localHandlers.map(ensureHandler)
|
|
505
505
|
: localHandlers?.handlers, false);
|
|
506
506
|
}
|
|
507
|
-
const verboseEnabled = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_VERBOSE") ||
|
|
507
|
+
const verboseEnabled = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_VERBOSE") === "true" ||
|
|
508
|
+
options?.verbose;
|
|
508
509
|
const tracingV2Enabled = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_TRACING_V2") === "true";
|
|
509
510
|
const tracingEnabled = tracingV2Enabled ||
|
|
510
511
|
((0, env_js_1.getEnvironmentVariable)("LANGCHAIN_TRACING") ?? false);
|
|
@@ -495,7 +495,8 @@ export class CallbackManager extends BaseCallbackManager {
|
|
|
495
495
|
? localHandlers.map(ensureHandler)
|
|
496
496
|
: localHandlers?.handlers, false);
|
|
497
497
|
}
|
|
498
|
-
const verboseEnabled = getEnvironmentVariable("LANGCHAIN_VERBOSE") ||
|
|
498
|
+
const verboseEnabled = getEnvironmentVariable("LANGCHAIN_VERBOSE") === "true" ||
|
|
499
|
+
options?.verbose;
|
|
499
500
|
const tracingV2Enabled = getEnvironmentVariable("LANGCHAIN_TRACING_V2") === "true";
|
|
500
501
|
const tracingEnabled = tracingV2Enabled ||
|
|
501
502
|
(getEnvironmentVariable("LANGCHAIN_TRACING") ?? false);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PDFLoader = void 0;
|
|
4
4
|
const document_js_1 = require("../../document.cjs");
|
|
5
5
|
const buffer_js_1 = require("./buffer.cjs");
|
|
6
|
+
const document_js_2 = require("../../util/document.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* A class that extends the `BufferLoader` class. It represents a document
|
|
8
9
|
* loader that loads documents from PDF files.
|
|
@@ -85,7 +86,7 @@ class PDFLoader extends buffer_js_1.BufferLoader {
|
|
|
85
86
|
}
|
|
86
87
|
return [
|
|
87
88
|
new document_js_1.Document({
|
|
88
|
-
pageContent:
|
|
89
|
+
pageContent: (0, document_js_2.formatDocumentsAsString)(documents),
|
|
89
90
|
metadata: {
|
|
90
91
|
...metadata,
|
|
91
92
|
pdf: {
|