-
-
Save ma-zah/4590c10464ac0062a91576ba89752a89 to your computer and use it in GitHub Desktop.
On Type Safety In LangChain TS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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