# 🚀 AI 客服系统 - 快速开始 ## 目录结构 ``` ai-chatbot-service/ ├── app/ │ ├── __init__.py │ ├── main.py # FastAPI 主服务 (端口 8890) │ ├── chatbot.py # LangGraph 客服逻辑 │ ├── knowledge.py # 知识库管理 │ └── config.py # 配置文件 ├── static/ # 静态文件 ├── templates/ │ └── index.html # 聊天界面 ├── knowledge_base/ # 知识库文档 │ └── sample_faq.txt # 示例 FAQ ├── data/ # 数据库文件 ├── requirements.txt ├── start.sh # 启动脚本 └── README.md ``` ## 快速开始 ### 1. 配置 API Key 编辑 `app/config.py`: ```python # 方案1: 直接修改配置 LLM_API_KEY = "your-deepseek-api-key" # DeepSeek API Key # 或者使用 OpenAI # LLM_API_KEY = "your-openai-key" # LLM_BASE_URL = "https://api.openai.com" # LLM_MODEL = "gpt-3.5-turbo" ``` **或者设置环境变量(推荐):** ```bash export DEEPSEEK_API_KEY="your-key" export OPENAI_API_KEY="your-key" # 用于嵌入模型 ``` ### 2. 准备知识库 将 FAQ 文档放入 `knowledge_base/` 目录,支持格式: - `.txt` - 文本文件 - `.md` - Markdown 文件 - `.pdf` - PDF 文件 ### 3. 启动服务 ```bash # 方式1: 使用启动脚本 ./start.sh # 方式2: 手动启动 cd app python3 main.py ``` 访问: http://localhost:8890 ### 4. 测试 API ```bash # 发送消息 curl -X POST http://localhost:8890/chat \ -H "Content-Type: application/json" \ -d '{"message": "你们的工作时间是?", "session_id": "test123"}' # 获取历史记录 curl http://localhost:8890/history/test123 ``` ## 系统要求 - Python 3.9+ - 内存: 2GB+ (推荐 4GB) - 无需 GPU - 依赖 LLM API (DeepSeek/OpenAI) ## 端口使用 服务运行在 **8890** 端口,确保端口未被占用。 ## 常见问题 **Q: 需要 API Key 吗?** A: 只需要 DeepSeek API Key(大语言模型),嵌入模型使用免费的 HuggingFace 模型,本地 CPU 运行,无需额外 Key。 **Q: 如何添加更多知识?** A: 将文档放入 `knowledge_base/` 目录,重启服务会自动加载。 **Q: 支持多人同时聊天吗?** A: 支持!每个会话有独立的 session_id,互不影响。