-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
zapier.ts
46 lines (44 loc) · 1.64 KB
/
zapier.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
37
38
39
40
41
42
43
44
45
46
import { ToolInterface } from "@langchain/core/tools";
import { Toolkit } from "@langchain/community/agents/toolkits/base";
import { ZapierNLARunAction, ZapierNLAWrapper } from "../../../tools/zapier.js";
/**
* Represents a toolkit for working with Zapier actions. It extends the
* Toolkit class and provides functionality for managing Zapier tools.
* @example
* ```typescript
* const toolkit = await ZapierToolKit.fromZapierNLAWrapper(
* new ZapierNLAWrapper(),
* );
* const result = await toolkit.invoke({
* input:
* "Summarize the last email I received regarding Silicon Valley Bank. Send the summary to the #test-zapier Slack channel.",
* });
* ```
*/
export class ZapierToolKit extends Toolkit {
tools: ToolInterface[] = [];
/**
* Creates a ZapierToolKit instance based on a ZapierNLAWrapper instance.
* It retrieves the list of available actions from the ZapierNLAWrapper
* and creates a ZapierNLARunAction tool for each action. The created
* tools are added to the tools property of the ZapierToolKit instance.
* @param zapierNLAWrapper The ZapierNLAWrapper instance to create the ZapierToolKit from.
* @returns A Promise that resolves to a ZapierToolKit instance.
*/
static async fromZapierNLAWrapper(
zapierNLAWrapper: ZapierNLAWrapper
): Promise<ZapierToolKit> {
const toolkit = new ZapierToolKit();
const actions = await zapierNLAWrapper.listActions();
for (const action of actions) {
const tool = new ZapierNLARunAction(
zapierNLAWrapper,
action.id,
action.description,
action.params
);
toolkit.tools.push(tool);
}
return toolkit;
}
}