MBE 开发者快速入门
5 分钟快速开始
1. 环境要求
- Docker Desktop (已安装并运行)
- Git
- Python 3.11+
- PowerShell 或 CMD
2. 启动开发环境
# 进入项目目录
cd D:\Mises\mises-behavior-engine
# 启动开发环境
.\start-dev.bat
# 或使用管理脚本
.\mbe.ps1 dev start
3. 验证服务
# 等待 60 秒后测试
Invoke-WebRequest http://localhost:8001/ -UseBasicParsing
4. 开始开发
# 修改代码后重启服务
docker-compose -f docker-compose.dev.yml restart mbe-api-dev
环境概览
┌─────────────────────────────────────────────────────────────────┐
│ MBE 开发环境 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Gitea │ │ MBE API │ │ Cloudflare │ │
│ │ Git 仓库 │───>│ 开发版 │───>│ Tunnel │ │
│ │ :3000 │ │ :8001 │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────┐ ┌──────────────┐ │
│ │ PostgreSQL│ │ mbe-dev. │ │
│ │ Redis │ │ hi-maker.com │ │
│ └──────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
常用地址
| 服务 | 本地地址 | 公网地址 |
|---|---|---|
| 开发 API | http://localhost:8001 | https://mbe-dev.hi-maker.com |
| 生产 API | http://localhost:8000 | https://mbe.hi-maker.com |
| Gitea | http://localhost:3000 | - |
| API 文档 | http://localhost:8001/docs | https://mbe-dev.hi-maker.com/docs |
常用命令速查
服务管理
# 启动
.\mbe.ps1 dev start # 开发环境
.\mbe.ps1 prod start # 生产环境
# 停止
.\mbe.ps1 dev stop
.\mbe.ps1 prod stop
# 重启
.\mbe.ps1 dev restart
.\mbe.ps1 prod restart
# 查看状态
.\mbe.ps1 status
# 查看日志
.\mbe.ps1 dev logs
docker logs mbe-api-dev --tail 100 -f
Git 操作
# 拉取代码
git pull origin main
# 提交代码
git add .
git commit -m "feat: 新功能"
git push origin main
# 创建分支
git checkout -b feature/my-feature
测试
# 运行测试
pytest tests/ -v
# 运行特定测试
pytest tests/test_api.py::TestChatAPI -v
# 快速健康检查
pytest tests/test_api.py::TestHealthCheck -v
部署
# 快速部署
python scripts/quick_deploy.py
# 查看部署状态
Invoke-WebRequest http://localhost:8001/webhook/deploy/status -UseBasicParsing
# 查看部署日志
Get-Content logs/deploy.log -Tail 50
开发工作流
1. 拉取最新代码
git pull origin main
2. 创建功能分支
git checkout -b feature/xxx
3. 本地开发测试
修改代码 → 重启服务 → 测试验证
4. 提交推送
git add . && git commit -m "feat: xxx" && git push
5. 创建 PR 合并到 main
6. 部署到开发环境
python scripts/quick_deploy.py
API 快速测试
PowerShell
# 对话
$body = @{message="你好"; session_id="test-001"} | ConvertTo-Json
Invoke-WebRequest -Uri "http://localhost:8001/api/v1/chat" -Method POST -Body $body -ContentType "application/json"
# 专家列表
Invoke-WebRequest -Uri "http://localhost:8001/api/v1/expert/list" -UseBasicParsing
Python
import httpx
API = "http://localhost:8001"
# 对话
resp = httpx.post(f"{API}/api/v1/chat", json={
"message": "你好",
"session_id": "test-001"
})
print(resp.json())
curl (Git Bash)
# 对话
curl -X POST http://localhost:8001/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"message":"你好","session_id":"test-001"}'
目录结构
mises-behavior-engine/
├── src/ # 源代码
│ ├── api/ # API 路由
│ ├── core/ # 核心引擎
│ ├── knowledge/ # 知识库
│ ├── llm/ # LLM 集成
│ └── mcp/ # MCP 协议
├── docs/ # 文档
│ ├── deployment/ # 部署文档
│ ├── development/ # 开发文档
│ └── product/ # 产品文档
├── scripts/ # 脚本
│ ├── auto_deploy.py # 自动部署
│ └── quick_deploy.py # 快速部署
├── tests/ # 测试
├── training/ # 训练相关
├── knowledge_bases/ # 知识库数据
├── docker-compose.dev.yml # 开发环境
├── docker-compose.prod.yml # 生产环境
├── mbe.ps1 # 管理脚本
└── .env # 环境变量
常见问题
Q: 服务启动失败
# 检查 Docker
docker ps
# 查看日志
docker logs mbe-api-dev
# 重建服务
docker-compose -f docker-compose.dev.yml down
docker-compose -f docker-compose.dev.yml up -d
Q: API 返回 502
服务正在启动,等待 60 秒后重试。
Q: 数据库连接失败
# 检查数据库容器
docker logs mbe-postgres-dev
# 重启数据库
docker-compose -f docker-compose.dev.yml restart mbe-postgres-dev
Q: 如何查看我的代码修改是否生效
# 重启 API 服务
docker-compose -f docker-compose.dev.yml restart mbe-api-dev
# 等待 60 秒后测试