# Windows + Clawdbot + GLM-4.7 配置指南 > **准确步骤**:从零开始,10 分钟完成配置 > > **你的环境**:Windows + WSL2 + GLM Coding Plan (GLM-4.7) --- ## 第一步:打开 WSL2 Ubuntu 在 Windows 中,按 `Win + R`,输入: ``` wsl ``` **或者**:打开 PowerShell,输入 `wsl` 回车 --- ## 第二步:配置 GLM-4.7(在 WSL2 中执行) ### 复制以下命令,粘贴到 WSL2 终端 ```bash echo 'export OPENAI_BASE_URL="https://open.bigmodel.cn/api/paas/v4/"' >> ~/.bashrc && \ echo 'export OPENAI_API_KEY="你的GLM_API_KEY"' >> ~/.bashrc && \ echo 'export MODEL_NAME="glm-4-plus"' >> ~/.bashrc && \ source ~/.bashrc ``` **重要**: - 将 `你的GLM_API_KEY` 替换为你的真实 API Key - 不要删除引号 ### 验证配置 ```bash echo $OPENAI_BASE_URL echo $OPENAI_API_KEY echo $MODEL_NAME ``` 应该显示: - `https://open.bigmodel.cn/api/paas/v4/` - 你的 API Key - `glm-4-plus` --- ## 第三步:安装 Node.js 22(如果还没安装) 在 WSL2 中执行: ```bash curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y nodejs ``` 验证安装: ```bash node --version ``` 应该显示:`v22.x.x` --- ## 第四步:安装 Clawdbot 在 WSL2 中执行: ```bash npm install -g clawdbot@latest ``` 验证安装: ```bash clawdbot --version ``` --- ## 第五步:启动 Clawdbot 在 WSL2 中执行: ```bash clawdbot gateway --port 18789 ``` **看到以下输出说明成功**: ``` [INFO] Gateway starting on port 18789 [INFO] Ready ``` --- ## 第六步:访问 Web 界面 ### 在 Windows 浏览器中打开 ``` http://localhost:18789/ ``` ### 如果访问不了 **在 PowerShell(管理员)中执行**: ```powershell # 1. 获取 WSL2 IP wsl hostname -I # 2. 配置端口转发(替换下面的 IP 地址) netsh interface portproxy add v4tov4 listenport=18789 listenaddress=0.0.0.0 connectport=18789 connectaddress=172.x.x.x ``` 再次访问 `http://localhost:18789/` --- ## 第七步:测试对话 在 Web 界面中输入: ``` 你好 ``` 如果收到回复,配置成功!✅ --- ## 完整配置命令(复制即用) ### 在 WSL2 中一次性执行: ```bash # 1. 配置 GLM-4.7(替换你的 API KEY) echo 'export OPENAI_BASE_URL="https://open.bigmodel.cn/api/paas/v4/"' >> ~/.bashrc && \ echo 'export OPENAI_API_KEY="你的GLM_API_KEY"' >> ~/.bashrc && \ echo 'export MODEL_NAME="glm-4-plus"' >> ~/.bashrc && \ source ~/.bashrc && \ # 2. 安装 Node.js 22(如果需要) curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && \ sudo apt-get install -y nodejs && \ # 3. 安装 Clawdbot npm install -g clawdbot@latest && \ # 4. 启动服务 clawdbot gateway --port 18789 ``` --- ## 常用操作 ### 查看 Clawdbot 日志 启动时添加 `--verbose`: ```bash clawdbot gateway --port 18789 --verbose ``` ### 后台运行 ```bash nohup clawdbot gateway --port 18789 > ~/clawdbot.log 2>&1 & ``` 查看日志: ```bash tail -f ~/clawdbot.log ``` ### 停止服务 ```bash ps aux | grep clawdbot kill <进程ID> ``` ### 重启服务 ```bash # 停止 ps aux | grep clawdbot kill <进程ID> # 启动 clawdbot gateway --port 18789 ``` --- ## 验证 GLM-4.7 连接 在 WSL2 中执行: ```bash curl -X POST https://open.bigmodel.cn/api/paas/v4/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "glm-4-plus", "messages": [{"role": "user", "content": "你好"}] }' ``` 如果返回 JSON 包含 AI 回复,说明 API 连接正常。 --- ## 配置文件位置 ``` ~/.bashrc # 环境变量配置 ~/.clawdbot/ # Clawdbot 配置目录 ├── config.json # 主配置文件 └── workspace/ # 工作空间 ``` --- ## 故障排查 ### 问题 1:`node: command not found` **解决**:安装 Node.js 22 ```bash curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y nodejs ``` ### 问题 2:`clawdbot: command not found` **解决**:安装 Clawdbot ```bash npm install -g clawdbot@latest ``` ### 问题 3:浏览器访问不了 `localhost:18789` **解决**:检查服务是否启动 ```bash ps aux | grep clawdbot ``` 如果没有运行,重新启动: ```bash clawdbot gateway --port 18789 ``` ### 问题 4:配置没生效 **解决**:重新加载环境变量 ```bash source ~/.bashrc ``` 验证配置: ```bash echo $OPENAI_BASE_URL echo $OPENAI_API_KEY echo $MODEL_NAME ``` ### 问题 5:API 返回错误 **检查**: 1. API Key 是否正确 2. 网络是否正常 3. 套餐是否有效 测试网络: ```bash curl -I https://open.bigmodel.cn ``` --- ## 快速检查清单 配置完成后,逐项检查: - [ ] WSL2 可以正常使用 - [ ] `node --version` 显示 v22.x.x - [ ] `clawdbot --version` 显示版本号 - [ ] `echo $OPENAI_API_KEY` 显示你的 API Key - [ ] `echo $MODEL_NAME` 显示 `glm-4-plus` - [ ] `curl` 测试 API 返回正常 - [ ] `clawdbot gateway` 启动成功 - [ ] 浏览器可以访问 `http://localhost:18789/` - [ ] Web 界面可以发送消息并收到回复 全部勾选 ✅ = 配置成功! --- ## 下一步 配置成功后,你可以: 1. **开始对话**:在 Web 界面与 GLM-4.7 对话 2. **尝试功能**:让 AI 帮你写代码、分析文档 3. **设置自启**:配置开机自动启动(见下方) --- ## 开机自动启动(可选) 在 WSL2 中执行: ```bash # 创建 systemd 服务 sudo cat > /etc/systemd/system/clawdbot.service << 'EOF' [Unit] Description=Clawdbot AI Assistant After=network.target [Service] Type=simple User=$USER WorkingDirectory=/home/$USER Environment="OPENAI_BASE_URL=https://open.bigmodel.cn/api/paas/v4/" Environment="OPENAI_API_KEY=$OPENAI_API_KEY" Environment="MODEL_NAME=glm-4-plus" ExecStart=/usr/bin/clawdbot gateway --port 18789 Restart=always [Install] WantedBy=multi-user.target EOF # 启动服务 sudo systemctl daemon-reload sudo systemctl enable clawdbot sudo systemctl start clawdbot # 查看状态 sudo systemctl status clawdbot ``` --- ## 完成! 现在你的 Windows 电脑上已经运行着: - ✅ Clawdbot(24/7 AI 助手) - ✅ GLM-4.7(最新旗舰模型) - ✅ Web 界面(浏览器访问) **访问地址**:http://localhost:18789/ **开始使用吧!** 🚀