-
Checked other resources
Commit to Help
Example Codeimport { z } from "zod";
import { tool } from "@langchain/core/tools";
const adderSchema = z.object({
a: z.number(),
b: z.number(),
});
const adderTool = tool(
async (input): Promise<string> => {
const sum = input.a + input.b;
return `The sum of ${input.a} and ${input.b} is ${sum}`;
},
{
name: "adder",
description: "Adds two numbers together",
schema: adderSchema,
}
); DescriptionI am moving my codbase from python to typescript, but I having a small problem with tool typing.
Running the code is working fine, but I wonder what is the problem here? System Infonpm
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The error you're encountering, "Property 'a' does not exist on type 'ZodObject'", is likely due to TypeScript not inferring the correct type for the To resolve this, you can explicitly type the import { z } from "zod";
import { tool } from "@langchain/core/tools";
const adderSchema = z.object({
a: z.number(),
b: z.number(),
});
type AdderInput = z.infer<typeof adderSchema>;
const adderTool = tool(
async (input: AdderInput): Promise<string> => {
const sum = input.a + input.b;
return `The sum of ${input.a} and ${input.b} is ${sum}`;
},
{
name: "adder",
description: "Adds two numbers together",
schema: adderSchema,
}
); By using |
Beta Was this translation helpful? Give feedback.
-
Okay, the error occurs if there are multiple versions of zod in the project
Make sure to only have a single versino |
Beta Was this translation helpful? Give feedback.
Okay, the error occurs if there are multiple versions of zod in the project
Make sure to only have a single versino