langchain 0.0.132 → 0.0.134
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/chat/outputParser.cjs +2 -1
- package/dist/agents/chat/outputParser.js +2 -1
- package/dist/agents/executor.cjs +106 -7
- package/dist/agents/executor.d.ts +23 -0
- package/dist/agents/executor.js +104 -6
- package/dist/agents/mrkl/outputParser.cjs +2 -1
- package/dist/agents/mrkl/outputParser.js +2 -1
- package/dist/callbacks/index.cjs +2 -1
- package/dist/callbacks/index.d.ts +1 -1
- package/dist/callbacks/index.js +1 -1
- package/dist/chains/sql_db/sql_db_chain.d.ts +1 -1
- package/dist/chains/sql_db/sql_db_prompt.d.ts +6 -6
- package/dist/chat_models/googlevertexai.cjs +1 -1
- package/dist/chat_models/googlevertexai.d.ts +2 -2
- package/dist/chat_models/googlevertexai.js +2 -2
- package/dist/chat_models/ollama.cjs +8 -8
- package/dist/chat_models/ollama.js +8 -8
- package/dist/document_loaders/web/notionapi.cjs +153 -74
- package/dist/document_loaders/web/notionapi.d.ts +19 -10
- package/dist/document_loaders/web/notionapi.js +154 -75
- package/dist/document_loaders/web/recursive_url.cjs +177 -0
- package/dist/document_loaders/web/recursive_url.d.ts +27 -0
- package/dist/document_loaders/web/recursive_url.js +173 -0
- package/dist/embeddings/googlevertexai.cjs +1 -1
- package/dist/embeddings/googlevertexai.d.ts +2 -2
- package/dist/embeddings/googlevertexai.js +2 -2
- package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +1 -1
- package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -2
- package/dist/experimental/multimodal_embeddings/googlevertexai.js +2 -2
- package/dist/hub.cjs +16 -0
- package/dist/hub.d.ts +4 -0
- package/dist/hub.js +11 -0
- package/dist/llms/bedrock.cjs +63 -19
- package/dist/llms/bedrock.d.ts +9 -1
- package/dist/llms/bedrock.js +63 -19
- package/dist/llms/googlevertexai.cjs +1 -1
- package/dist/llms/googlevertexai.js +2 -2
- package/dist/load/import_constants.cjs +3 -0
- package/dist/load/import_constants.js +3 -0
- package/dist/schema/output_parser.cjs +2 -2
- package/dist/schema/output_parser.js +2 -2
- package/dist/tools/base.cjs +26 -2
- package/dist/tools/base.d.ts +9 -0
- package/dist/tools/base.js +24 -1
- package/dist/tools/sql.cjs +9 -3
- package/dist/tools/sql.d.ts +0 -1
- package/dist/tools/sql.js +9 -3
- package/dist/types/googlevertexai-types.d.ts +8 -3
- package/dist/util/googlevertexai-connection.cjs +49 -15
- package/dist/util/googlevertexai-connection.d.ts +12 -4
- package/dist/util/googlevertexai-connection.js +46 -13
- package/dist/vectorstores/googlevertexai.cjs +551 -0
- package/dist/vectorstores/googlevertexai.d.ts +180 -0
- package/dist/vectorstores/googlevertexai.js +520 -0
- package/dist/vectorstores/myscale.cjs +2 -2
- package/dist/vectorstores/myscale.d.ts +1 -1
- package/dist/vectorstores/myscale.js +2 -2
- package/dist/vectorstores/vectara.cjs +11 -2
- package/dist/vectorstores/vectara.d.ts +10 -1
- package/dist/vectorstores/vectara.js +11 -2
- package/document_loaders/web/recursive_url.cjs +1 -0
- package/document_loaders/web/recursive_url.d.ts +1 -0
- package/document_loaders/web/recursive_url.js +1 -0
- package/hub.cjs +1 -0
- package/hub.d.ts +1 -0
- package/hub.js +1 -0
- package/package.json +41 -2
- package/vectorstores/googlevertexai.cjs +1 -0
- package/vectorstores/googlevertexai.d.ts +1 -0
- package/vectorstores/googlevertexai.js +1 -0
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ChatAgentOutputParser = exports.FINAL_ANSWER_ACTION = void 0;
|
|
4
4
|
const types_js_1 = require("../types.cjs");
|
|
5
5
|
const prompt_js_1 = require("./prompt.cjs");
|
|
6
|
+
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
6
7
|
exports.FINAL_ANSWER_ACTION = "Final Answer:";
|
|
7
8
|
/**
|
|
8
9
|
* A class that extends the AgentActionOutputParser to parse the output of
|
|
@@ -46,7 +47,7 @@ class ChatAgentOutputParser extends types_js_1.AgentActionOutputParser {
|
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
catch {
|
|
49
|
-
throw new
|
|
50
|
+
throw new output_parser_js_1.OutputParserException(`Unable to parse JSON response from chat agent.\n\n${text}`);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AgentActionOutputParser } from "../types.js";
|
|
2
2
|
import { FORMAT_INSTRUCTIONS } from "./prompt.js";
|
|
3
|
+
import { OutputParserException } from "../../schema/output_parser.js";
|
|
3
4
|
export const FINAL_ANSWER_ACTION = "Final Answer:";
|
|
4
5
|
/**
|
|
5
6
|
* A class that extends the AgentActionOutputParser to parse the output of
|
|
@@ -43,7 +44,7 @@ export class ChatAgentOutputParser extends AgentActionOutputParser {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
catch {
|
|
46
|
-
throw new
|
|
47
|
+
throw new OutputParserException(`Unable to parse JSON response from chat agent.\n\n${text}`);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
/**
|
package/dist/agents/executor.cjs
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentExecutor = void 0;
|
|
3
|
+
exports.AgentExecutor = exports.ExceptionTool = void 0;
|
|
4
4
|
const base_js_1 = require("../chains/base.cjs");
|
|
5
|
+
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
6
|
+
const base_js_2 = require("../tools/base.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Tool that just returns the query.
|
|
9
|
+
* Used for exception tracking.
|
|
10
|
+
*/
|
|
11
|
+
class ExceptionTool extends base_js_2.Tool {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
Object.defineProperty(this, "name", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: "_Exception"
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "description", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: "Exception tool"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async _call(query) {
|
|
28
|
+
return query;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ExceptionTool = ExceptionTool;
|
|
5
32
|
/**
|
|
6
33
|
* A chain managing an agent using tools.
|
|
7
34
|
* @augments BaseChain
|
|
@@ -51,8 +78,26 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
51
78
|
writable: true,
|
|
52
79
|
value: "force"
|
|
53
80
|
});
|
|
81
|
+
/**
|
|
82
|
+
* How to handle errors raised by the agent's output parser.
|
|
83
|
+
Defaults to `False`, which raises the error.
|
|
84
|
+
|
|
85
|
+
If `true`, the error will be sent back to the LLM as an observation.
|
|
86
|
+
If a string, the string itself will be sent to the LLM as an observation.
|
|
87
|
+
If a callable function, the function will be called with the exception
|
|
88
|
+
as an argument, and the result of that function will be passed to the agent
|
|
89
|
+
as an observation.
|
|
90
|
+
*/
|
|
91
|
+
Object.defineProperty(this, "handleParsingErrors", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
configurable: true,
|
|
94
|
+
writable: true,
|
|
95
|
+
value: false
|
|
96
|
+
});
|
|
54
97
|
this.agent = input.agent;
|
|
55
98
|
this.tools = input.tools;
|
|
99
|
+
this.handleParsingErrors =
|
|
100
|
+
input.handleParsingErrors ?? this.handleParsingErrors;
|
|
56
101
|
if (this.agent._agentActionType() === "multi") {
|
|
57
102
|
for (const tool of this.tools) {
|
|
58
103
|
if (tool.returnDirect) {
|
|
@@ -94,7 +139,36 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
94
139
|
return { ...returnValues, ...additional };
|
|
95
140
|
};
|
|
96
141
|
while (this.shouldContinue(iterations)) {
|
|
97
|
-
|
|
142
|
+
let output;
|
|
143
|
+
try {
|
|
144
|
+
output = await this.agent.plan(steps, inputs, runManager?.getChild());
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
148
|
+
if (e instanceof output_parser_js_1.OutputParserException) {
|
|
149
|
+
let observation;
|
|
150
|
+
if (this.handleParsingErrors === true) {
|
|
151
|
+
observation = "Invalid or incomplete response";
|
|
152
|
+
}
|
|
153
|
+
else if (typeof this.handleParsingErrors === "string") {
|
|
154
|
+
observation = this.handleParsingErrors;
|
|
155
|
+
}
|
|
156
|
+
else if (typeof this.handleParsingErrors === "function") {
|
|
157
|
+
observation = this.handleParsingErrors(e);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
output = {
|
|
163
|
+
tool: "_Exception",
|
|
164
|
+
toolInput: observation,
|
|
165
|
+
log: e.message,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw e;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
98
172
|
// Check if the agent has finished
|
|
99
173
|
if ("returnValues" in output) {
|
|
100
174
|
return getOutput(output);
|
|
@@ -108,11 +182,36 @@ class AgentExecutor extends base_js_1.BaseChain {
|
|
|
108
182
|
}
|
|
109
183
|
const newSteps = await Promise.all(actions.map(async (action) => {
|
|
110
184
|
await runManager?.handleAgentAction(action);
|
|
111
|
-
const tool =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
185
|
+
const tool = action.tool === "_Exception"
|
|
186
|
+
? new ExceptionTool()
|
|
187
|
+
: toolsByName[action.tool?.toLowerCase()];
|
|
188
|
+
let observation;
|
|
189
|
+
try {
|
|
190
|
+
observation = tool
|
|
191
|
+
? await tool.call(action.toolInput, runManager?.getChild())
|
|
192
|
+
: `${action.tool} is not a valid tool, try another one.`;
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
196
|
+
if (e instanceof base_js_2.ToolInputParsingException) {
|
|
197
|
+
if (this.handleParsingErrors === true) {
|
|
198
|
+
observation =
|
|
199
|
+
"Invalid or incomplete tool input. Please try again.";
|
|
200
|
+
}
|
|
201
|
+
else if (typeof this.handleParsingErrors === "string") {
|
|
202
|
+
observation = this.handleParsingErrors;
|
|
203
|
+
}
|
|
204
|
+
else if (typeof this.handleParsingErrors === "function") {
|
|
205
|
+
observation = this.handleParsingErrors(e);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
observation = await new ExceptionTool().call(observation, runManager?.getChild());
|
|
211
|
+
return { action, observation: observation ?? "" };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { action, observation: observation ?? "" };
|
|
116
215
|
}));
|
|
117
216
|
steps.push(...newSteps);
|
|
118
217
|
const lastStep = steps[steps.length - 1];
|
|
@@ -4,6 +4,8 @@ import { StoppingMethod } from "./types.js";
|
|
|
4
4
|
import { SerializedLLMChain } from "../chains/serde.js";
|
|
5
5
|
import { ChainValues } from "../schema/index.js";
|
|
6
6
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
7
|
+
import { OutputParserException } from "../schema/output_parser.js";
|
|
8
|
+
import { Tool, ToolInputParsingException } from "../tools/base.js";
|
|
7
9
|
/**
|
|
8
10
|
* Interface defining the structure of input data for creating an
|
|
9
11
|
* AgentExecutor. It extends ChainInputs and includes additional
|
|
@@ -15,6 +17,16 @@ export interface AgentExecutorInput extends ChainInputs {
|
|
|
15
17
|
returnIntermediateSteps?: boolean;
|
|
16
18
|
maxIterations?: number;
|
|
17
19
|
earlyStoppingMethod?: StoppingMethod;
|
|
20
|
+
handleParsingErrors?: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tool that just returns the query.
|
|
24
|
+
* Used for exception tracking.
|
|
25
|
+
*/
|
|
26
|
+
export declare class ExceptionTool extends Tool {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
_call(query: string): Promise<string>;
|
|
18
30
|
}
|
|
19
31
|
/**
|
|
20
32
|
* A chain managing an agent using tools.
|
|
@@ -28,6 +40,17 @@ export declare class AgentExecutor extends BaseChain {
|
|
|
28
40
|
returnIntermediateSteps: boolean;
|
|
29
41
|
maxIterations?: number;
|
|
30
42
|
earlyStoppingMethod: StoppingMethod;
|
|
43
|
+
/**
|
|
44
|
+
* How to handle errors raised by the agent's output parser.
|
|
45
|
+
Defaults to `False`, which raises the error.
|
|
46
|
+
|
|
47
|
+
If `true`, the error will be sent back to the LLM as an observation.
|
|
48
|
+
If a string, the string itself will be sent to the LLM as an observation.
|
|
49
|
+
If a callable function, the function will be called with the exception
|
|
50
|
+
as an argument, and the result of that function will be passed to the agent
|
|
51
|
+
as an observation.
|
|
52
|
+
*/
|
|
53
|
+
handleParsingErrors: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
|
|
31
54
|
get inputKeys(): string[];
|
|
32
55
|
get outputKeys(): string[];
|
|
33
56
|
constructor(input: AgentExecutorInput);
|
package/dist/agents/executor.js
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { BaseChain } from "../chains/base.js";
|
|
2
|
+
import { OutputParserException } from "../schema/output_parser.js";
|
|
3
|
+
import { Tool, ToolInputParsingException } from "../tools/base.js";
|
|
4
|
+
/**
|
|
5
|
+
* Tool that just returns the query.
|
|
6
|
+
* Used for exception tracking.
|
|
7
|
+
*/
|
|
8
|
+
export class ExceptionTool extends Tool {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
Object.defineProperty(this, "name", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: "_Exception"
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "description", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: "Exception tool"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async _call(query) {
|
|
25
|
+
return query;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
29
|
* A chain managing an agent using tools.
|
|
4
30
|
* @augments BaseChain
|
|
@@ -48,8 +74,26 @@ export class AgentExecutor extends BaseChain {
|
|
|
48
74
|
writable: true,
|
|
49
75
|
value: "force"
|
|
50
76
|
});
|
|
77
|
+
/**
|
|
78
|
+
* How to handle errors raised by the agent's output parser.
|
|
79
|
+
Defaults to `False`, which raises the error.
|
|
80
|
+
|
|
81
|
+
If `true`, the error will be sent back to the LLM as an observation.
|
|
82
|
+
If a string, the string itself will be sent to the LLM as an observation.
|
|
83
|
+
If a callable function, the function will be called with the exception
|
|
84
|
+
as an argument, and the result of that function will be passed to the agent
|
|
85
|
+
as an observation.
|
|
86
|
+
*/
|
|
87
|
+
Object.defineProperty(this, "handleParsingErrors", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: false
|
|
92
|
+
});
|
|
51
93
|
this.agent = input.agent;
|
|
52
94
|
this.tools = input.tools;
|
|
95
|
+
this.handleParsingErrors =
|
|
96
|
+
input.handleParsingErrors ?? this.handleParsingErrors;
|
|
53
97
|
if (this.agent._agentActionType() === "multi") {
|
|
54
98
|
for (const tool of this.tools) {
|
|
55
99
|
if (tool.returnDirect) {
|
|
@@ -91,7 +135,36 @@ export class AgentExecutor extends BaseChain {
|
|
|
91
135
|
return { ...returnValues, ...additional };
|
|
92
136
|
};
|
|
93
137
|
while (this.shouldContinue(iterations)) {
|
|
94
|
-
|
|
138
|
+
let output;
|
|
139
|
+
try {
|
|
140
|
+
output = await this.agent.plan(steps, inputs, runManager?.getChild());
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
144
|
+
if (e instanceof OutputParserException) {
|
|
145
|
+
let observation;
|
|
146
|
+
if (this.handleParsingErrors === true) {
|
|
147
|
+
observation = "Invalid or incomplete response";
|
|
148
|
+
}
|
|
149
|
+
else if (typeof this.handleParsingErrors === "string") {
|
|
150
|
+
observation = this.handleParsingErrors;
|
|
151
|
+
}
|
|
152
|
+
else if (typeof this.handleParsingErrors === "function") {
|
|
153
|
+
observation = this.handleParsingErrors(e);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
158
|
+
output = {
|
|
159
|
+
tool: "_Exception",
|
|
160
|
+
toolInput: observation,
|
|
161
|
+
log: e.message,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
95
168
|
// Check if the agent has finished
|
|
96
169
|
if ("returnValues" in output) {
|
|
97
170
|
return getOutput(output);
|
|
@@ -105,11 +178,36 @@ export class AgentExecutor extends BaseChain {
|
|
|
105
178
|
}
|
|
106
179
|
const newSteps = await Promise.all(actions.map(async (action) => {
|
|
107
180
|
await runManager?.handleAgentAction(action);
|
|
108
|
-
const tool =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
181
|
+
const tool = action.tool === "_Exception"
|
|
182
|
+
? new ExceptionTool()
|
|
183
|
+
: toolsByName[action.tool?.toLowerCase()];
|
|
184
|
+
let observation;
|
|
185
|
+
try {
|
|
186
|
+
observation = tool
|
|
187
|
+
? await tool.call(action.toolInput, runManager?.getChild())
|
|
188
|
+
: `${action.tool} is not a valid tool, try another one.`;
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
192
|
+
if (e instanceof ToolInputParsingException) {
|
|
193
|
+
if (this.handleParsingErrors === true) {
|
|
194
|
+
observation =
|
|
195
|
+
"Invalid or incomplete tool input. Please try again.";
|
|
196
|
+
}
|
|
197
|
+
else if (typeof this.handleParsingErrors === "string") {
|
|
198
|
+
observation = this.handleParsingErrors;
|
|
199
|
+
}
|
|
200
|
+
else if (typeof this.handleParsingErrors === "function") {
|
|
201
|
+
observation = this.handleParsingErrors(e);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
observation = await new ExceptionTool().call(observation, runManager?.getChild());
|
|
207
|
+
return { action, observation: observation ?? "" };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return { action, observation: observation ?? "" };
|
|
113
211
|
}));
|
|
114
212
|
steps.push(...newSteps);
|
|
115
213
|
const lastStep = steps[steps.length - 1];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZeroShotAgentOutputParser = exports.FINAL_ANSWER_ACTION = void 0;
|
|
4
|
+
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
4
5
|
const types_js_1 = require("../types.cjs");
|
|
5
6
|
const prompt_js_1 = require("./prompt.cjs");
|
|
6
7
|
exports.FINAL_ANSWER_ACTION = "Final Answer:";
|
|
@@ -42,7 +43,7 @@ class ZeroShotAgentOutputParser extends types_js_1.AgentActionOutputParser {
|
|
|
42
43
|
}
|
|
43
44
|
const match = /Action: ([\s\S]*?)(?:\nAction Input: ([\s\S]*?))?$/.exec(text);
|
|
44
45
|
if (!match) {
|
|
45
|
-
throw new
|
|
46
|
+
throw new output_parser_js_1.OutputParserException(`Could not parse LLM output: ${text}`);
|
|
46
47
|
}
|
|
47
48
|
return {
|
|
48
49
|
tool: match[1].trim(),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OutputParserException } from "../../schema/output_parser.js";
|
|
1
2
|
import { AgentActionOutputParser } from "../types.js";
|
|
2
3
|
import { FORMAT_INSTRUCTIONS } from "./prompt.js";
|
|
3
4
|
export const FINAL_ANSWER_ACTION = "Final Answer:";
|
|
@@ -39,7 +40,7 @@ export class ZeroShotAgentOutputParser extends AgentActionOutputParser {
|
|
|
39
40
|
}
|
|
40
41
|
const match = /Action: ([\s\S]*?)(?:\nAction Input: ([\s\S]*?))?$/.exec(text);
|
|
41
42
|
if (!match) {
|
|
42
|
-
throw new
|
|
43
|
+
throw new OutputParserException(`Could not parse LLM output: ${text}`);
|
|
43
44
|
}
|
|
44
45
|
return {
|
|
45
46
|
tool: match[1].trim(),
|
package/dist/callbacks/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.consumeCallback = exports.awaitAllCallbacks = exports.traceAsGroup = exports.TraceGroup = exports.CallbackManagerForToolRun = exports.CallbackManagerForLLMRun = exports.CallbackManagerForChainRun = exports.CallbackManager = exports.getTracingV2CallbackHandler = exports.getTracingCallbackHandler = exports.LangChainTracerV1 = exports.LangChainTracer = exports.ConsoleCallbackHandler = exports.BaseTracer = exports.BaseCallbackHandler = void 0;
|
|
3
|
+
exports.consumeCallback = exports.awaitAllCallbacks = exports.traceAsGroup = exports.TraceGroup = exports.CallbackManagerForToolRun = exports.CallbackManagerForLLMRun = exports.CallbackManagerForChainRun = exports.CallbackManagerForRetrieverRun = exports.CallbackManager = exports.getTracingV2CallbackHandler = exports.getTracingCallbackHandler = exports.LangChainTracerV1 = exports.LangChainTracer = exports.ConsoleCallbackHandler = exports.BaseTracer = exports.BaseCallbackHandler = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseCallbackHandler", { enumerable: true, get: function () { return base_js_1.BaseCallbackHandler; } });
|
|
6
6
|
var tracer_js_1 = require("./handlers/tracer.cjs");
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "getTracingCallbackHandler", { enumerable: true,
|
|
|
16
16
|
Object.defineProperty(exports, "getTracingV2CallbackHandler", { enumerable: true, get: function () { return initialize_js_1.getTracingV2CallbackHandler; } });
|
|
17
17
|
var manager_js_1 = require("./manager.cjs");
|
|
18
18
|
Object.defineProperty(exports, "CallbackManager", { enumerable: true, get: function () { return manager_js_1.CallbackManager; } });
|
|
19
|
+
Object.defineProperty(exports, "CallbackManagerForRetrieverRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForRetrieverRun; } });
|
|
19
20
|
Object.defineProperty(exports, "CallbackManagerForChainRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForChainRun; } });
|
|
20
21
|
Object.defineProperty(exports, "CallbackManagerForLLMRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForLLMRun; } });
|
|
21
22
|
Object.defineProperty(exports, "CallbackManagerForToolRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForToolRun; } });
|
|
@@ -4,5 +4,5 @@ export { ConsoleCallbackHandler } from "./handlers/console.js";
|
|
|
4
4
|
export { LangChainTracer } from "./handlers/tracer_langchain.js";
|
|
5
5
|
export { LangChainTracerV1 } from "./handlers/tracer_langchain_v1.js";
|
|
6
6
|
export { getTracingCallbackHandler, getTracingV2CallbackHandler, } from "./handlers/initialize.js";
|
|
7
|
-
export { CallbackManager, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, CallbackManagerOptions, Callbacks, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
7
|
+
export { CallbackManager, CallbackManagerForRetrieverRun, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, CallbackManagerOptions, Callbacks, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
8
8
|
export { awaitAllCallbacks, consumeCallback } from "./promises.js";
|
package/dist/callbacks/index.js
CHANGED
|
@@ -4,5 +4,5 @@ export { ConsoleCallbackHandler } from "./handlers/console.js";
|
|
|
4
4
|
export { LangChainTracer } from "./handlers/tracer_langchain.js";
|
|
5
5
|
export { LangChainTracerV1 } from "./handlers/tracer_langchain_v1.js";
|
|
6
6
|
export { getTracingCallbackHandler, getTracingV2CallbackHandler, } from "./handlers/initialize.js";
|
|
7
|
-
export { CallbackManager, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
7
|
+
export { CallbackManager, CallbackManagerForRetrieverRun, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
8
8
|
export { awaitAllCallbacks, consumeCallback } from "./promises.js";
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
2
2
|
export declare const DEFAULT_SQL_DATABASE_PROMPT: PromptTemplate<{
|
|
3
3
|
input: any;
|
|
4
|
+
top_k: any;
|
|
4
5
|
dialect: any;
|
|
5
6
|
table_info: any;
|
|
6
|
-
top_k: any;
|
|
7
7
|
}, any>;
|
|
8
8
|
export declare const SQL_POSTGRES_PROMPT: PromptTemplate<{
|
|
9
9
|
input: any;
|
|
10
|
+
top_k: any;
|
|
10
11
|
dialect: any;
|
|
11
12
|
table_info: any;
|
|
12
|
-
top_k: any;
|
|
13
13
|
}, any>;
|
|
14
14
|
export declare const SQL_SQLITE_PROMPT: PromptTemplate<{
|
|
15
15
|
input: any;
|
|
16
|
+
top_k: any;
|
|
16
17
|
dialect: any;
|
|
17
18
|
table_info: any;
|
|
18
|
-
top_k: any;
|
|
19
19
|
}, any>;
|
|
20
20
|
export declare const SQL_MYSQL_PROMPT: PromptTemplate<{
|
|
21
21
|
input: any;
|
|
22
|
+
top_k: any;
|
|
22
23
|
dialect: any;
|
|
23
24
|
table_info: any;
|
|
24
|
-
top_k: any;
|
|
25
25
|
}, any>;
|
|
26
26
|
export declare const SQL_MSSQL_PROMPT: PromptTemplate<{
|
|
27
27
|
input: any;
|
|
28
|
+
top_k: any;
|
|
28
29
|
dialect: any;
|
|
29
30
|
table_info: any;
|
|
30
|
-
top_k: any;
|
|
31
31
|
}, any>;
|
|
32
32
|
export declare const SQL_SAP_HANA_PROMPT: PromptTemplate<{
|
|
33
33
|
input: any;
|
|
34
|
+
top_k: any;
|
|
34
35
|
dialect: any;
|
|
35
36
|
table_info: any;
|
|
36
|
-
top_k: any;
|
|
37
37
|
}, any>;
|
|
@@ -158,7 +158,7 @@ class ChatGoogleVertexAI extends base_js_1.BaseChatModel {
|
|
|
158
158
|
this.topP = fields?.topP ?? this.topP;
|
|
159
159
|
this.topK = fields?.topK ?? this.topK;
|
|
160
160
|
this.examples = fields?.examples ?? this.examples;
|
|
161
|
-
this.connection = new googlevertexai_connection_js_1.
|
|
161
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({
|
|
162
162
|
...fields,
|
|
163
163
|
...this,
|
|
164
164
|
}, this.caller);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseChatModel } from "./base.js";
|
|
2
2
|
import { BaseMessage, ChatGeneration, ChatMessage, ChatResult, LLMResult } from "../schema/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
|
|
4
4
|
import { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction } from "../types/googlevertexai-types.js";
|
|
5
5
|
import { BaseLanguageModelCallOptions } from "../base_language/index.js";
|
|
6
6
|
/**
|
|
@@ -105,7 +105,7 @@ export declare class ChatGoogleVertexAI extends BaseChatModel implements GoogleV
|
|
|
105
105
|
topP: number;
|
|
106
106
|
topK: number;
|
|
107
107
|
examples: ChatExample[];
|
|
108
|
-
connection:
|
|
108
|
+
connection: GoogleVertexAILLMConnection<BaseLanguageModelCallOptions, GoogleVertexAIChatInstance, GoogleVertexAIChatPrediction>;
|
|
109
109
|
constructor(fields?: GoogleVertexAIChatInput);
|
|
110
110
|
_combineLLMOutput(): LLMResult["llmOutput"];
|
|
111
111
|
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<ChatResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseChatModel } from "./base.js";
|
|
2
2
|
import { AIMessage, ChatMessage, } from "../schema/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
|
|
4
4
|
/**
|
|
5
5
|
* Represents a chat message in the Google Vertex AI chat model.
|
|
6
6
|
*/
|
|
@@ -154,7 +154,7 @@ export class ChatGoogleVertexAI extends BaseChatModel {
|
|
|
154
154
|
this.topP = fields?.topP ?? this.topP;
|
|
155
155
|
this.topK = fields?.topK ?? this.topK;
|
|
156
156
|
this.examples = fields?.examples ?? this.examples;
|
|
157
|
-
this.connection = new
|
|
157
|
+
this.connection = new GoogleVertexAILLMConnection({
|
|
158
158
|
...fields,
|
|
159
159
|
...this,
|
|
160
160
|
}, this.caller);
|
|
@@ -177,27 +177,27 @@ class ChatOllama extends base_js_1.SimpleChatModel {
|
|
|
177
177
|
_formatMessagesAsPrompt(messages) {
|
|
178
178
|
const formattedMessages = messages
|
|
179
179
|
.map((message) => {
|
|
180
|
-
let
|
|
180
|
+
let messageText;
|
|
181
181
|
if (message._getType() === "human") {
|
|
182
|
-
|
|
182
|
+
messageText = `[INST] ${message.content} [/INST]`;
|
|
183
183
|
}
|
|
184
184
|
else if (message._getType() === "ai") {
|
|
185
|
-
|
|
185
|
+
messageText = message.content;
|
|
186
186
|
}
|
|
187
187
|
else if (message._getType() === "system") {
|
|
188
|
-
|
|
188
|
+
messageText = `<<SYS>> ${message.content} <</SYS>>`;
|
|
189
189
|
}
|
|
190
190
|
else if (index_js_1.ChatMessage.isInstance(message)) {
|
|
191
|
-
|
|
191
|
+
messageText = `\n\n${message.role[0].toUpperCase()}${message.role.slice(1)}: ${message.content}`;
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
194
194
|
console.warn(`Unsupported message type passed to Ollama: "${message._getType()}"`);
|
|
195
|
-
|
|
195
|
+
messageText = "";
|
|
196
196
|
}
|
|
197
|
-
return
|
|
197
|
+
return messageText;
|
|
198
198
|
})
|
|
199
199
|
.join("\n");
|
|
200
|
-
return
|
|
200
|
+
return formattedMessages;
|
|
201
201
|
}
|
|
202
202
|
/** @ignore */
|
|
203
203
|
async _call(messages, options) {
|
|
@@ -174,27 +174,27 @@ export class ChatOllama extends SimpleChatModel {
|
|
|
174
174
|
_formatMessagesAsPrompt(messages) {
|
|
175
175
|
const formattedMessages = messages
|
|
176
176
|
.map((message) => {
|
|
177
|
-
let
|
|
177
|
+
let messageText;
|
|
178
178
|
if (message._getType() === "human") {
|
|
179
|
-
|
|
179
|
+
messageText = `[INST] ${message.content} [/INST]`;
|
|
180
180
|
}
|
|
181
181
|
else if (message._getType() === "ai") {
|
|
182
|
-
|
|
182
|
+
messageText = message.content;
|
|
183
183
|
}
|
|
184
184
|
else if (message._getType() === "system") {
|
|
185
|
-
|
|
185
|
+
messageText = `<<SYS>> ${message.content} <</SYS>>`;
|
|
186
186
|
}
|
|
187
187
|
else if (ChatMessage.isInstance(message)) {
|
|
188
|
-
|
|
188
|
+
messageText = `\n\n${message.role[0].toUpperCase()}${message.role.slice(1)}: ${message.content}`;
|
|
189
189
|
}
|
|
190
190
|
else {
|
|
191
191
|
console.warn(`Unsupported message type passed to Ollama: "${message._getType()}"`);
|
|
192
|
-
|
|
192
|
+
messageText = "";
|
|
193
193
|
}
|
|
194
|
-
return
|
|
194
|
+
return messageText;
|
|
195
195
|
})
|
|
196
196
|
.join("\n");
|
|
197
|
-
return
|
|
197
|
+
return formattedMessages;
|
|
198
198
|
}
|
|
199
199
|
/** @ignore */
|
|
200
200
|
async _call(messages, options) {
|