forked from i-am-bee/beeai-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlangchain.ts
34 lines (32 loc) · 869 Bytes
/
langchain.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
import { tool as createTool } from "@langchain/core/tools";
import { z } from "zod";
import { LangChainTool } from "bee-agent-framework/adapters/langchain/tools";
// You can use an arbitrary LangChain tool (see https://js.langchain.com/docs/integrations/tools/)
const generateRandomNumber = createTool(
({ min, max }) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
{
name: "GenerateRandomNumber",
description: "Generates a random number in the given interval.",
schema: z.object({
min: z.number().int().min(0),
max: z.number().int().min(0),
}),
},
);
const tool = new LangChainTool({
tool: generateRandomNumber,
});
const response = await tool.run(
// input to the tool
{
min: 1,
max: 10,
},
// (optional) LangChain's run options
{
timeout: 10 * 1000,
},
);
console.info(response);