Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/aiPublic

The AI Toolkit for TypeScript. From the creators of Next.js, the AI SDK is a free open-source library for building AI-powered applications and agents

License

NotificationsYou must be signed in to change notification settings

vercel/ai

Repository files navigation

hero illustration

AI SDK

TheAI SDK is a TypeScript toolkit designed to help you build AI-powered applications using popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.

To learn more about how to use the AI SDK, check out ourAPI Reference andDocumentation.

Installation

You will need Node.js 18+ and pnpm installed on your local development machine.

npm install ai

Usage

AI SDK Core

TheAI SDK Core module provides a unified API to interact with model providers likeOpenAI,Anthropic,Google, and more.

You will then install the model provider of your choice.

npm install @ai-sdk/openai
@/index.ts (Node.js Runtime)
import{generateText}from'ai';import{openai}from'@ai-sdk/openai';// Ensure OPENAI_API_KEY environment variable is setconst{ text}=awaitgenerateText({model:openai('gpt-4o'),system:'You are a friendly assistant!',prompt:'Why is the sky blue?',});console.log(text);

AI SDK UI

TheAI SDK UI module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, Vue, and SolidJS.

@/app/page.tsx (Next.js App Router)
'use client';import{useChat}from'ai/react';exportdefaultfunctionPage(){const{ messages, input, handleSubmit, handleInputChange, status}=useChat();return(<div>{messages.map(message=>(<divkey={message.id}><div>{message.role}</div><div>{message.content}</div></div>))}<formonSubmit={handleSubmit}><inputvalue={input}placeholder="Send a message..."onChange={handleInputChange}disabled={status!=='ready'}/></form></div>);}
@/app/api/chat/route.ts (Next.js App Router)
import{streamText}from'ai';import{openai}from'@ai-sdk/openai';exportasyncfunctionPOST(req:Request){const{ messages}=awaitreq.json();constresult=streamText({model:openai('gpt-4o'),system:'You are a helpful assistant.',    messages,});returnresult.toDataStreamResponse();}

Templates

We've builttemplates that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.

Community

The AI SDK community can be found onGitHub Discussions where you can ask questions, voice ideas, and share your projects with other people.

Contributing

Contributions to the AI SDK are welcome and highly appreciated. However, before you jump right into it, we would like you to review ourContribution Guidelines to make sure you have smooth experience contributing to AI SDK.

Authors

This library is created byVercel andNext.js team members, with contributions from theOpen Source Community.


[8]ページ先頭

©2009-2025 Movatter.jp