Last active
November 14, 2024 21:52
-
-
Save jtmuller5/9c212e7ada591ef5802a30eb5882b7af to your computer and use it in GitHub Desktop.
Snippet for creating tools for AI function calling
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
Show hidden characters
"AI Tool Template": { | |
"prefix": "aiTool", | |
"body": [ | |
"import { ToolResult } from './AITools';", | |
"import { tool } from 'ai';", | |
"import { z } from 'zod';", | |
"", | |
"export interface ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}Params {", | |
" input: string;", | |
"}", | |
"", | |
"type ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}Result = ToolResult<{", | |
" output: string;", | |
"}>;", | |
"", | |
"export async function ${TM_FILENAME_BASE/(.*)/${1:/camelcase}/}({", | |
" input,", | |
"}: ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}Params): Promise<${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}Result> {", | |
" return {", | |
" data: {", | |
" output: 'success',", | |
" },", | |
" saveToMemory: true,", | |
" error: null,", | |
" };", | |
"}", | |
"", | |
"export const ${TM_FILENAME_BASE/(.*)/${1:/camelcase}/}Tool = tool({", | |
" description: 'Tool call',", | |
" parameters: z.object({", | |
" input: z", | |
" .string()", | |
" .describe('The output'),", | |
" }),", | |
" execute: async ({ input }) => {", | |
" return await ${TM_FILENAME_BASE/(.*)/${1:/camelcase}/}({ input });", | |
" },", | |
"});" | |
], | |
"description": "Creates an AI Tool for function calling" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment