-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtools.js
More file actions
107 lines (99 loc) · 1.92 KB
/
tools.js
File metadata and controls
107 lines (99 loc) · 1.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { tool } from "@langchain/core/tools";
import axios from "axios";
import { z } from "zod";
// An Example Multiply tool
export const multiply = tool(
({ a, b }) => {
return a * b;
},
{
name: "multiply",
description: "Multiply two numbers",
schema: z.object({
a: z.number(),
b: z.number(),
}),
}
);
export const divide = tool(
({ a, b }) => {
return a / b;
},
{
name: "divide",
description: "Divide two numbers",
schema: z.object({
a: z.number(),
b: z.number(),
}),
}
);
export const add = tool(
({ a, b }) => {
return a + b;
},
{
name: "add",
description: "Add two numbers",
schema: z.object({
a: z.number(),
b: z.number(),
}),
}
);
export const subtract = tool(
({ a, b }) => {
return a - b;
},
{
name: "subtract",
description: "Subtract two numbers",
schema: z.object({
a: z.number(),
b: z.number(),
}),
}
);
// Some fun tools
// -- Random number
export const random = tool(
({ min, max }) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
{
name: "random",
description: "Generate a random number between min and max",
schema: z.object({
min: z.number(),
max: z.number(),
}),
}
);
// -- Insult API
export const insult = tool(
async () => {
const response = await axios.get(
'https://evilinsult.com/generate_insult.php?lang=en&type=json'
);
console.log(response.data)
return response.data.insult;
},
{
name: "insult",
description: "Generate an insult. No arguments required.",
}
);
export const qoute = tool(
async () => {
//https://api.quotable.io
const response = await axios.get(
'https://api.quotable.io/random'
);
console.log(response.data)
return response.data.content;
},
{
name: "qoute",
description: "Generate a qoute. No arguments required.",
}
)