Communitygithub.com

YepAPI/skills

AI 聊天助手技能:实现流式响应、对话窗口管理、RAG 模式及持久化存储。

skills 是什么?

此技能为构建 AI 聊天助手提供一套完整的解决方案,特别适合需要实现流式响应、高效上下文管理和检索增强生成(RAG)的开发场景。技能基于 Vercel AI SDK,在客户端使用 `useChat()` 钩子,在服务端使用 `streamText()` 函数,确保以 `text/event-stream` 格式流式返回结果,绝不缓冲完整响应。其上下文窗口管理策略支持自动裁剪最早消息以逼近 Token 限制,同时始终保留系统提示词。RAG 模式通过嵌入用户查询、执行向量搜索,并在用户消息前注入 Top-K 相关上下文来提升回答质量。此外,技能还包含自动滚动、加载动画、Markdown 渲染等 UI 细节,以及利用 `AbortController` 实现停止生成功能。消息历史在服务端持久化,支持跨会话恢复,API 调用遵循 YepAPI 的 POST `/v1/ai/chat` 规范。

兼容平台~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() 钩子,服务端使用 streamText()
  • 以 text/event-stream 格式流式响应——绝不先缓冲完整响应再发送
  • 消息格式:{ role: "user" | "assistant" | "system", content: string }
  • 上下文窗口管理:在接近 Token 限制时裁剪最旧的消息,始终保留系统提示词
  • RAG 模式:嵌入用户查询 → 向量搜索 → 在用户消息前注入 Top-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.

相关技能