使用 DeepSeek API + 飞书,在 Mac/Linux/Windows 本地部署个人 AI 助手
📋 目录
准备工作 第一步:安装 OpenClaw 第二步:配置 DeepSeek 模型 第三步:创建飞书应用 第四步:连接飞书与 OpenClaw 第五步:启动和测试 日常使用 进阶配置 常见问题
准备工作
必需条件
Node.js 18+
Mac: brew install nodeWindows: 下载安装 https://nodejs.org Linux: sudo apt install nodejs npm或sudo yum install nodejsDeepSeek API 密钥
访问 https://platform.deepseek.com 注册并创建 API Key 充值少量余额(建议 ¥20 起) 飞书企业账号(免费)
访问 https://www.feishu.cn 注册企业版 个人也可以创建企业账号
预估成本
OpenClaw 软件: 免费开源 DeepSeek API: 约 ¥0.001/千 tokens(超低价) 飞书企业版: 免费 电费: 约 ¥5-10/月(如果 24/7 运行)
月度预估: 轻度使用约 ¥10-30
第一步:安装 OpenClaw
1.1 全局安装
打开终端,执行:
npm install -g openclaw@latest安装时间:约 1-2 分钟
1.2 验证安装
openclaw --version应该显示版本号,例如:2026.2.26
1.3 安装飞书插件
openclaw plugins install @openclaw/feishu第二步:配置 DeepSeek 模型
2.1 创建配置目录
mkdir -p ~/.openclaw2.2 创建配置文件
方法一:使用命令创建(推荐)
cat > ~/.openclaw/openclaw.json << 'EOF'{"models": {"mode": "merge","providers": {"deepseek": {"baseUrl": "https://api.deepseek.com/v1","apiKey": "你的DeepSeek密钥","api": "openai-completions","models": [ {"id": "deepseek-chat","name": "DeepSeek Chat (v3)","reasoning": false,"input": ["text"],"cost": {"input": 2.8e-7,"output": 4.2e-7,"cacheRead": 2.8e-8,"cacheWrite": 2.8e-7 },"contextWindow": 128000,"maxTokens": 8192 } ] } } },"agents": {"defaults": {"model": {"primary": "deepseek/deepseek-chat" },"models": {"deepseek/deepseek-chat": {} } } }}EOF重要: 把 你的DeepSeek密钥 替换成你的实际 API 密钥(以 sk- 开头)
方法二:手动编辑
nano ~/.openclaw/openclaw.json复制上面的 JSON 内容,修改 API 密钥后保存(Ctrl + O,回车,Ctrl + X)
2.3 验证配置
openclaw models list应该能看到:deepseek/deepseek-chat
第三步:创建飞书应用
3.1 访问飞书开放平台
打开浏览器:https://open.feishu.cn/app
使用飞书账号登录,点击"开发者后台"
3.2 创建企业自建应用
点击"创建企业自建应用" 填写应用信息: 应用名称: OpenClaw Bot(或你喜欢的名字)应用描述: 我的个人 AI 助手应用图标: 上传一个图标(可选) 点击"创建"
3.3 获取应用凭证
在应用详情页面,点击"凭证与基础信息":
复制 App ID(格式: cli_xxxxxxxxxx)点击"查看",复制 App Secret
重要: 将这两个值保存到记事本,稍后会用到。
3.4 配置应用权限
点击左侧"权限管理" 点击"批量导入"按钮 粘贴以下 JSON 配置:
{"scopes": {"tenant": ["contact:user.base:readonly","contact:contact.base:readonly","im:chat","im:message","im:message.group_at_msg:readonly","im:message.p2p_msg:readonly","im:message:send_as_bot"],"user": []}}点击"确定"导入权限
3.5 配置机器人
点击左侧"机器人"菜单 机器人功能已默认启用 可以填写"如何开始使用"的引导文字(可选)
3.6 配置事件订阅
点击左侧"事件与回调" 选择"使用长连接接收事件" 此时会提示"应用未建立长连接",这是正常的
重要:需要先启动 OpenClaw 建立连接,才能添加事件。
暂时跳过这一步,在第四步配置完 OpenClaw 并启动后再回来完成。
3.7 暂时不发布应用
注意:先不要发布应用,等配置完 OpenClaw 并添加事件订阅后再发布。
第四步:连接飞书与 OpenClaw
4.1 配置飞书频道
使用命令行配置(替换为你的实际 App ID 和 Secret):
openclaw config set channels.feishu.enabled trueopenclaw config set channels.feishu.accounts.main.appId "cli_你的AppID"openclaw config set channels.feishu.accounts.main.appSecret "你的AppSecret"openclaw config set channels.feishu.accounts.main.botName "OpenClaw Bot"openclaw config set plugins.entries.feishu.enabled true4.2 设置访问策略(暂时跳过)
注意: 这一步暂时跳过,等获取到你的飞书用户 ID 后再配置。
默认配置会阻止未授权用户,我们需要先获取用户 ID,然后添加到白名单。
4.3 设置 Gateway 模式
openclaw config set gateway.mode local4.4 配置工作目录(重要)
OpenClaw 默认只能在工作目录内操作文件。设置工作目录:
选项一:使用桌面作为工作目录(推荐)
openclaw config set agents.defaults.workspace "~/Desktop"或者使用完整路径:
openclaw config set agents.defaults.workspace "/Users/你的用户名/Desktop"选项二:使用默认工作目录
openclaw config set agents.defaults.workspace "~/.openclaw/workspace"文件会创建在 ~/.openclaw/workspace 目录下。
选项三:使用其他目录
openclaw config set agents.defaults.workspace "/path/to/your/folder"说明:
机器人只能在工作目录内创建、编辑、删除文件 如果尝试访问工作目录外的文件,会报错: Path escapes workspace root建议使用桌面或专门的项目文件夹
第五步:启动和测试
5.1 启动 Gateway
openclaw gateway --port 18789 --verbose成功标志:看到以下日志
Gateway listening on 127.0.0.1:18789feishu[main]: WebSocket client startedws client ready5.2 回到飞书开放平台添加事件
现在 OpenClaw 已经启动并建立了长连接,回到飞书开放平台:
刷新"事件与回调"页面 应该能看到"长连接已建立"的提示 点击"添加事件" 搜索并添加: im.message.receive_v1(接收消息)保存
5.3 发布飞书应用
点击左侧"版本管理与发布" 点击"创建版本" 填写版本说明(例如: 初始版本)点击"保存" 点击"申请发布" 提交审核(企业自建应用通常自动通过)
5.4 在飞书中找到机器人
打开飞书客户端(桌面版或手机版) 点击"+"或"新建会话" 搜索你的机器人名称: OpenClaw Bot点击机器人头像,开始对话
5.5 获取飞书用户 ID
在飞书中向机器人发送任意消息,例如:
你好查看运行 Gateway 的终端日志,会看到类似:
feishu[main]: received message from ou_e34e1249c5d5b8af8ec7767a792231dbfeishu[main]: blocked unauthorized sender ou_e34e1249c5d5b8af8ec7723a792661db或者机器人会返回:
OpenClaw: access not configured.Your Feishu user id: ou_e34e1249c5d5b8af8ec7237a792661dbPairing code: P42TJJ78记录你的飞书用户 ID( ou_开头的那串字符)
5.6 配置白名单
打开新终端(保持 Gateway 运行),执行:
openclaw config set channels.feishu.dmPolicy allowlistopenclaw config set channels.feishu.allowFrom '["ou_你的用户ID"]'例如:
openclaw config set channels.feishu.dmPolicy allowlistopenclaw config set channels.feishu.allowFrom '["ou_e34e1249c5d5b8af8ec77623792661db"]'如果有多个用户需要使用:
openclaw config set channels.feishu.allowFrom '["ou_用户1", "ou_用户2", "ou_用户3"]'5.7 重启 Gateway
在运行 Gateway 的终端按 Ctrl + C 停止,然后重新启动:
openclaw gateway --port 18789 --verbose5.8 测试对话
重启 Gateway 后,在飞书中再次发送消息:
你好,请介绍一下自己这次机器人应该会正常回复了!
在飞书中发送消息:
你好,请介绍一下自己如果一切正常,机器人会用 DeepSeek 模型回复你!
日常使用
启动 Gateway
前台运行(查看日志)
openclaw gateway --port 18789 --verbose按 Ctrl + C 停止
后台运行(推荐)
nohup openclaw gateway --port 18789 --verbose > ~/openclaw.log 2>&1 &查看日志:
tail -f ~/openclaw.log停止后台进程:
pkill -f "openclaw gateway"设置开机自启(可选)
Mac/Linux
openclaw daemon installopenclaw daemon start查看状态:
openclaw daemon status停止服务:
openclaw daemon stop卸载服务:
openclaw daemon uninstall常用命令
# 查看 Gateway 状态openclaw gateway status# 重启 Gatewayopenclaw gateway restart# 查看模型列表openclaw models list# 查看配置openclaw config get# 查看日志openclaw logs --follow# 查看配对列表openclaw pairing list feishu# 运行诊断openclaw doctor在飞书中可以做什么
基础对话
OpenClaw 可以像 ChatGPT 一样进行对话:
你:帮我写一个 Python 函数计算斐波那契数列AI:[生成代码]你:请添加缓存优化AI:[优化后的代码]你:再添加单元测试AI:[带测试的完整代码]多轮对话
OpenClaw 会自动记住上下文,支持连续对话。
飞书聊天命令
在飞书中可以使用以下命令:
/status # 查看会话状态(模型、tokens、成本)/new 或 /reset # 重置会话,清空上下文/compact # 压缩上下文,节省 tokens/think high # 设置思考级别(off/minimal/low/medium/high/xhigh)/verbose on # 开启详细模式/usage full # 显示使用统计实际应用场景
1. 编程助手
帮我写一个 React 组件,实现一个可拖拽的卡片列表2. 文档处理
帮我总结这段文字的要点:[粘贴长文本]3. 数据分析
这组数据的平均值、中位数和标准差是多少?[1, 5, 3, 8, 2, 9, 4, 7, 6]4. 翻译
把这段话翻译成英文:[中文内容]5. 学习辅导
用简单的语言解释一下什么是区块链6. 创意写作
帮我写一封专业的邮件,主题是申请远程工作7. 问题解决
我的 Node.js 项目报错:Cannot find module 'express'应该怎么解决?群聊使用
将机器人添加到飞书群 在群中 @机器人 发送消息 机器人会回复
配置群聊策略:
openclaw config set channels.feishu.groupPolicy "open"openclaw config set channels.feishu.requireMention true进阶配置
切换模型
如果你想使用 DeepSeek Reasoner(推理模型):
openclaw config set agents.defaults.model.primary "deepseek/deepseek-reasoner"openclaw gateway restart切换回普通模型:
openclaw config set agents.defaults.model.primary "deepseek/deepseek-chat"openclaw gateway restart添加多个模型
编辑配置文件 ~/.openclaw/openclaw.json,在 models.providers.deepseek.models 数组中添加:
{"id": "deepseek-reasoner","name": "DeepSeek Reasoner (v3)","reasoning": true,"input": ["text"],"cost": {"input": 2.8e-7,"output": 4.2e-7,"cacheRead": 2.8e-8,"cacheWrite": 2.8e-7},"contextWindow": 128000,"maxTokens": 65536}然后在 agents.defaults.models 中添加:
"deepseek/deepseek-reasoner": {}安装技能(Skills)
查看可用技能:
openclaw skills list安装技能:
openclaw skills install <skill-name>查看已安装技能:
openclaw skills installed配置上下文压缩
节省 tokens 和成本:
openclaw config set agents.defaults.compaction.mode safeguardopenclaw config set agents.defaults.compaction.maxTokens 50000配置并发数
openclaw config set agents.defaults.maxConcurrent 4查看完整配置
cat ~/.openclaw/openclaw.json常见问题
Q1: Gateway 启动失败
症状: 执行 openclaw gateway 后立即退出
解决方案:
检查配置文件语法:
cat ~/.openclaw/openclaw.json | python -m json.tool运行诊断:
openclaw doctor查看日志:
openclaw logs --followQ2: 飞书机器人不回复
排查步骤:
检查 Gateway 是否运行:
ps aux | grep openclaw检查是否已配对或在白名单中:
openclaw pairing list feishuopenclaw config get channels.feishu.allowFrom查看日志:
tail -f ~/openclaw.log检查飞书应用是否已发布
检查事件订阅是否配置正确
Q3: DeepSeek API 调用失败
排查步骤:
验证 API 密钥:
openclaw config get models.providers.deepseek.apiKey测试 API 连接:
curl https://api.deepseek.com/v1/models \ -H "Authorization: Bearer 你的API密钥"检查账户余额:登录 DeepSeek 控制台查看
Q4: 每次重启都要重新配对
解决方案: 使用白名单模式
openclaw config set channels.feishu.dmPolicy allowlistopenclaw config set channels.feishu.allowFrom '["ou_你的用户ID"]'Q5: 如何查看 API 使用量和成本
方法一: 在飞书中使用命令
/usage full方法二: 访问 DeepSeek 控制台查看详细账单
Q6: Gateway 占用 CPU 过高
解决方案:
降低并发数:
openclaw config set agents.defaults.maxConcurrent 2启用更激进的上下文压缩:
openclaw config set agents.defaults.compaction.mode aggressiveQ7: 如何更新 OpenClaw
npm update -g openclawopenclaw plugins updateopenclaw gateway restartQ8: 如何备份配置
cp ~/.openclaw/openclaw.json ~/openclaw-backup-$(date +%Y%m%d).json恢复配置:
cp ~/openclaw-backup-20260301.json ~/.openclaw/openclaw.jsonQ9: 如何完全卸载
# 停止服务openclaw daemon stopopenclaw daemon uninstall# 卸载软件npm uninstall -g openclaw# 删除配置(可选)rm -rf ~/.openclaw性能优化
减少内存占用
openclaw config set agents.defaults.compaction.mode safeguardopenclaw config set agents.defaults.compaction.maxTokens 50000加快响应速度
使用更快的模型(deepseek-chat 比 deepseek-reasoner 快):
openclaw config set agents.defaults.model.primary "deepseek/deepseek-chat"降低成本
启用上下文压缩 定期重置会话( /reset)使用 deepseek-chat 而不是 deepseek-reasoner
安全建议
1. 保护 API 密钥
不要在公开的地方分享配置文件,因为里面包含 API 密钥。
2. 使用白名单模式
openclaw config set channels.feishu.dmPolicy allowlistopenclaw config set channels.feishu.allowFrom '["ou_你的用户ID"]'3. 定期更新
npm update -g openclaw4. 监控使用量
定期检查 DeepSeek 控制台,设置预算告警。
5. 备份配置
定期备份 ~/.openclaw/openclaw.json。
故障排查流程
步骤 1: 检查 Gateway 状态
openclaw gateway status步骤 2: 查看日志
tail -n 50 ~/openclaw.log步骤 3: 运行诊断
openclaw doctor步骤 4: 验证配置
openclaw config getopenclaw models list步骤 5: 测试 API
curl https://api.deepseek.com/v1/models \ -H "Authorization: Bearer 你的API密钥"步骤 6: 重启 Gateway
pkill -f "openclaw gateway"openclaw gateway --port 18789 --verbose命令速查表
Gateway 管理
# 前台启动(查看日志)openclaw gateway --port 18789 --verbose# 后台启动nohup openclaw gateway --port 18789 --verbose > ~/openclaw.log 2>&1 &# 查看状态openclaw gateway status# 重启openclaw gateway restart# 停止pkill -f "openclaw gateway"# 查看日志tail -f ~/openclaw.log配置管理
# 查看所有配置openclaw config get# 查看特定配置openclaw config get channels.feishu# 设置配置openclaw config set <key> <value># 查看模型列表openclaw models list# 运行诊断openclaw doctor配对管理
# 查看待配对请求openclaw pairing list feishu# 批准配对openclaw pairing approve feishu <CODE># 拒绝配对openclaw pairing reject feishu <CODE># 查看已配对设备openclaw pairing list --approved插件和技能
# 列出已安装插件openclaw plugins list# 安装插件openclaw plugins install <plugin-name># 更新插件openclaw plugins update# 列出可用技能openclaw skills list# 安装技能openclaw skills install <skill-name># 查看已安装技能openclaw skills installed守护进程(开机自启)
# 安装守护进程openclaw daemon install# 启动守护进程openclaw daemon start# 停止守护进程openclaw daemon stop# 查看状态openclaw daemon status# 卸载守护进程openclaw daemon uninstall日志和调试
# 查看实时日志openclaw logs --follow# 查看最近日志tail -n 50 ~/openclaw.log# 搜索错误grep -i error ~/openclaw.log# 查看进程ps aux | grep openclaw完整配置文件示例
~/.openclaw/openclaw.json 完整示例:
{"meta": {"lastTouchedVersion": "2026.2.26","lastTouchedAt": "2026-03-01T14:54:40.715Z"},"models": {"mode": "merge","providers": {"deepseek": {"baseUrl": "https://api.deepseek.com/v1","apiKey": "sk-your-api-key-here","api": "openai-completions","models": [{"id": "deepseek-chat","name": "DeepSeek Chat (v3)","reasoning": false,"input": ["text"],"cost": {"input": 2.8e-7,"output": 4.2e-7,"cacheRead": 2.8e-8,"cacheWrite": 2.8e-7},"contextWindow": 128000,"maxTokens": 8192},{"id": "deepseek-reasoner","name": "DeepSeek Reasoner (v3)","reasoning": true,"input": ["text"],"cost": {"input": 2.8e-7,"output": 4.2e-7,"cacheRead": 2.8e-8,"cacheWrite": 2.8e-7},"contextWindow": 128000,"maxTokens": 65536}]}}},"agents": {"defaults": {"model": {"primary": "deepseek/deepseek-chat"},"models": {"deepseek/deepseek-chat": {},"deepseek/deepseek-reasoner": {}},"compaction": {"mode": "safeguard","maxTokens": 100000},"maxConcurrent": 4}},"channels": {"feishu": {"enabled": true,"dmPolicy": "allowlist","allowFrom": ["ou_your_user_id_here"],"groupPolicy": "open","requireMention": true,"accounts": {"main": {"appId": "cli_your_app_id_here","appSecret": "your_app_secret_here","botName": "OpenClaw Bot"}}}},"gateway": {"mode": "local","port": 18789,"bind": "127.0.0.1"},"plugins": {"entries": {"feishu": {"enabled": true}}}}相关链接
OpenClaw 官网: https://openclaw.ai OpenClaw GitHub: https://github.com/openclaw/openclaw OpenClaw 文档: https://docs.openclaw.ai DeepSeek 平台: https://platform.deepseek.com DeepSeek API 文档: https://api-docs.deepseek.com 飞书开放平台: https://open.feishu.cn 飞书开发文档: https://open.feishu.cn/document
总结
恭喜!你已经成功在本地部署了 OpenClaw。现在你拥有:
✅ 一个运行在本地的 AI 助手✅ 使用超低价的 DeepSeek API✅ 通过飞书随时随地访问✅ 完全掌控的私有部署
下一步建议
探索更多功能:在飞书中尝试各种问题和命令 安装技能: openclaw skills list查看可用技能优化配置:根据使用情况调整模型和参数 设置开机自启: openclaw daemon install && openclaw daemon start定期备份配置: cp ~/.openclaw/openclaw.json ~/backup/
如果需要 24/7 运行
本地部署需要电脑一直开着。如果需要 24/7 运行,可以考虑:
Oracle Cloud 永久免费 VPS(推荐,真正的 24/7,完全免费) Render.com(有免费额度) Fly.io(有免费额度) 树莓派(低功耗,适合家庭部署)
享受你的 AI 助手吧!🦞


夜雨聆风