forked from humanlayer/humanlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuman-as-tool.ts
More file actions
50 lines (42 loc) · 912 Bytes
/
human-as-tool.ts
File metadata and controls
50 lines (42 loc) · 912 Bytes
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
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 ?R?@)GSA
contact a human if you need help`;
const multiply = tool({
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return args.a * args.b;
},
});
const contactHuman = hl.humanAsTool();
const openai = createOpenAI({
compatibility: "strict",
});
const main = async () => {
const { text, steps } = await generateText({
model: openai("gpt-4o-mini"),
tools: {
multiply,
contactHuman,
},
maxSteps: 5,
prompt: prompt,
});
console.log(text);
};
main()
.then((result) => {
console.log(result);
})
.catch((e) => {
console.error(e);
process.exit(1);
});