baodan/docs/部署指南.md

129 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# BaoDan 源码集成指南
## 一、BaoDan 版本要求
- BaoDan 版本:>= 1.0.0(社区版)
- Python 版本3.12
- 数据库PostgreSQL 15+
- Redis7+
## 二、目录结构
```
项目根目录/
├── baodan-main/ # BaoDan 源码git clone
│ ├── api/
│ │ ├── main.py # ★ 你需要改的文件(加 5 行)
│ │ ├── core/ # BaoDan 核心(不改)
│ │ └── ...
│ └── web/
│ └── .env.local # ★ 你需要改的文件(加 1 行)
├── api/
│ └── insurance/ # ★ 你的全部自研代码
├── frontend/ # ★ 你的 Vue 前端
└── docker-compose.yml
```
## 三、修改 BaoDan main.py仅 5 行)
`baodan-main/api/main.py` 文件末尾添加:
```python
# ======== 保险智能客服系统 - 路由注册 ========
try:
from insurance.routes import register_insurance_routes
register_insurance_routes(app)
except ImportError as e:
import logging
logging.warning(f"Insurance module not loaded: {e}")
# ======== END 保险智能客服系统 ========
```
## 四、修改 BaoDan web/.env.local仅 1 行)
`baodan-main/web/.env.local` 中添加:
```
NEXT_PUBLIC_ALLOW_EMBED=true
```
如果需要允许 iframe 嵌入到你的域名:
```
NEXT_PUBLIC_ALLOW_EMBED=true
NEXT_PUBLIC_APP_URL=https://your-domain.com
```
## 五、自研代码挂载方式
### 方式一Docker Volume 挂载(推荐)
`docker-compose.yml` 中:
```yaml
baodan-api:
image: langgenius/baodan-api:latest
volumes:
- ./api/insurance:/app/api/insurance # 挂载自研代码
```
### 方式二:开发模式直接复制
```bash
# 开发时,将 insurance 目录复制到 BaoDan api 目录下
cp -r api/insurance/ baodan-main/api/insurance/
```
## 六、验证集成
```bash
# 1. 启动 BaoDan
cd baodan-main && docker compose up -d
# 2. 检查 insurance 模块是否加载
curl http://localhost:5001/api/health
# 预期:{"status": "ok"}
# 3. 测试认证接口
curl -X POST http://localhost:5001/api/auth/password-login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "test123"}'
# 4. 测试企微回调
curl http://localhost:5001/api/wecom/callback
```
## 七、BaoDan Python 模块 Import 路径
以下 import 路径需要根据实际 BaoDan 版本验证:
```python
# 数据库连接
from extensions.ext_database import db
# Redis 连接
from extensions.ext_redis import redis_client
# BaoDan 模型(用于 LLM 调用)
# from core.model_runtime.model_manager import ModelManager
# BaoDan Workflow
# from core.workflow.workflow_engine import WorkflowEngine
# BaoDan RAG 检索
# from core.rag.retrieval.dataset_retrieval import DatasetRetrieval
```
> 注意:直接 import BaoDan 内部模块有版本耦合风险。建议优先通过 BaoDan HTTP API/v1/chat-messages 等)调用,
> 仅在性能关键路径上使用 Python 直接调用。
## 八、BaoDan API Key 获取
在 BaoDan 后台 → 应用设置 → API 访问中获取:
| Key 类型 | 用途 | 存放环境变量 |
|---------|------|-------------|
| App API Key | 对话接口 | `BAODAN_CHAT_APP_API_KEY` |
| Workflow API Key | 推荐方案 | `BAODAN_WORKFLOW_APP_API_KEY` |
| Dataset API Key | 知识库管理 | `BAODAN_DATASET_API_KEY` |