一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

耗时48小时踩坑无数 我终于让飞书接管了本地大模型

时间:2026-07-21 11:04:50 编辑:袖梨 来源:一聚教程网

{"type":"doc","content":[{"type":"paragraph","attrs":{"id":"b6b667bf-22e0-4d82-8399-89dd33e1a61e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这两天,我死磕了一个硬核项目:"},{"type":"text","marks":[{"type":"bold"}],"text":"构建一个以飞书为交互终端的 AI 现场工程师中控系统。"}]},{"type":"paragraph","attrs":{"id":"29cbfc51-f7e8-4671-9971-9745e2b64e10","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"听起来很极客对吧?简单来说,就是我想在飞书上发一句“帮我写个快速排序”,消息能直接穿透到本地的 Ollama,由本地大模型进行意图识别,再调度合适的模型处理,最后把结果回复到飞书里。"}]},{"type":"paragraph","attrs":{"id":"4f779c25-23ba-4275-9b76-e6cc9af56119","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这不仅是打通了一个 API,而是把“飞书”变成了我个人 AI 中控的“遥控器”。"}]},{"type":"paragraph","attrs":{"id":"0db121c1-a272-4c6a-beb8-6d2bec4b6cae","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"今天,这套端到端的管道终于跑通了。但在庆祝之前,我必须得说:"},{"type":"text","marks":[{"type":"bold"}],"text":"这48小时的踩坑历程,简直是一部血泪史。"}]},{"type":"paragraph","attrs":{"id":"ed3a3c92-6910-4162-a47a-966cbc410886","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"如果你也想自己搞 AI 私域部署、对接飞书机器人,这篇文章里的坑,建议你全文背诵。"}]},{"type":"heading","attrs":{"id":"ae139053-45c5-4f3c-97b8-486b1b4c733b","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"01. 核心架构:从“单打独斗”到“模型分工”"}]},{"type":"paragraph","attrs":{"id":"69989f77-73a3-48e4-aad5-35de54030a1c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"先给大家看下我熬了两个通宵搭出来的底座。我不想让大模型只是个“聊天框”,我要它是个“工程师团队”。"}]},{"type":"paragraph","attrs":{"id":"0bf902c5-1c3c-490a-a13b-fb6d2166a489","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"在 "},{"type":"text","marks":[{"type":"code"}],"text":"models.md"},{"type":"text","text":" 里,我给我的 AI 们分了工:"}]},{"type":"bulletList","attrs":{"id":"b1e04873-fe24-4308-84aa-b9fbda03aa93","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"6951f5b5-3b67-4997-92a4-f31cb9c5e8ad"},"content":[{"type":"paragraph","attrs":{"id":"91f944f5-79cf-4469-bece-9f4816c7c537","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Ollama (qwen2.5:1.5b)"},{"type":"text","text":":作为"},{"type":"text","marks":[{"type":"bold"}],"text":"中控"},{"type":"text","text":"。轻量级,专门负责意图识别和日常对话。"}]}]},{"type":"listItem","attrs":{"id":"70efd39c-f6a1-41ae-93e0-486a1197818a"},"content":[{"type":"paragraph","attrs":{"id":"c396f220-d8d6-45d7-8a92-eed691545402","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"DeepSeek-v4-pro"},{"type":"text","text":":作为"},{"type":"text","marks":[{"type":"bold"}],"text":"导师/推理器"},{"type":"text","text":"。专门啃代码、逻辑推理,Ollama 搞不定的低置信度意图全丢给它兜底。"}]}]},{"type":"listItem","attrs":{"id":"0354fa5c-adb0-4ce3-acac-cfad6d00a944"},"content":[{"type":"paragraph","attrs":{"id":"c0629d65-2dd7-4796-b1b6-40e8c002c735","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Claude-opus"},{"type":"text","text":":作为"},{"type":"text","marks":[{"type":"bold"}],"text":"创意大脑"},{"type":"text","text":"。负责设计、头脑风暴。"}]}]},{"type":"listItem","attrs":{"id":"89498ca1-f414-4a8b-bf05-3598d509b249"},"content":[{"type":"paragraph","attrs":{"id":"633918a6-0f2c-4b37-b037-fbb7b9fd39fa","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Gemini-3.5-flash"},{"type":"text","text":":作为"},{"type":"text","marks":[{"type":"bold"}],"text":"规划师"},{"type":"text","text":"。负责长文本、理财决策和周报。"}]}]}]},{"type":"paragraph","attrs":{"id":"aaddf47b-460a-4d29-80e8-e79e5c5f128b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"整个请求流是这样的:"}]},{"type":"blockquote","attrs":{"id":"6c7a2293-303c-43ac-83c2-623a70f1f9fc","textAlign":"inherit","isHoverDragHandle":false},"content":[{"type":"paragraph","attrs":{"id":"c7e0c7c4-c722-428d-af3d-d99cf61f3c69","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"飞书发消息 → Cloudflare 隧道穿透到本地 FastAPI → Ollama 秒级识别意图 → 匹配对应领域的模型(比如代码类给 DeepSeek) → 生成结果 → 飞书 API 回复 → SQLite 记忆存储。"}]},{"type":"paragraph","attrs":{"id":"c712543a-8aef-4b53-b98c-43b4ceed4dec","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"79c35832-d4ef-4ad5-a403-b3d107cfc16f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}}]},{"type":"paragraph","attrs":{"id":"27bb8527-0bc0-4e71-ab20-2c316d7c7cc4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"逻辑很完美,代码写得也很顺(两天写了2600多行 Python)。但真正让我头秃的,是飞书那边的“玄学”配置。"}]},{"type":"heading","attrs":{"id":"d8e0ec4d-8117-4e88-aa65-788abeab9cc2","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"02. 灵魂拷问:为什么飞书收不到消息?"}]},{"type":"paragraph","attrs":{"id":"b9e3e95a-1001-4bce-8d58-74adc9f16ca7","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"代码写完,本地测试全通。我用 "},{"type":"text","marks":[{"type":"code"}],"text":"curl"},{"type":"text","text":" 模拟飞书请求,意图识别、模型调用、存储,一气呵成。但一到飞书真刀真枪地 @机器人,服务器就像死了一样,"},{"type":"text","marks":[{"type":"bold"}],"text":"连个 pong 都没有。"}]},{"type":"paragraph","attrs":{"id":"0abebe57-0177-4fa6-ac84-b66999b39974","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"我开启了地狱级 Debug 模式:"}]},{"type":"orderedList","attrs":{"id":"01363a54-3940-488a-ae16-3c4aff5f8eac","start":1,"isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"8a7d7c0b-dd51-41b8-8016-a7d46e4bf8d6"},"content":[{"type":"paragraph","attrs":{"id":"b565c1b5-df5e-44f6-b69f-ee8fd33c5142","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"怀疑是长连接 WebSocket 的锅"},{"type":"text","text":":改成长连接,结果只有心跳 "},{"type":"text","marks":[{"type":"code"}],"text":"pong"},{"type":"text","text":",零消息事件。"}]}]},{"type":"listItem","attrs":{"id":"7596deb1-1686-41cf-8ead-0461ee02d167"},"content":[{"type":"paragraph","attrs":{"id":"17a952cb-49c5-45de-9d6a-15efad63d546","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"怀疑是权限没开"},{"type":"text","text":":去飞书后台开权限,结果 UI 显示“已添加”,API 诊断死活返回 "},{"type":"text","marks":[{"type":"code"}],"text":"Access Denied"},{"type":"text","text":"。这就好比你买了票,检票员说系统里没你名字,绝望不绝望?"}]}]},{"type":"listItem","attrs":{"id":"dba51645-5a04-4a31-9310-d91e59796c94"},"content":[{"type":"paragraph","attrs":{"id":"f53ea8bb-f6c7-4d75-96d9-080d3743a407","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"怀疑是机器人没激活"},{"type":"text","text":":查了半天,发现应用根本没添加“机器人”功能。加上之后,状态终于变成 "},{"type":"text","marks":[{"type":"code"}],"text":"activate_status=2"},{"type":"text","text":"。"}]}]},{"type":"listItem","attrs":{"id":"0b684787-5b4d-4468-9ebc-1be9a742bb4a"},"content":[{"type":"paragraph","attrs":{"id":"880df729-624a-4647-9a98-4bf131806212","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"依然收不到消息!"}]}]}]},{"type":"paragraph","attrs":{"id":"0b57f464-4b01-4d62-a5db-f252bf654255","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"最后,通过一个诊断脚本查 API,真相大白:"},{"type":"text","marks":[{"type":"code"}],"text":"chats: 0"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"id":"eff42841-7b07-49d9-be9d-a8eaef9cb273","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"破案了兄弟们。我在群里 @ 的那个“无情督导”,是用 Webhook URL 添加的 "},{"type":"text","marks":[{"type":"bold"}],"text":"Custom Bot(自定义机器人)"},{"type":"text","text":"。而我代码里配置的,是 "},{"type":"text","marks":[{"type":"bold"}],"text":"App Bot(应用机器人)"},{"type":"text","text":"。"},{"type":"text","marks":[{"type":"bold"}],"text":"我的 App Bot 压根就不在那个群里!"}]},{"type":"paragraph","attrs":{"id":"78dbe547-184c-41f8-af7a-ed527fe275d5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"更搞心态的是,飞书个人版居然有限制,App Bot 没法被邀请进普通的组织群聊。"}]},{"type":"paragraph","attrs":{"id":"8ec0d28b-28dd-4321-9bdb-562a56e5eeff","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"解决方案:"},{"type":"text","text":" 既然群聊走不通,那就先测私聊!我直接私聊我的 App Bot, Bingo!Webhook 瞬间收到消息,Ollama 意图识别成功,SQLite 成功存储!管道终于通了!"}]},{"type":"heading","attrs":{"id":"e49c5f5a-c322-4730-97c8-cc01459c8f6b","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"03. 收到消息了,为什么回复不了?"}]},{"type":"paragraph","attrs":{"id":"57f6104a-6a84-435d-b5ae-11588092e6f2","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"刚高兴了三秒钟,飞书还是没动静。一看日志:"},{"type":"text","marks":[{"type":"code"}],"text":"Bot Not Enabled"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"id":"5daacb05-18ca-467d-ba69-713642eac0c6","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"又是一顿排查,发现是一个很低级但很容易忽略的坑:"},{"type":"hardBreak","attrs":{"id":"3bbbd753-288f-41cf-a56d-c785d97425d6"}},{"type":"text","text":" 我之前为了测试,用的是 Custom Bot 的 Webhook URL 来发消息。但要用 App Bot 回复,必须得走飞书的官方 API("},{"type":"text","marks":[{"type":"code"}],"text":"im/v1/messages/reply"},{"type":"text","text":")。"}]},{"type":"paragraph","attrs":{"id":"f61bf52c-5ab5-484a-aa57-beea91dfbf6b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"连夜重写了 "},{"type":"text","marks":[{"type":"code"}],"text":"reply_to_message()"},{"type":"text","text":" 函数,把回复机制彻底重构。重启服务器,私聊发消息,飞书终于弹出了大模型的回复!"}]},{"type":"heading","attrs":{"id":"72632f1c-2b2d-4497-81af-548ae98b69fa","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"04. 给所有开发者的避坑指南"}]},{"type":"paragraph","attrs":{"id":"9709ce42-d0c5-4af0-8ad4-4b0ff6b9d815","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这两天踩的坑,远远不止这些。GitHub 下载被墙、"},{"type":"text","marks":[{"type":"code"}],"text":"lark_oapi"},{"type":"text","text":" SDK 版本不匹配、Ollama URL 缺少 "},{"type":"text","marks":[{"type":"code"}],"text":"/v1"},{"type":"text","text":" 前缀……每一个都能卡你一小时。"}]},{"type":"paragraph","attrs":{"id":"07c1a022-2b12-4d99-976c-7506313b3ed4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"总结几条血泪经验,给后面想搞飞书 本地大模型的朋友:"}]},{"type":"orderedList","attrs":{"id":"5e87e6a1-e685-44cb-b734-3809ae71cec8","start":1,"isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"eed4d0c2-4b0a-4e2c-b988-638d34becd53"},"content":[{"type":"paragraph","attrs":{"id":"165d749c-df77-4fab-b061-62db20474118","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"搞清楚 Custom Bot 和 App Bot 的区别!"},{"type":"text","text":" 如果你要双向通信,必须用 App Bot,并且确保把它"},{"type":"text","marks":[{"type":"bold"}],"text":"真正添加到会话里"},{"type":"text","text":"(群聊或私聊)。不要看着群里有机器人就以为万事大吉了。"}]}]},{"type":"listItem","attrs":{"id":"cb7dc0ec-e9b7-423a-9100-b4eb1acc0103"},"content":[{"type":"paragraph","attrs":{"id":"ec85ed6d-8578-4b70-b5b7-1270da956d38","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"飞书权限有延迟,且 UI 会骗人。"},{"type":"text","text":" UI 显示权限已开通没用,必须用 API 去实测(比如调一下 "},{"type":"text","marks":[{"type":"code"}],"text":"im:chat"},{"type":"text","text":")。如果返回 "},{"type":"text","marks":[{"type":"code"}],"text":"Access Denied"},{"type":"text","text":",多发布几次版本,或者等一会儿再试。"}]}]},{"type":"listItem","attrs":{"id":"f67f73f9-a840-4fd5-b1ed-ae84eb9e044b"},"content":[{"type":"paragraph","attrs":{"id":"dd910fe8-5156-49ad-980e-7f9cc8848694","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"个人版限制要注意。"},{"type":"text","text":" 如果是飞书个人版,App Bot 加群可能会受限,先用私聊跑通 MVP(最小可行性产品)最重要。"}]}]},{"type":"listItem","attrs":{"id":"db2aac6f-0618-4a30-977f-f3b76a50fe5d"},"content":[{"type":"paragraph","attrs":{"id":"cba02a8e-c315-4eb5-b3bc-74ec7218b677","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"本地穿透用 Cloudflare Tunnel。"},{"type":"text","text":" 简单好用,虽然临时域名会变,但调试阶段足够了。"}]}]}]},{"type":"heading","attrs":{"id":"43ba6c5b-115d-4a54-8f63-00c0320d0310","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"05. 下一步:让它真正“管事”"}]},{"type":"paragraph","attrs":{"id":"8cd9af46-5b31-42c3-8625-0ccf5b895607","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"目前,这套系统已经具备了:"},{"type":"text","marks":[{"type":"bold"}],"text":"飞书私聊 → 意图识别 → 模型调度 → 记忆存储 → 飞书回复"},{"type":"text","text":" 的完整闭环。"}]},{"type":"paragraph","attrs":{"id":"b5ee4304-00a0-45d2-af9d-ab260f7473d5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"但这只是个开始。我设计的“交叉监督矩阵”(比如 Claude 审查 DeepSeek 的逻辑漏洞,Gemini 做最终仲裁)还没实现。"},{"type":"text","marks":[{"type":"code"}],"text":"executor.py"},{"type":"text","text":"(并行执行)、"},{"type":"text","marks":[{"type":"code"}],"text":"task_manager.py"},{"type":"text","text":"(任务管理)、"},{"type":"text","marks":[{"type":"code"}],"text":"reporter.py"},{"type":"text","text":"(周报生成)这些真正能让它变成“数字员工”的模块,都因为这两天死磕飞书 I/O 被搁置了。"}]},{"type":"paragraph","attrs":{"id":"4e0f77b9-e9b2-4939-8e4d-ea9bacea6133","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"但没关系,地基打牢了,起高楼只是时间问题。"}]},{"type":"paragraph","attrs":{"id":"2b9c385b-4d39-49ad-9a4c-29ba21839e66","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"如果你也对 AI 中控系统、个人效能工具感兴趣,或者也在踩飞书对接的坑,欢迎在评论区找我交流。"}]},{"type":"image","attrs":{"id":"8d96cb9a-ce5e-4c57-a1ac-d3e141f95c84","src":"https://developer.qcloudimg.com/http-save/audit-11989886/278b2de7aea6f35a15e38a0f98dacc40.png","extension":"png","align":"center","alt":"","showAlt":false,"href":"","boxShadow":"","width":611,"aspectRatio":"1.725989","status":"success","showText":true,"isPercentage":false,"percentage":0,"isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"4de9b88a-074f-4929-a1af-ce7e395e9b46","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"eafb65fb-9c07-4e60-9b9c-d22c001c9b9c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}}]}","createTime":1782741577,"ext":{"closeTextLink":0,"comment_ban":0,"description":"","focusRead":0},"favNum":0,"html":"","isOriginal":0,"likeNum":0,

热门栏目