40 lines
953 B
TypeScript
40 lines
953 B
TypeScript
import { tool } from "@langchain/core/tools";
|
|
import * as z from "zod";
|
|
|
|
|
|
// Define tools
|
|
const add = tool(({ a, b }) => a + b, {
|
|
name: "add",
|
|
description: "Add two numbers",
|
|
schema: z.object({
|
|
a: z.number().describe("First number"),
|
|
b: z.number().describe("Second number"),
|
|
}),
|
|
});
|
|
|
|
const multiply = tool(({ a, b }) => a * b, {
|
|
name: "multiply",
|
|
description: "Multiply two numbers",
|
|
schema: z.object({
|
|
a: z.number().describe("First number"),
|
|
b: z.number().describe("Second number"),
|
|
}),
|
|
});
|
|
|
|
const divide = tool(({ a, b }) => a / b, {
|
|
name: "divide",
|
|
description: "Divide two numbers",
|
|
schema: z.object({
|
|
a: z.number().describe("First number"),
|
|
b: z.number().describe("Second number"),
|
|
}),
|
|
});
|
|
|
|
// Augment the LLM with tools
|
|
export const arithmeticToolsByName = {
|
|
[add.name]: add,
|
|
[multiply.name]: multiply,
|
|
[divide.name]: divide,
|
|
};
|
|
|
|
//const arithmeticTools = Object.values(arithmeticToolsByName);
|