智能客服 AI 实践
思路:引入 deepseek 大模型,然后通过 API 接口进行调用,实现智能客服功能。
智能客服 AI MVP 方案
🎯 目标
基于 DeepSeek 大模型,实现一个最小可用的 智能客服 AI,通过 API 接口 接收用户问题,并返回智能回答。
📌 MVP 实现步骤
1️⃣ 部署 DeepSeek-Chat
✅ 方式 1:使用 Ollama
如果你能顺利安装 ollama
,可以使用以下命令拉取并运行:
bash
ollama pull deepseek-chat
ollama run deepseek-chat
然后测试:
bash
ollama run deepseek-chat "你好,你是做什么的?"
如果返回正常说明模型部署成功。
✅ 方式 2:手动下载 DeepSeek-Chat
如果 ollama pull
失败,可以手动下载 .gguf
模型,并导入:
- 访问 Hugging Face 下载
.gguf
文件 - 放入
C:\Users\Administrator\.ollama\models
- 运行:bash
ollama create deepseek-chat C:\Users\Administrator\.ollama\models\deepseek-chat.gguf ollama run deepseek-chat
✅ 方式 3:使用 Docker 部署
bash
docker run -d -p 11434:11434 ollama/ollama
ollama pull deepseek-chat
ollama run deepseek-chat
2️⃣ 搭建 API 接口
使用 Node.js
+ Express
搭建 HTTP API,让前端可以调用。
安装 Express
bash
mkdir deepseek-chat-api && cd deepseek-chat-api
npm init -y
npm install express cors axios body-parser
创建 server.js
javascript
const express = require("express");
const axios = require("axios");
const cors = require("cors");
const app = express();
app.use(express.json());
app.use(cors());
const OLLAMA_API_URL = "http://localhost:11434/api/generate"; // Ollama API 地址
// 处理用户问题的 API
app.post("/ask", async (req, res) => {
const { question } = req.body;
if (!question) return res.status(400).json({ error: "请输入问题" });
try {
const response = await axios.post(OLLAMA_API_URL, {
model: "deepseek-chat",
prompt: question,
stream: false,
});
res.json({ answer: response.data.response });
} catch (error) {
console.error("请求出错:", error.message);
res.status(500).json({ error: "AI 服务器异常" });
}
});
app.listen(3000, () => {
console.log("智能客服 API 运行在 http://localhost:3000");
});
然后运行:
bash
node server.js
测试:
bash
curl -X POST http://localhost:3000/ask -H "Content-Type: application/json" -d '{"question":"你是谁?"}'
3️⃣ 搭建前端(可选)
可以使用 Vue.js / React,通过 fetch
请求 API:
javascript
fetch("http://localhost:3000/ask", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ question: "你好!" }),
})
.then((res) => res.json())
.then((data) => console.log("回答:", data.answer));
🔧 技术细节
功能 | 技术方案 |
---|---|
模型部署 | DeepSeek-Chat + Ollama |
API 服务 | Node.js + Express |
前端 (可选) | Vue.js / React |
数据库 (可选) | MongoDB / SQLite(存储用户问答记录) |
🚀 进阶优化
- 多轮对话支持:让 AI 记住上下文,可以引入 Redis 存储对话历史
- 语音客服:结合
whisper
语音识别,实现语音输入 - 知识库增强:接入 FAQ 文档,提高回答准确性
👉 你可以先完成 MVP,然后再逐步扩展!如果有问题,欢迎交流! 🎯
- https://www.163.com/dy/article/JO9CK1Q405387208.html
- https://forum.cocos.org/t/topic/165431
- https://ollama.com/download
- https://ollama.com/library/deepseek-r1/tags
- https://huggingface.co/TheBloke/deepseek-llm-67b-chat-GPTQ
- https://chatboxai.app/zh
- https://github.com/deepseek-ai/DeepSeek-R1
- https://ollama.com/search