Skip to content

Instantly share code, notes, and snippets.

@ma-zah
Last active October 2, 2023 15:39
Show Gist options
  • Save ma-zah/4590c10464ac0062a91576ba89752a89 to your computer and use it in GitHub Desktop.
Save ma-zah/4590c10464ac0062a91576ba89752a89 to your computer and use it in GitHub Desktop.
On Type Safety In LangChain TS
import { z } from "zod";
import { StructuredTool } from "langchain/tools";
const clickSchema = z.object({
selector: z.string().describe("The query seletor to click on."),
});
const ClickSchema = z.infer<typeof clickSchema>;
class ClickTool extends StructuredTool<typeof clickSchema> {
schema = clickSchema;
name = "click";
description =
"left click on an element on a web page represented by a query selector";
protected _call(arg: ClickSchema): Promise<string> {
// We need to know that arg.selector is a thing here
return this.click(arg.selector);
}
private click(selector: string): Promise<string> {
// Add actual implementation of clicking
return Promise.resolve(`Clicked on ${selector}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment