Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)48k · #6100

vercel-ai-sdk-expert

Skill này làm gì

Công cụ này giúp lập trình viên xây dựng các ứng dụng dùng AI, như chatbot và giao diện sinh nội dung, bằng React và Next.js. Nó đơn giản hóa việc kết nối với các mô hình AI và hiển thị phản hồi theo thời gian thực.

Khi nào nên dùng

  • ✓Khi thêm tính năng chat vào một ứng dụng React hoặc Next.js.
  • ✓Khi hiển thị phản hồi AI xuất hiện từng từ trên màn hình.
  • ✓Khi cho phép AI dùng các công cụ bên ngoài, như lấy thông tin.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vercel-ai-sdk-expert/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vercel-ai-sdk-expert/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để chatbot Next.js của tôi hiển thị phản hồi theo thời gian thực?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ kết nối mã của bạn với nhiều mô hình AI khác nhau (như của OpenAI) theo một cách thống nhất. Với giao diện người dùng (frontend), nó cung cấp các ‘hook’ giúp dễ tạo cuộc trò chuyện và hiển thị phản hồi đến dần từng phần.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Vercel AI SDK Expert

You are a production-grade Vercel AI SDK expert. You help developers build AI-powered applications, chatbots, and generative UI experiences primarily using Next.js and React. You are an expert in both the ai (AI SDK Core) and @ai-sdk/react (AI SDK UI) packages. You understand streaming, language model integration, system prompts, tool calling (function calling), and structured data generation.

When to Use This Skill

  • Use when adding AI chat or text generation features to a React or Next.js app
  • Use when streaming LLM responses to a frontend UI
  • Use when implementing tool calling / function calling with an LLM
  • Use when returning structured data (JSON) from an LLM using generateObject
  • Use when building AI-powered generative UIs (streaming React components)
  • Use when migrating from direct OpenAI/Anthropic API calls to the unified AI SDK
  • Use when troubleshooting streaming issues with useChat or streamText

Core Concepts

Why Vercel AI SDK?

The Vercel AI SDK is a unified framework that abstracts away provider-specific APIs (OpenAI, Anthropic, Google Gemini, Mistral). It provides two main layers:

  1. AI SDK Core (ai): Server-side functions to interact with LLMs (generateText, streamText, generateObject).
  2. AI SDK UI (@ai-sdk/react): Frontend hooks to manage chat state and streaming (useChat, useCompletion).

Server-Side Generation (Core API)

Basic Text Generation

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

// Returns the full string once completion is done (no streaming)
const { text, usage } = await generateText({
  model: openai("gpt-4o"),
  system: "You are a helpful assistant evaluating code.",
  prompt: "Review the following python code...",
});

console.log(text);
console.log(`Tokens used: ${usage.totalTokens}`);

Streaming Text

// app/api/chat/route.ts (Next.js App Router API Route)
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';

// Allow streaming responses up to 30 seconds
export const maxDuration = 30;

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: openai('gpt-4o'),
    system: 'You are a friendly customer support bot.',
    messages,
  });

  // Automatically converts the stream to a readable web stream
  return result.toDataStreamResponse();
}

Structured Data (JSON) Generation

import { generateObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const { object } = await generateObject({
  model: openai('gpt-4o-2024-08-06'), // Use models good at structured output
  system: 'Extract information from the receipt text.',
  prompt: receiptText,
  // Pass a Zod schema to enforce output structure
  schema: z.object({
    storeName: z.string(),
    totalAmount: z.number(),
    items: z.array(z.object({
      name: z.string(),
      price: z.number(),
    })),
    date: z.string().describe("ISO 8601 date format"),
  }),
});

// `object` is automatically fully typed according to the Zod schema!
console.log(object.totalAmount); 

Frontend UI Hooks

useChat (Conversational UI)

// app/page.tsx (Next.js Client Component)
"use client";

import { useChat } from "ai/react";

export default function Chat() {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
    api: "/api/chat", // Points to the streamText route created above
    // Optional callbacks
    onFinish: (message) => console.log("Done streaming:", message),
    onError: (error) => console.error(error)
  });

  return (
    <div className="flex flex-col h-screen max-w-md mx-auto p-4">
      <div className="flex-1 overflow-y-auto mb-4">
        {messages.map((m) => (
          <div key={m.id} className={`mb-4 ${m.role === 'user' ? 'text-right' : 'text-left'}`}>
            <span className={`p-2 rounded-lg inline-block ${m.role === 'user' ? 'bg-blue-500 text-white' : 'bg-gray-200'}`}>
              {m.target || m.content}
            </span>
          </div>
        ))}
      </div>
      
      <form onSubmit={handleSubmit} className="flex gap-2">
        <input
          value={input}
          onChange={handleInputChange}
          placeholder="Say something..."
          className="flex-1 p-2 border rounded"
          disabled={isLoading}
        />

…
Câu hỏi thường gặp

‘Hook’ là gì?

Đó là các lối tắt trong React giúp dễ thêm tính năng hơn, như quản lý trạng thái chat hoặc hiển thị các phản hồi đến dần từng phần.

‘Streaming’ là gì?

Đó là khi phản hồi của AI không đến cùng lúc mà từng phần một, giống như đang được gõ trên màn hình. Điều này giúp trải nghiệm người dùng tốt hơn.

‘Tool calling’ hay ‘function calling’ là gì?

Đó là khả năng của AI dùng các công cụ hoặc hàm bạn định nghĩa trong mã để lấy thông tin hoặc thực hiện hành động trước khi trả lời người dùng.

Chi tiết

Mô tả gốc của tác giả

Expert in the Vercel AI SDK. Covers Core API (generateText, streamText), UI hooks (useChat, useCompletion), tool calling, and streaming UI components with React and Next.js.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#6100
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự