forked from humanlayer/humanlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.ts
More file actions
59 lines (51 loc) · 1.14 KB
/
math.ts
File metadata and controls
59 lines (51 loc) · 1.14 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
import { tool, generateText } from "ai";
import { createOpenAI } from "@ai-sdk/openai";
import { humanlayer } from "humanlayer-vercel-ai-sdk";
import { z } from "zod";
const hl = humanlayer({
verbose: true,
});
const prompt = `multiply 2 and 5, then add 32 to the result`;
const add = tool({
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return args.a + args.b;
},
});
const multiplyTool = tool({
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return args.a * args.b;
},
});
// todo fix "type instantiation is excessively deep and possibly infinite" because...sure
const multiply = hl.requireApproval({ multiplyTool: multiplyTool });
const openai = createOpenAI({
compatibility: "strict",
});
const main = async () => {
const { text, steps } = await generateText({
model: openai("gpt-4o-mini"),
tools: {
add,
multiply,
},
maxSteps: 5,
prompt: prompt,
});
console.log(text);
};
main()
.then((result) => {
console.log(result);
})
.catch((e) => {
console.error(e);
process.exit(1);
});