npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ai-functions

v0.3.0

Published

A powerful TypeScript library for building AI-powered applications with template literals and structured outputs

Readme

ai-functions

npm version License: MIT

A powerful TypeScript library for building AI-powered applications with template literals and structured outputs. Uses ai SDK with OpenAI gpt-4o by default.

Features

  • 🚀 Template literal API for natural AI prompts
  • 🔄 Async iterator support for streaming responses
  • 📝 Structured output generation with Zod schemas
  • 🎯 Type-safe API with full TypeScript support
  • ⚡️ Built on ai SDK for streaming & object generation
  • 🔍 Support for various output formats (objects, arrays, enums)

Installation

pnpm add ai-functions

Usage

Basic Template Literals

import { ai, list } from 'ai-functions'

// Simple text generation
const text = ai`write a blog post in markdown starting with '# ${title}'`

// Complex objects/arrays dumped to YAML
const summary = ai`Summarize the itinerary: ${itinerary}`

// Basic list generation
const things = await list`fun things to do in Miami`
console.log(things)

// Using async iterator
for await (const thing of list`fun things to do in Miami`) {
  console.log(thing)
}

// Structured output
const categorizeProduct = ai.categorizeProduct({
  productType: 'App | API | Marketplace | Platform | Packaged Service | Professional Service | Website',
  customer: 'ideal customer profile in 3-5 words',
  solution: 'describe the offer in 4-10 words',
  description: 'website meta description',
})

const product = await categorizeProduct({ domain: name })

Configuration

Specifying the model

By default ai-functions uses the openai provider from the ai SDK. You can specify any openai model name as a string.

const text = ai`write a blog post in markdown starting with "# ${title}"`({ model: 'gpt-4o' })

Or you can pass in any other provider compatible with the ai SDK.

import { anthropic } from '@ai-sdk/anthropic'

const text = ai`write a function in TypeScript called ${name}`({ model: anthropic('claude-3-5-sonnet-20241022') })

Specifying other options

You can pass in any other options supported by the ai SDK, like system, temperature, maxTokens, etc.

const things = await list`fun things to do in ${city}`({ system: 'You are an expert tour guide', temperature: 0.2 })

Composable Functions & Workflows

const listBlogPosts = (count, topic) => list`${count} blog post titles about ${topic}`
const writeBlogPost = (title) => ai`write a blog post in markdown starting with '# ${title}'`

async function* writeBlog(count, topic) {
  for await (const title of listBlogPosts(count, topic)) {
    const content = await writeBlogPost(title)
    yield { title, content }
  }
}

for await (const post of writeBlog(25, 'future of car sales')) {
  console.log({ post })
}

Concurrency

you can specify the concurrency option to limit the number of concurrent requests.

activities.map(async (activity) => {
  const result = await ai`write a paragraph overview of ${activity}`({ concurrency: 5 })
})

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Build the package
pnpm build

# Lint the code
pnpm lint

# Format the code
pnpm format

Contributing

Please read our Contributing Guide to learn about our development process and how to propose bugfixes and improvements.

License

MIT © Drivly

Dependencies

This package uses the following key dependencies:

  • ai SDK for AI model integration
  • Defaults to @ai-sdk/openai provider
  • TypeScript for static typing
  • Zod for schema validation
  • Vitest for testing
  • ESLint for linting
  • Prettier for code formatting