重构MaiBot适配器为官方API Server长连接采集模式并补全Dashboard说明
This commit is contained in:
@@ -1,91 +1,50 @@
|
||||
# 192.168.2.240 部署 MaiBot 清单
|
||||
# 192.168.2.240 上的 MaiBot 部署说明
|
||||
|
||||
这份文档用于把 `MaiBot` 部署到 `192.168.2.240`,供 `plugins/maibot_adapter` 调用。
|
||||
这份文档记录当前 `MaiBot 官方镜像` 在 `192.168.2.240` 的实际部署状态,供 `plugins/maibot_adapter` 对接使用。
|
||||
|
||||
## 当前状态
|
||||
## 当前结论
|
||||
|
||||
我已经在 `abot` 里新增了 `maibot_adapter` 插件,但当前还没有这台服务器的 SSH 凭据。
|
||||
如果你把 SSH 用户名/密码,或者私钥登录方式给我,我就可以直接按这份清单远程执行。
|
||||
1. `MaiBot` 使用官方镜像 `sengokucola/maibot:latest` 部署。
|
||||
2. 没有改动 MaiBot 源码,dashboard 通过官方 `maibot-dashboard==1.0.0` 静态资源挂载方式补齐。
|
||||
3. `abot` 侧不再走 WebUI 聊天页,而是改走 `官方 API Server`。
|
||||
4. 现在的推荐接入地址如下:
|
||||
- WebUI / Dashboard:`http://192.168.2.240:18001/`
|
||||
- WebUI Health:`http://192.168.2.240:18001/api/webui/health`
|
||||
- 官方 API Server WS:`ws://192.168.2.240:18009/ws`
|
||||
|
||||
## 目标
|
||||
## 当前 docker-compose 关键点
|
||||
|
||||
部署完成后,`abot` 将使用以下接口访问 MaiBot:
|
||||
容器名:
|
||||
|
||||
1. `POST /api/webui/auth/verify`
|
||||
2. `GET /api/webui/ws-token`
|
||||
3. `WS /ws?token=...`
|
||||
|
||||
因此最终需要保证:
|
||||
|
||||
1. `http://192.168.2.240:8001/api/webui/health` 可访问
|
||||
2. 你手里有一个可用的 `MaiBot WebUI token`
|
||||
3. `plugins/maibot_adapter/config.toml` 中填入同一个 `server_url` 与 `access_token`
|
||||
|
||||
## 推荐部署方式
|
||||
|
||||
当前优先建议“宿主机 Python 直跑”:
|
||||
|
||||
1. 部署简单,方便先打通插件联调
|
||||
2. 日志更容易直接看
|
||||
3. 后面稳定后再考虑改成 Docker Compose
|
||||
|
||||
## 服务器执行步骤
|
||||
|
||||
以下命令默认按 Linux 服务器写。
|
||||
|
||||
### 1. 安装基础依赖
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install -y git python3 python3-venv python3-pip
|
||||
```text
|
||||
maibot-core-lite
|
||||
```
|
||||
|
||||
### 2. 拉取 MaiBot
|
||||
镜像:
|
||||
|
||||
```bash
|
||||
cd /opt
|
||||
sudo git clone https://github.com/Mai-with-u/MaiBot.git
|
||||
sudo chown -R $USER:$USER /opt/MaiBot
|
||||
cd /opt/MaiBot
|
||||
```text
|
||||
sengokucola/maibot:latest
|
||||
```
|
||||
|
||||
### 3. 创建虚拟环境并安装依赖
|
||||
核心端口映射:
|
||||
|
||||
```bash
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
python -m pip install --upgrade pip
|
||||
pip install -e .
|
||||
```text
|
||||
18001 -> 8001 # WebUI / Dashboard / WebUI API
|
||||
18009 -> 8090 # 官方 API Server
|
||||
```
|
||||
|
||||
如果 `pip install -e .` 遇到单个依赖下载慢,可以切换镜像源再执行。
|
||||
## Dashboard 访问地址
|
||||
|
||||
### 4. 首次启动
|
||||
当前已经补全完成,可直接访问:
|
||||
|
||||
```bash
|
||||
source /opt/MaiBot/.venv/bin/activate
|
||||
cd /opt/MaiBot
|
||||
python bot.py
|
||||
```text
|
||||
http://192.168.2.240:18001/
|
||||
```
|
||||
|
||||
说明:
|
||||
如果只想看健康状态:
|
||||
|
||||
1. `bot.py` 是 MaiBot 主入口
|
||||
2. 首次启动时通常需要你按它自己的配置流程完成基础设置
|
||||
3. WebUI 默认监听端口通常是 `8001`
|
||||
|
||||
### 5. 验证健康状态
|
||||
|
||||
本机执行:
|
||||
|
||||
```bash
|
||||
curl http://127.0.0.1:8001/api/webui/health
|
||||
```
|
||||
|
||||
局域网执行:
|
||||
|
||||
```bash
|
||||
curl http://192.168.2.240:8001/api/webui/health
|
||||
```text
|
||||
http://192.168.2.240:18001/api/webui/health
|
||||
```
|
||||
|
||||
期待返回:
|
||||
@@ -94,87 +53,61 @@ curl http://192.168.2.240:8001/api/webui/health
|
||||
{"status":"healthy","service":"MaiBot WebUI"}
|
||||
```
|
||||
|
||||
### 6. 获取 WebUI token
|
||||
## embedding 模型现状
|
||||
|
||||
这一步有两种方式:
|
||||
当前远端已切到 Ollama 向量服务:
|
||||
|
||||
1. 按 MaiBot 首次配置流程,在 WebUI 中设置 token
|
||||
2. 如果已经有现成 token,直接记下来给 `maibot_adapter` 使用
|
||||
```text
|
||||
ollama_base_url = "http://192.168.2.50:11434/v1"
|
||||
embedding_model = "bge-m3:latest"
|
||||
```
|
||||
|
||||
最终你需要把 token 填到:
|
||||
这套配置已经验证可用,MaiBot 日志里能看到 embedding 维度识别成功。
|
||||
|
||||
`plugins/maibot_adapter/config.toml`
|
||||
## 官方 API Server 接入方式
|
||||
|
||||
`maibot_adapter` 现在用的是官方 API Server 协议,不再使用:
|
||||
|
||||
1. `POST /api/webui/auth/verify`
|
||||
2. `GET /api/webui/ws-token`
|
||||
3. `WS /api/webui/ws?token=...`
|
||||
|
||||
现在实际使用的是:
|
||||
|
||||
1. `WS ws://192.168.2.240:18009/ws`
|
||||
2. 握手头:
|
||||
- `x-uuid`
|
||||
- `x-apikey`
|
||||
- `x-platform`
|
||||
3. 消息包类型:
|
||||
- `sys_std`
|
||||
4. 负载结构:
|
||||
- `APIMessageBase`
|
||||
|
||||
## abot 配置建议
|
||||
|
||||
当前 `plugins/maibot_adapter/config.toml` 推荐值:
|
||||
|
||||
```toml
|
||||
server_url = "http://192.168.2.240:8001"
|
||||
access_token = "你的MaiBotToken"
|
||||
[MaiBotAdapter]
|
||||
enable = true
|
||||
collect_group_messages = true
|
||||
collect_private_messages = true
|
||||
enable_reply_output = true
|
||||
reply_group_messages = true
|
||||
reply_private_messages = true
|
||||
respect_group_feature_switch = true
|
||||
mention_user_on_group_reply = false
|
||||
api_server_ws_url = "ws://192.168.2.240:18009/ws"
|
||||
api_key = "abot-maibot"
|
||||
platform_name = "abot-maibot"
|
||||
```
|
||||
|
||||
### 7. 建议做成 systemd 服务
|
||||
## 设计边界
|
||||
|
||||
创建 `/etc/systemd/system/maibot.service`
|
||||
当前这套接法遵循你已经确认过的原则:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=MaiBot Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/MaiBot
|
||||
ExecStart=/opt/MaiBot/.venv/bin/python /opt/MaiBot/bot.py
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
启用并启动:
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable maibot
|
||||
sudo systemctl start maibot
|
||||
sudo systemctl status maibot
|
||||
```
|
||||
|
||||
看日志:
|
||||
|
||||
```bash
|
||||
sudo journalctl -u maibot -f
|
||||
```
|
||||
|
||||
## 与 abot 对接
|
||||
|
||||
部署好后,回到 `abot`:
|
||||
|
||||
1. 编辑 `plugins/maibot_adapter/config.toml`
|
||||
2. 填入:
|
||||
- `server_url = "http://192.168.2.240:8001"`
|
||||
- `access_token = "你的MaiBotToken"`
|
||||
3. 重启 `abot` 或热加载插件
|
||||
|
||||
测试指令:
|
||||
|
||||
```text
|
||||
麦麦 你好
|
||||
```
|
||||
|
||||
或者在群里直接:
|
||||
|
||||
```text
|
||||
@机器人 你好
|
||||
```
|
||||
|
||||
## 备注
|
||||
|
||||
如果你后面希望:
|
||||
|
||||
1. `ai_auto_response` 也复用 MaiBot
|
||||
2. 做自动插话而不是只做命令对话
|
||||
3. 做会话长驻、减少每次重新认证和建连成本
|
||||
|
||||
下一步就可以把 `maibot_adapter` 再往“共享长连接 + 自动回复桥”方向升级。
|
||||
1. 消息默认发送给 MaiBot 做采集。
|
||||
2. 是否真的回复,由开关和群功能权限控制。
|
||||
3. 不重新开发 MaiBot 对话/记忆本体能力。
|
||||
4. 尽量把“参与聊天”的判断留在 MaiBot 侧,而不是在 abot 里再做一遍复杂前置策略。
|
||||
|
||||
Reference in New Issue
Block a user