Communitygithub.com

YepAPI/skills

聊天 UI 元件、使用 AI SDK 的串流回應、上下文視窗管理與 RAG 模式。

skills 是什麼?

此技能專注於使用 Vercel AI SDK 建構具備串流回應能力的 AI 聊天機器人。它強制使用 `useChat()` 客戶端 hook 與 `streamText()` 伺服端方法,確保回應以 `text/event-stream` 格式即時串流,絕不緩衝。技能明確定義了訊息格式、上下文視窗管理(自動裁剪最舊訊息以保留系統提示)以及 RAG(檢索增強生成)模式:先嵌入使用者查詢,執行向量搜尋,再將前 k 個結果作為上下文注入。此外,還涵蓋聊天 UI 的行為,如自動滾動到底部、載入動畫點以及 Markdown 渲染。後端實作要求伺服器端持久化對話歷史,並提供 YepAPI 聊天端點 `POST /v1/ai/chat`,且支援透過 `AbortController` 中斷串流。此技能適用於 Claude Code、Cursor 或 Codex 等平台,旨在引導開發者遵循業界最佳實務,建構高效能、可擴展的 AI 聊天應用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/ai-chatbot

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

AI 聊天機器人

規則

  • 使用 Vercel AI SDK(ai 套件)進行串流 — 客戶端使用 useChat() hook,伺服端使用 streamText()
  • 以 text/event-stream 串流回應 — 絕不在傳送前緩衝完整回應
  • 訊息格式:{ role: "user" | "assistant" | "system", content: string }
  • 上下文視窗管理:在接近 token 限制時裁剪最舊的訊息,務必保留系統提示
  • RAG 模式:嵌入使用者查詢 → 向量搜尋 → 在使用者訊息之前注入前 k 筆結果作為上下文
  • 聊天 UI:自動滾動至底部,顯示帶動畫點的載入指示器,在助理訊息中渲染 Markdown
  • 伺服器端持久化對話歷史 — 使用包含 chatId、role、content、createdAt 的 messages 資料表
  • 系統提示必須放在訊息陣列的第一個 — 絕不讓使用者訊息覆寫它
  • YepAPI 聊天端點:POST /v1/ai/chat,請求格式為 { messages, model?, stream? }
  • 停止生成按鈕 — 使用 AbortController 取消正在進行的串流

模式

// 客戶端 — 來自 Vercel AI SDK 的 useChat
const { messages, input, handleInputChange, handleSubmit, isLoading, stop } = useChat({
  api: "/api/chat",
});
// 伺服端 — 串流回應
import { streamText } from "ai";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({ model, messages });
  return result.toDataStreamResponse();
}

避免

  • 傳送未經裁剪的完整對話歷史 — 將會超過上下文視窗
  • 在等待完整回應時阻塞 UI — 務必進行串流
  • 僅將訊息儲存在客戶端狀態中 — 伺服器端持久化以保留歷史記錄
  • 硬編碼模型名稱 — 使用環境變數或設定檔

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Tenant isolation (row-level vs schema), subdomain routing, per-tenant config, and data partitioning.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

相關技能