Skip to content

vercel-labs/ai-sdk-tool-as-package-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI SDK Tool Package Template

A TypeScript package template for building and publishing AI SDK tools.

Installation

npm install ai-sdk-tool-as-package-template

Usage

import { getWeather } from "ai-sdk-tool-as-package-template"; import { generateText, gateway } from "ai"; const result = await generateText({ model: gateway("openai/gpt-4o-mini"), prompt: "What's the weather like in San Francisco?", tools: { getWeather: getWeather({ unit: "celsius" }), }, });

Options

You can configure options for your tool. The example implementation, getWeather tool, accepts an optional configuration object:

type WeatherToolOptions = { unit?: "fahrenheit" | "celsius"; };

Development

Setup

  1. Clone the repository
  2. Install dependencies:
pnpm install
  1. Create a .env file:
cp .env.example .env
  1. Add your Vercel AI Gateway (or other preferred provider) API key to .env

Testing

Test your tool locally:

pnpm test

Building

Build the package:

pnpm build

Publishing

Before publishing, update the package name in package.json to your desired package name.

The package automatically builds before publishing:

pnpm publish

Project structure

. ├── src/ │ ├── tools/ │ │ └── weather.ts # Example weather tool implementation │ ├── index.ts # Your tool exports │ └── test.ts # Test script ├── dist/ # Build output (generated) ├── package.json ├── tsconfig.json └── README.md 

License

MIT

About

Template for publishing your tools as an NPM package.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published