✅ 一、学习路线图(从零到上线)
我把大模型应用开发拆成 6 个阶段:
阶段 1:基础能力(Node.js + TS)
- JavaScript ES6+
- TypeScript(类型、泛型、类、装饰器)
- Node.js 基础:async/await、fs、path、events
- npm / pnpm 基本指令
阶段 2:Nest.js 后端基础
- 项目创建(CLI)
- 模块、控制器、服务
- 依赖注入(DI)
- DTO + Pipe
- Interceptor
- 全局异常过滤
- Swagger 文档生成
阶段 3:数据库 + 服务端能力
- TypeORM / Prisma
- MySQL / Postgres
- Redis(缓存 + 限流)
- 登录鉴权(JWT)
- 文件上传、HTTP 请求
- WebSocket / SSE(AI 流式响应)
阶段 4:大模型核心能力(重点)
- OpenAI / DeepSeek / 通义 API 调用
- Chat Completions / Responses
- Function Calling(智能体最重要)
- JSON 模式(用 AI 准确生成结构化数据)
- 多模态(图片理解 / 生成)
- 提示词工程 Prompt Engineering
阶段 5:AI 智能体(Agent)开发能力
- Agent 工作流(workflow)
- Memory(会话记忆)
- 工具调用(Tools)
- LangChain.js / LangGraph.js
- 多智能体协作
- 系统角色 Prompt 设计
- 决策 Agent(Planner + Executor)
阶段 6:RAG(检索增强生成)知识库能力
- 文档切片(chunking)
- 文档解析(PDF/Word/网页)
- Embedding(向量化)
- 向量数据库(Milvus、Pinecone、Qdrant、Chroma)
- 混合检索(关键词 + 向量)
- RAG Pipeline(召回 → 重写 → 生成)
阶段 7:部署与工程化
- Docker 容器化
- Nginx
- Linux 基本运维
- 日志系统(Winston/Pino)
- 监控(Sentry)
- CI/CD(GitHub Actions)
🧭 二、详细学习顺序(逐步升级技能)
你只要按照下面这个顺序走 1~2 个月就能开发 AI 智能体项目。
📌 Step 1:TypeScript 基础(2 天)
掌握:
- interface & type
- class
- 泛型
- 装饰器(Nest.js 会大量使用)
📌 Step 2:Node.js 核心(2–4 天)
重点:
- async/await
- fs / path
- HTTP 请求(axios)
- 事件循环
📌 Step 3:Nest.js 基础(7 天)
掌握:
- Controller、Service
- Module + DI
- CRUD
- DTO + Pipe
- Interceptor(日志 / 响应包装)
- Swagger(API 文档)
- 全局异常过滤
📌 Step 4:OpenAI / DeepSeek 接口(3–5 天)
掌握:
- Chat API
- 流式输出
- Function Calling (工具调用)
- JSON mode
📌 Step 5:智能体框架(10–14 天)
- LangChain.js
- LangGraph.js(打造真正的 Agent Workflow)
- Memory(会话记忆)
- Agent + Tools(工具调用)
- 多智能体协作(Agent Team)
📌 Step 6:RAG(10–20 天)
- Embedding
- 向量数据库(Milvus / Qdrant / Pinecone / Chroma)
- 文档解析
- Query 重写
- 混合检索
- 最终构建一个知识库问答系统
📌 Step 7:部署(2–5 天)
- Docker
- 服务器部署
- Nginx 反向代理
- CI/CD
🧩 三、智能体 Demo(Nest.js + OpenAI)
1. 安装依赖
1npm install openai 2
2. 新建 AIService(核心智能体服务)
1// ai.service.ts 2import { Injectable } from '@nestjs/common'; 3import OpenAI from 'openai'; 4 5@Injectable() 6export class AIService { 7 private client = new OpenAI({ 8 apiKey: process.env.OPENAI_API_KEY, 9 }); 10 11 async ask(prompt: string) { 12 const response = await this.client.chat.completions.create({ 13 model: "gpt-4o-mini", 14 messages: [{ role: "user", content: prompt }], 15 }); 16 17 return response.choices[0].message.content; 18 } 19} 20
3. Controller
1// ai.controller.ts 2import { Controller, Get, Query } from '@nestjs/common'; 3import { AIService } from './ai.service'; 4 5@Controller('ai') 6export class AIController { 7 constructor(private aiService: AIService) {} 8 9 @Get('ask') 10 async ask(@Query('q') q: string) { 11 return await this.aiService.ask(q); 12 } 13} 14
4. Function Calling(智能体最重要)
1const res = await client.chat.completions.create({ 2 model: "gpt-4o-mini", 3 messages: [ 4 { role: "user", content: "给我查询北京今天的天气" } 5 ], 6 tools: [ 7 { 8 type: "function", 9 function: { 10 name: "getWeather", 11 description: "获取指定城市的天气", 12 parameters: { 13 type: "object", 14 properties: { 15 city: { type: "string" } 16 }, 17 required: ["city"] 18 } 19 } 20 } 21 ] 22}); 23
🧰 四、AI 插件模板(OpenAI Plugin / Intelligent Agent Tool)
你可以做一个标准插件让 ChatGPT 调用你的 API。
目录结构
1/well-known/ai-plugin.json 2/openapi.yaml 3/api/your-endpoint 4
ai-plugin.json 示例
1{ 2 "schema_version": "v1", 3 "name_for_human": "My AI Tools", 4 "name_for_model": "my_tools", 5 "description_for_model": "提供天气查询等工具", 6 "auth": { "type": "none" }, 7 "api": { 8 "type": "openapi", 9 "url": "https://your-domain.com/openapi.yaml" 10 } 11} 12
openapi.yaml 示例
1openapi: 3.0.1 2info: 3 title: My AI API 4paths: 5 /weather: 6 get: 7 summary: 获取天气 8 parameters: 9 - name: city 10 in: query 11 required: true 12 schema: 13 type: string 14
完成后即可被 ChatGPT / Claude 作为工具调用。
📚 五、RAG 示例项目(从零到可用)
1. 解析文档(PDF / txt)
1import * as pdfParse from 'pdf-parse'; 2 3const data = await pdfParse(fileBuffer); 4
2. 文档切片
1function chunkText(text: string, size = 500) { 2 let chunks = []; 3 for (let i = 0; i < text.length; i += size) { 4 chunks.push(text.slice(i, i + size)); 5 } 6 return chunks; 7} 8
3. 向量化 Embedding
1const embedding = await client.embeddings.create({ 2 model: "text-embedding-3-small", 3 input: chunk 4}); 5
4. 存入向量数据库(以 Chroma 为例)
1import { ChromaClient } from "chromadb"; 2
5. 检索召回
1const results = await collection.query({ 2 query_embeddings: [queryEmbedding], 3 n_results: 5 4}); 5
6. 让大模型根据召回内容回答
1await llm.chat.completions.create({ 2 model: "gpt-4o-mini", 3 messages: [ 4 { role: "system", content: "你是一个知识库助手" }, 5 { role: "user", content: question }, 6 { role: "assistant", content: retrievedText } 7 ] 8}); 9
《node.js和nest.js做智能体开发需要会哪些东西》 是转载文章,点击查看原文。
