Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vercel AI SDK Demo

A demonstration project for the Vercel AI SDK, showcasing how to build AI-powered applications with TypeScript and Node.js.

What is Vercel AI SDK?

The Vercel AI SDK is a powerful library for building AI-powered applications. It provides a set of functions for:

  • Generating text from language models (LLMs)
  • Streaming responses for better UX
  • Creating structured data from LLM outputs
  • Tool calling and function execution
  • Multi-modal capabilities
  • Support for multiple AI providers (OpenAI, Anthropic, Google, etc.)

Prerequisites

  • Node.js (v22 or higher)

Installation

Install dependencies:

npm install

Create a .env file with your API keys:

OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here
GOOGLE_GENERATIVE_AI_API_KEY=your_google_key_here

Running Examples

This repo contains examples demonstrating Vercel AI SDK capabilities:

# Basic examples
npm run lesson_1  # Basic text generation (generateText)
npm run lesson_2  # Streaming text responses (streamText)
npm run lesson_3  # Usage tracking and token counting

# Advanced features
npm run lesson_4  # System prompts for controlling AI behavior
npm run lesson_5  # Structured output with Zod schemas (JSON output)
npm run lesson_6  # Tool calling with weather API integration
npm run lesson_7  # Working with multiple model providers

Example Code

Here's a simple example of using the Vercel AI SDK:

import { generateText } from 'ai';
import { google } from '@ai-sdk/google';

// Initialize the model
const model = google('gemini-1.5-flash');

// Generate text
const result = await generateText({
  model,
  prompt: 'Explain the Vercel AI SDK in one sentence',
});

console.log(result.text);

Key Concepts

  • Language Models: Generate text using state-of-the-art LLMs
  • Streaming: Real-time text generation with streaming responses
  • Structured Data: Generate JSON and other structured outputs
  • Tool Calling: Enable LLMs to call functions and use tools
  • Provider Management: Use models from multiple AI providers

Resources

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages