Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Last active November 14, 2024 21:52
Show Gist options
  • Save jtmuller5/9c212e7ada591ef5802a30eb5882b7af to your computer and use it in GitHub Desktop.
Save jtmuller5/9c212e7ada591ef5802a30eb5882b7af to your computer and use it in GitHub Desktop.
Snippet for creating tools for AI function calling
"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