-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
chain.ts
36 lines (32 loc) · 1.02 KB
/
chain.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { DynamicTool, DynamicToolInput } from "@langchain/core/tools";
import { BaseChain } from "../chains/base.js";
/**
* @deprecated Wrap in a DynamicTool instead.
* Interface for the input parameters of the ChainTool constructor.
* Extends the DynamicToolInput interface, replacing the 'func' property
* with a 'chain' property.
*/
export interface ChainToolInput extends Omit<DynamicToolInput, "func"> {
chain: BaseChain;
}
/**
* @deprecated Wrap in a DynamicTool instead.
* Class that extends DynamicTool for creating tools that can run chains.
* Takes an instance of a class that extends BaseChain as a parameter in
* its constructor and uses it to run the chain when its 'func' method is
* called.
*/
export class ChainTool extends DynamicTool {
static lc_name() {
return "ChainTool";
}
chain: BaseChain;
constructor({ chain, ...rest }: ChainToolInput) {
super({
...rest,
func: async (input, runManager) =>
chain.run(input, runManager?.getChild()),
});
this.chain = chain;
}
}