<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>hllqk blog</title>
        <link>https://hllqk.cn</link>
        <description>AI 开发实践、技术笔记与实用工具</description>
        <lastBuildDate>Sun, 01 Nov 2026 17:23:14 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2026, hllqkb</copyright>
        <item>
            <title><![CDATA[每周的总结]]></title>
            <link>https://hllqk.cn/article/p-be601f64</link>
            <guid>https://hllqk.cn/article/p-be601f64</guid>
            <pubDate>Sun, 01 Nov 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[我已经很久没有写过周报了，与其叫周报，应该叫每周的复盘，听起来像是公司的复盘会一样，其实也大差不大了 日报我是一直有写的，但是每天都一两行，or 一两个字，复盘意义不大，而周报则可以总结一周的学习和工作，无论是公司 or 个人角度来看都是很…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-40bcdaa272b68073b0fbfb97a1fd2350"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-40bcdaa272b6806da78ed51f8d7b3d33">我已经很久没有写过周报了，与其叫周报，应该叫每周的复盘，听起来像是公司的复盘会一样，其实也大差不大了</div><div class="notion-text notion-block-40bcdaa272b680a3b48ff0f40891f23e">日报我是一直有写的，但是每天都一两行，or 一两个字，复盘意义不大，而周报则可以总结一周的学习和工作，无论是公司 or 个人角度来看都是很有必要和价值的</div><div class="notion-text notion-block-40bcdaa272b68007a2bbf0341b94de1e">现在开始复盘吧，这周其实都在处理公司的业务没有花太多时间学习自己的内容，这个是需要注意的，要多花时间提升自己，学习新知识和新的认知</div><div class="notion-text notion-block-40bcdaa272b680b8a2c1c6325334c977">论新知识，就凭着兴趣研究了一下量化策略，搞了一个量化 agent，经过几天的研究，终于还是抵不过腾讯理财通的年化率😂</div><div class="notion-text notion-block-40bcdaa272b680cd931ed4bcdcc21e40">除了学习了我一直都想学的量化，我要把自己心里一直想要的的博客给搭建出来了，现在我已经用上这个博客来发文章了，反正这个博客也没什么人看，就当我个人在这发内容了，然后还搞了最近很火的大肥鱼，成功让它能在 B 站上刷视频，然后发总结到我的 QQ 里面，让它自己去刷一些技术向的、对我有用的、工作上的视频内容，让我每天进行一个学习，感觉还是美滋滋的，而且还可以陪我聊聊天，也可以顺便帮我干一些电脑的杂活，毕竟它的底层是基于 Deepseekharness 的干活能力也不错，虽然相比 claude，codex 可能差远了</div><div class="notion-text notion-block-40bcdaa272b680cf8033c7a9e36f835b">然后最近听了一些有关爱情的播客，现在对爱情有了更多新的认知，还有思考。然后也认识到自己，要以自己的情绪为主，多为自己考虑，多对自己好，多让自己开心，这是最重要的，别人的情绪你接不住，那就不用接，没必要专门为他人兜底，或者对他人有期待 也更不要内耗，要学会转移注意力去做其他事情，转移注意力的方式有很多，但都比专门躺下休息好多，躺下的话，脑子空空，就只会不断回想你目前的担忧内容，然后反复咀嚼，这是毫无价值的，所以学会转移注意力也是处理情绪的一种很重要的课题，我们总是想要在情绪中找到解决方案，不亚于身在此山中，不知庐山真面目的感觉</div><div class="notion-text notion-block-40bcdaa272b68052988dfc29152a5710">只有当我们清醒理智的时候，我们才能做出正确的判断和选择</div><div class="notion-text notion-block-40bcdaa272b6804f8be5e10be75b9f54">这正好也印证了我前几天看到的视频，不要在吵架的时候，对爱的人说伤人的话，也不要在晚上做决定</div><div class="notion-text notion-block-40bcdaa272b68091a09ef7e863572bc6">回到休息这个话题，我们前面提到，我们要学会转移注意力，而不是在有情绪的时候专门躺下休息，这样子会让我们完全无法休息到。但是有时候休息也是很重要的，在大部分方面。学习都讲就劳逸结合，但是这个道理谁不懂呢？只是也没有多少人能够做到，我大一在图书馆卷的时候，也是每天都是早出晚归，一天都要学满多少个小时才罢休，累了就还要学，直到累的不行了才趴着睡一会，这个时候搭子的翻书声就显得格外刺耳……有一个很卷的搭子其实并不是一件很好的事情，你也会被他的节奏所影响，而失去自己的节奏，如果没有自己的内核和节奏，花再多时间学习也是徒劳，不亚于一种流行的打卡文化，纯粹是一种自我感动式的学习</div><div class="notion-text notion-block-40bcdaa272b680a1b981cfaa123638b1">努力的人不一定成功，有效努力的人才能成功</div><div class="notion-text notion-block-40bcdaa272b6806cac22e697cd0bc0bc">我们要多做有效学习，比如一种心流状态的学习，我们可以不对自己设置一个下限，比如最少进入状态多少个小时，人的精力本来就很有限，很难保持一直高精力学习，有一种很著名的学习方式叫做番茄工作法，也顶多是 25 分钟专注学习然后休息 5 分钟</div><div class="notion-text notion-block-40bcdaa272b68091a660c3e3b65570ca">当然我们在公司肯定是不能 25 分钟专注再休息的，有些活是需要连续性的打磨的，至于到底该多久，还是看个人的精力和感受吧</div><div class="notion-text notion-block-40bcdaa272b6803c9efffc085045e2d0">如果你感觉自己精力低下，那就休息，在没精力的时候休息几分钟，可以恢复很多，如果几分钟不够，可能是被消耗的精力实在是太多了，已经为 0 电量了，那就需要花几个 h 休息了，不要硬撑，也不要自责没有花足够时间专注 你的每一次休息都是为了更好的专注，为了更高效率。</div><div class="notion-text notion-block-40bcdaa272b68067b7a8d02dd1b66c3c">如果感觉自己精力很多的话，那就可以进行一个连续几个小时的学习，当然，真别忘了放松，比如走一走，久坐的危害还是很多的，像我有些同事，年纪轻轻就已经…（</div><div class="notion-text notion-block-40bcdaa272b68094ac67e0aef94e513d">在这个高度信息化的时代，如何保持极度专注进行高效学习而不是纯靠意志力，是一个值得深入探讨的话题，有关这个话题，李大钊先生早就教导过我们：要学就学个痛快，要玩就玩个痛快</div><div class="notion-text notion-block-40bcdaa272b680e28cb7d5358f1f4357">在累的时候休息，正好符合我们在舒适区边缘学习的原则，当我们疲惫的时候，正好是处于精力的边缘区，往里是高精力，往外是低精力，这个是我们休息，正好可以保持我们在高精力的状态里去处理舒适区边缘的内容，而且正因为有舒适区边缘的内容，我们才会消耗我们的精力，也才会学习到对我们来说不算困难、但价值比较大的内容，人只能赚到认知内的钱，也只能处理力所能及的事情</div><div class="notion-text notion-block-40bcdaa272b6808195a2c1acac42a909">总之，我们要把困难的事情分解开来，处理我们力所能及的区域，累的时候就休息</div><div class="notion-text notion-block-40bcdaa272b680fdbc60f75e13d2494f"><em>真正的自控高手，不是只会一味地咬牙坚持，而是懂得主动休息，保持平衡的人</em></div><div class="notion-text notion-block-40bcdaa272b6807ca3e1d363b73afcc4">我也经常陷入这种自控困境，平时工作日都是奋力工作学习的，一到节假日就无法控制住自己，大玩特玩，又或者是熬夜通宵，明明知道不好，还总是控制不住，这也是因为没有得到足够的休息和放松，有时候太压抑自己、太控制自己，反而会适得其反，在学习的时候，给自己玩的时间，才不会让自己一直有一种亏欠的心理，才不会把这种亏欠以熬夜的方式补回来</div><div class="notion-text notion-block-40bcdaa272b68092b767ff99a7555e00">要玩就白天玩，晚上是绝对要休息的！熬夜的危害实在是太多太多了……</div><div class="notion-text notion-block-40bcdaa272b680fb97c3f6b8319d33ce">有时候我总想把自己量化成机器，每天完成多少时长的学习，每天按部就班，有足够的自制力，希望自己能坚持，特别是在堕落后这种想法更加强烈，但是人的本能脑和情绪脑是天生趋利避害的，完全不是理性脑可以抗衡的，当一个想玩的念头出现，理性脑很难控制得住，去对抗是很难成功的，在经历了无数次失败和堕落和后悔后，我也渐渐地明白与天性作对是不可为，制止力也不一定代表行动力</div><div class="notion-text notion-block-40bcdaa272b6803c89b1e91a06de467c">这有一个很经典的列子，在堕落的时候，比如控制不住熬夜刷视频，玩游戏，然后晚上时间很晚了才睡觉，基本上都会后悔自己为何不早点睡觉，为何要做出那个选择，后悔的时候理智脑占据了上风，我们巴不得立刻改正，还列举了一大堆早睡早起的方案，结果第二天就忘了一个精光</div><div class="notion-text notion-block-40bcdaa272b680f4994ceb5549f8f1cb">改变自己的天性很难，人人都想玩，想放松，放松不够多了就会放纵，所以我们还是需要把安排时间放松的，比如休息，又或者娱乐，把他们放到白天，你的晚上就不会一塌糊涂，这也是对身体和精神的一种保护</div><div class="notion-text notion-block-40bcdaa272b6807eb767c07662df3499">当然有时候我们熬夜也不是单纯因为没有放松，可能是单纯无聊，又或者是孤独，又或者遇到了焦虑的事情</div><div class="notion-text notion-block-40bcdaa272b680438b5bdb2cb8f140de">与其纠结怎么样解决这些事情，我也没有很好的办法，这些事情本身就很难解决，而且往往会在我们要入睡前来影响我们的情绪</div><div class="notion-text notion-block-40bcdaa272b680feb880e5244681b0f5">但是我们可以提升认知，认知到第二天早起的重要性，是可以帮助我们在这些胡乱的思绪里面做出一个平衡的，就像第二天要早起上班一样</div><div class="notion-text notion-block-40bcdaa272b68091a3ede3107d5b9b55">我们也可以改变环境，设置一些神经反馈机制，比如刷完牙之后、洗完澡之后就睡觉，又比如，遇到烦心事的时候，去干其他不相关的事情 15 分钟，往往是一种很好的解决情绪方案，再比如，我们每次坚持完之后，给自己一些正向奖励，我们才能不断地坚持，坚持坚持，再坚持，贯穿昆虫记的自始至终只有两字，坚持。</div><div class="notion-text notion-block-40bcdaa272b6801088d4f9aa39e1bb14">如果坚持早睡的话，那每天早上我们都会有一份很好的礼物，那就是纯净的注意力，我晚上的各种焦虑、各种烦心事，第二天起来都会少很多，或者直接清零，这是大脑的工作机制：它每天都要清空大脑里的各种缓存。这时候我们的精力和注意力是最强的，正是我们开始专注的最佳时机，然后通过这种专注，我们在触发我们的专注回路，越来越专注，久而久之就可以形成一个注意力的回路，我要早起专注，就相当于早上有工作要干，我们就会渐渐的养成一个早睡的习惯，早睡真的益处很多，我们不仅要意识到，还要实现它</div><div class="notion-text notion-block-40bcdaa272b68005ac64dbc758eed1d7">关于早睡，网上有很多教程，我们要做的不单单是收藏，还要去学习，去运用，然后再输出相关教程，再通过输出倒闭输入，只有输出到其他人能通俗易懂的程度，我们才算真正的理解了这么一个事，真正才能运用这么一个事</div><div class="notion-text notion-block-40bcdaa272b6806a8378fe8071035361">我写博客，也是这么一个原理</div><div class="notion-text notion-block-40bcdaa272b680a49d12cad72930fa70">而且不单单要让他能通俗易懂，还要让看的人能有收获感，所以要细心打磨自己的每一篇文章，像是孩子一样培养他，它也会渐渐的长大，在未来的某一天回馈你的，如果连自己写的文章都不用心，用 AI 随意生成一篇，又或者随便写点没用的内容，其他人又怎么会看呢</div><div class="notion-text notion-block-40bcdaa272b6803b9e36ce03d5e833b0">这周的总结就先到这吧，下周也要设置个待办提醒自己写总结，不能每次都忘记了，然后后面再搞一个年度总结、季度总结这些的，先有周总结，再有季度，再有年总结，感觉这样才能不断的进步和成长，加油，给自己说一句，“你是最棒的！”，我们干活需要有正向反馈，每天给自己打打气，多做做正向冥想之类的，有一个积极的心态，无论是对精神层面还是身体健康都有莫大好处！记住，人活着就是为了开心啊~</div><div class="notion-blank notion-block-40bcdaa272b680f093ebcc28865e2384"> </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-40bcdaa272b680559201cb32595ceb4c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:339px;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/40bcdaa2-72b6-8055-9201-cb32595ceb4c?src=attachment%3A9124340d-3366-4709-8f47-ad9986dfa3cc%3A1000022344.jpg"/></div></figure><div class="notion-blank notion-block-40bcdaa272b68096ba3aead48828e641"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[关于爱情的几件事]]></title>
            <link>https://hllqk.cn/article/p-db54bfee</link>
            <guid>https://hllqk.cn/article/p-db54bfee</guid>
            <pubDate>Sat, 31 Oct 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[摘要： 1.他不是你的全部，你也不是他的全部。 2.再亲密的两个人也需要有自己的空间。 3.不要把你付出变成对方不知道存在的账单。 4.很多问题不是后来才出现的，只是你们以前没有聊过。 5.不是因为关系稳定了就停止吸引对方。 6.可以听别人…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-408cdaa272b68082917ed10f51a14eaf"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-40acdaa272b6805c98c5e3d20767e8ca">摘要：</div><div class="notion-text notion-block-40acdaa272b680a090b9f8575a05b797"><em>1.他不是你的全部，你也不是他的全部。
2.再亲密的两个人也需要有自己的空间。
3.不要把你付出变成对方不知道存在的账单。
4.很多问题不是后来才出现的，只是你们以前没有聊过。
5.不是因为关系稳定了就停止吸引对方。
6.可以听别人的意见，但不要把自己的感情交给别人决定。</em></div><div class="notion-text notion-block-40bcdaa272b6803dbd20fd1cc6c567b9">本来写了很多，但是都删了，要说的话太多了，但是又不知道从何说起，后面再写一篇专门讲讲吧</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[我是怎么样从零开始折腾的一个新博客]]></title>
            <link>https://hllqk.cn/article/how-i-built-this-blog</link>
            <guid>https://hllqk.cn/article/how-i-built-this-blog</guid>
            <pubDate>Fri, 30 Oct 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[我想要一个像书一样的博客]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-f8d133d911ee459698479c5ce51bfb5f"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-cf5749fee5b44862968026eb958ad8d9">从我初中开始，搞过很多博客，最开始是从 GitHub Pages 上的 Jekyll 起步，后来换到 <a class="notion-link" href="https://www.hllqk.cn/" target="_blank" rel="noopener noreferrer">hllqk.cn</a> 的 Hexo，以及各种常规的动态博客，比如 wordpress，最后现在搬到了 Notion + NotionNext</div><div class="notion-text notion-block-40acdaa272b680d3855df02bb36651e5">为什么选择了 Notion 呢？我平时也是把它当做知识库用来存文档的，后面听说可以拿来用博客，正好我也喜欢在手机上记录内容，Notion就成为了一个很好的同步平台。</div><div class="notion-text notion-block-40acdaa272b680bda971f19debcbe413">选择 Notion 主要是因为它的方便，还有是因为它的图床是免费的，像是Jekyll它已经过时了，所以我后面选择了 Hexo，我花了整整 1 年时间提升它的 UI 和性能，还做了 SEO 优化，在这期间我花了不少心思，但最后还是弃用了，因为当时那个 hexo 版本太低了，导致了各种奇奇怪怪的前端问题，解决也很复杂。想要做一个兼容性的版本提升的话，在当时我也没有想出一个很好的办法。因为当时还是没有 AI 的，现在已经有 AI 了，应该可以非常方便的实现一个兼容性的提升。但是最后我还是选择了弃用，主要是因为，首先它想要实现在手机上发文章有点麻烦。我个人还是比较喜欢 Notion 这个软件，然后想实现在 Notion 上进行发文章的，正好看到有 Notion Next 这个项目，所以我就直接搭建了，由于用的是 Cf Page，所以是免费的，而且还可以做一个托管，也不单单是因为这一个点，还有一个点是因为以前做的那个博客太花里胡哨了，而且太花里胡哨的博客加载也很慢，这个博客的速度已经提升到了极致，至于怎么提升的，就是通过LightHouse 排查和各种性能测试，如果感兴趣，完全可以交给 CC 出一版方案，我个人觉得网站的速度提升还是很重要的，目前我现在的审美变成了比较喜欢简约风，而不是以前那种花里胡哨的页面，现在是喜欢类似 Claude 的那种页面，读起来不烧心，很舒服，非常感兴趣，所以我就搭建了现在这个博客，全程依靠 claude 开发，整体布局也参考了 claude，字体选用我最喜欢的白鹭文楷，由于这个博客遵循我的简约主旨，所以很快就搭起来上线了，目前算是定官盖论，不打算折腾了</div><div class="notion-text notion-block-40acdaa272b680719e58c9ac14345506">果然正如三年前说的话一样，美化的尽头是默认，前几年搞的各种花里胡哨的博客，最终还是回到了朴朴素素的样子</div><div class="notion-text notion-block-40acdaa272b680fa9e46cca8a5096a5d">至于为什么这么多年了，又重新开始写文章了，是因为我在想，自己学到一些东西，也要进行产出，只有能用文字来描述，才算真正的学习，只有能输出的内容能让一个不了解的人进行学习，自己才算是真正的了解透了这个内容</div><div class="notion-text notion-block-40acdaa272b68030a94df725a0088ecc">确实也有很多年没有写文章了，无论是写小说，还是写个人的日记，已经没有以前那种文采了，哈哈，感觉最近几年 AI 爆火，用 AI 写文本越来越多，越来越多那种 AI 生成的内容，看着非常的咬文嚼字，我本人感觉也深受其害，现在输出的内容，感觉自己也有点像 AI 生成的，已经没有人话了😃，但这些内容都是我一个个手敲的加上语音输入</div><div class="notion-text notion-block-40acdaa272b680048ce4fa72807caaf4">希望自己能多多产出文章，提升自己的文笔，同时也能把一个内容了解透彻，通过输出、再输入、再输出，不断学习</div><div class="notion-blank notion-block-40acdaa272b6806c8c46c2a4ef85b666"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[在手机上用 Notion App 发博客：从写到上线]]></title>
            <link>https://hllqk.cn/article/notion-app-publish-guide</link>
            <guid>https://hllqk.cn/article/notion-app-publish-guide</guid>
            <pubDate>Wed, 28 Oct 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[手机 Notion App 发博客速查：三步发出去，撤稿、定时发布和每个属性怎么填。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-809592f5f63e4c208a101ab99b05c85e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7890077ce8f94677b433c83931feedd0" data-id="7890077ce8f94677b433c83931feedd0"><span><div id="7890077ce8f94677b433c83931feedd0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7890077ce8f94677b433c83931feedd0" title="三步发出去"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">三步发出去</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-6570825ae47447e3afb214f1eca92583" style="list-style-type:decimal"><li>在博客数据库点「新建」，会自动带上 type=Post、status=Draft、date=今天。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-e27767806d1246208b6f1a869a8f04c7" style="list-style-type:decimal"><li>写标题和正文。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-0c00d8f965db4e72ba8d1520da5b59ab" style="list-style-type:decimal"><li>status 改成 Published，放下手机就行。</li></ol><div class="notion-text notion-block-bc11a92ffc374a0ca4b4e07a81e146b1">停手约 10 分钟后网站开始更新，一般 15 到 25 分钟能看到，不用手动点。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-a1df59aea122413591f6fe107c3eaae8" data-id="a1df59aea122413591f6fe107c3eaae8"><span><div id="a1df59aea122413591f6fe107c3eaae8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a1df59aea122413591f6fe107c3eaae8" title="发布和撤稿"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">发布和撤稿</span></span></h2><ul class="notion-list notion-list-disc notion-block-8a89b53937ff4cb094c2caa8f04c1473"><li><b>Draft</b>：怎么改都不会发。撤稿也是改回 Draft，会自动下线。</li></ul><ul class="notion-list notion-list-disc notion-block-365e3ab765ae4e199644858a15620519"><li><b>Invisible</b>：不进首页和列表，知道链接的人能打开。</li></ul><ul class="notion-list notion-list-disc notion-block-a78e15690f5b429da8ae9503acf27221"><li><b>date</b>：填未来的时间，到点自动发布；清空就用页面创建时间。</li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-dd3f31c106324f7cb3d1358c3a6f4e15" data-id="dd3f31c106324f7cb3d1358c3a6f4e15"><span><div id="dd3f31c106324f7cb3d1358c3a6f4e15" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dd3f31c106324f7cb3d1358c3a6f4e15" title="属性按需填"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">属性按需填</span></span></h2><ul class="notion-list notion-list-disc notion-block-c97a8a97c6d74c7bae3688b882cea34b"><li><b>slug</b>：空着会自动生成短链接，改标题也不变。自己填就用小写英文和短横线。发布后别改，旧链接会打不开。</li></ul><ul class="notion-list notion-list-disc notion-block-c534bed461274aa8988a657b70ed8f8a"><li><b>summary</b>：空着取正文开头约 120 字，加密文章不取。</li></ul><ul class="notion-list notion-list-disc notion-block-22d0881b59094039a1395e083411cd34"><li><b>category</b>：空着归到「随笔」。可选 AI 与工具、算法与深度学习、开发笔记、环境配置、建站与博客、随笔、转载。</li></ul><ul class="notion-list notion-list-disc notion-block-d958056ca3cd4688a3e34ebfb828c2e9"><li><b>tags</b>：可多选，也能直接打新标签，空着就没有。</li></ul><ul class="notion-list notion-list-disc notion-block-3dd935dd7bef49cabfe01e87183d6665"><li><b>password</b>：填了就加密。读者输对一次，这台设备会记住；点「锁上」就要重新输。密码要长，别用 123456。</li></ul><div class="notion-text notion-block-5760d288ba0a495bad7cd7e74de29602">其余几个平时不用管：CAN_COPY 留空就允许复制，填 false 禁止复制这一篇；icon 不用填；featured 勾上会进首页「从这里读起」；series 和 seriesOrder 用来把几篇串成系列；source_url 是文章在别处首发时填原文地址。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-04aa282d25b94106b385e8b2cdb4a15a" data-id="04aa282d25b94106b385e8b2cdb4a15a"><span><div id="04aa282d25b94106b385e8b2cdb4a15a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#04aa282d25b94106b385e8b2cdb4a15a" title="正文和更新"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">正文和更新</span></span></h2><ul class="notion-list notion-list-disc notion-block-324a297209a74a2ab27e614b60a8296f"><li><b>图片</b>：输入 <code class="notion-inline-code">/图片</code>（英文界面 <code class="notion-inline-code">/image</code>），选上传，从相册挑。</li></ul><ul class="notion-list notion-list-disc notion-block-230e202b008f4a558ff67d4c99375f5f"><li><b>代码</b>：输入 <code class="notion-inline-code">/代码</code>（<code class="notion-inline-code">/code</code>），点代码块左上角选语言。选对才有高亮，Plain Text 没颜色。</li></ul><ul class="notion-list notion-list-disc notion-block-4aee48d75d46413d8ff09f130f5e40ce"><li><b>没更新</b>：等了 25 分钟左右还没看到，就查 type 是不是 Post、status 是不是 Published。</li></ul><div class="notion-text notion-block-053c8aa5839f4ad5ae7831b3580a00eb">页面顶部蓝条「This page is live on the web」说的是 Notion 自己的公开页，不是博客。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A/B 看不出来的时候，搜索排序还能怎么评]]></title>
            <link>https://hllqk.cn/article/ab-search-ranking-eval</link>
            <guid>https://hllqk.cn/article/ab-search-ranking-eval</guid>
            <pubDate>Mon, 26 Oct 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[假设你改了一版搜索排序，开了 A/B 实验，跑了两周，数据上上下下地晃，就是不显著。那这次到底改好了还是改坏了？说不清。 这几天我在补搜索评估的资料，发现这种情]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-a72004daa1c642bab0966bda2a94592c"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-46df64ce3d4247e6ac278579e664ac6b">假设你改了一版搜索排序，开了 A/B 实验，跑了两周，数据上上下下地晃，就是不显著。那这次到底改好了还是改坏了？说不清。</div><div class="notion-text notion-block-0aaff9242889459088b1b64912003918">这几天我在补搜索评估的资料，发现这种情况很常见，也有不少现成的办法。下面按我自己理解的顺序整理一遍。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3475afd929184f40bda48a8e99fe8e9a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/3475afd9-2918-4f40-bda4-8a8e99fe8e9a?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fab-search-ranking-eval-1.jpg%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-651f4d24ddf74e339abb1d52ae32680f">✻ 01 · SCOPE</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-20988ec4c89a4d608772f1f642fdcfb9" data-id="20988ec4c89a4d608772f1f642fdcfb9"><span><div id="20988ec4c89a4d608772f1f642fdcfb9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#20988ec4c89a4d608772f1f642fdcfb9" title="先想清楚：你到底想知道什么"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">先想清楚：你到底想知道什么</span></span></h4><div class="notion-text notion-block-ea31df907bb343f288614bb743610894">「排序好不好」其实是三个不同的问题：</div><div class="notion-text notion-block-7dcaa686949146b6971655caf4bf0f2f">1.搜出来的东西和搜索词对不对得上。这叫相关性。</div><div class="notion-text notion-block-79f3a34aacae4192bfab39a2ca096786">2.用户更爱点哪一版的结果。这是行为偏好。</div><div class="notion-text notion-block-fef613a48e0043648bbd6bff226aa0ef">3.换了排序以后，留存、转化有没有变。这是业务结果。</div><div class="notion-text notion-block-85d7c859b2744bcead465cb6485b0b64">很多人会把点击直接当成「搜得准」，但这两件事不一样。排在第一位的东西，哪怕一般，被点的机会也比排第二十的好东西大得多，这叫位置偏差。后面讲的几种办法，各自只回答其中一个问题，先想清楚要哪个答案，再挑办法。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2bd75e78ee414f3891a80203a1b8e28c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2bd75e78-ee41-4f38-91a8-0203a1b8e28c?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fab-search-ranking-eval-2.jpg%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-7f5ea2feafaa462eadab62d610007002">✻ 02 · POWER</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-af90e4d6a2344d969fee8d442bb97da8" data-id="af90e4d6a2344d969fee8d442bb97da8"><span><div id="af90e4d6a2344d969fee8d442bb97da8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#af90e4d6a2344d969fee8d442bb97da8" title="实验看不出来，先算算样本够不够"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">实验看不出来，先算算样本够不够</span></span></h4><div class="notion-text notion-block-5f2096a7c87f448e9a6e021cd6a5f8ce">A/B 没结论，最先该怀疑的是样本不够。当然也可能改动本来就没什么效果，或者指标选得不对。</div><div class="notion-text notion-block-169b4ffa06ef4212b5dd39dc7845fcf3">样本要多少，有个现成的估算公式。Ron Kohavi 等人 2007 年在 KDD 发的实验指南里写的是：显著性水平 5%、想有 90% 的把握看出差别、各组人数差不多的时候，总共大约需要 n = (4rσ/Δ)² 个用户。r 是一共几个版本（对照组也算，普通 A/B 就是 2），σ 是指标的标准差，也就是它平时晃得有多厉害，Δ 是你想看出来的最小差别，按绝对值算。</div><div class="notion-text notion-block-118fab8bd4ff4f2aaa6044c1d94c1e6a">论文里举了个假设的例子：转化率 5%，想看出 5% 的相对变化，也就是从 5% 涨到 5.25%，总共要不到 50 万人；要是只想看出 20% 的相对变化，也就是涨到 6%，3 万多人就够了。差别放大 4 倍，人数降到原来的 1/16，因为公式里是平方。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b91893489f234082971999d8ef075839"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/b9189348-9f23-4082-9719-99d8ef075839?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fab-search-ranking-eval-3.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-41ebf2b00c7847378ec8a9df625aa0e7">打个比方：想看清的东西越小，放大镜就得越大，而且是成倍地大。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-f52fa6726949486b9796df6ee1792f76"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/f52fa672-6949-486b-9796-df6ee1792f76?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fab-search-ranking-eval-4.jpg%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2508a64b046c4b8599688a52effe4cd7">有两个地方容易理解错：</div><div class="notion-text notion-block-e8836a2ff84f4fb98694960c3e565a1d">●公式算出来的是「有 90% 的把握看出这么大的变化」要多少人，不是说小于这个变化就一定看不出来。</div><div class="notion-text notion-block-ee1c0e84c3844fbf9aa13b50a8f29b1b">●不显著不等于没效果。更该看的是效果大概有多大、置信区间有多宽。区间很宽，说明还不知道；区间很窄、紧贴着零，才比较像是真没影响。</div><div class="notion-text notion-block-e1f40bddfb6d419bb11dfcc8c97b27e9">所以开实验之前，最好先拿自己的流量和指标的波动算一遍。如果你预计的改动幅度比能看出来的范围小一大截，就提前想别的办法，别等跑完了对着「不显著」发愁。</div><div class="notion-text notion-block-85f061cb124f4a64988f3f4d1d619342">✻ 03 · SENSITIVITY</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-49ded3f3e3314b3e8bd68275ab9846b2" data-id="49ded3f3e3314b3e8bd68275ab9846b2"><span><div id="49ded3f3e3314b3e8bd68275ab9846b2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#49ded3f3e3314b3e8bd68275ab9846b2" title="样本加不上去，就让实验更灵敏"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">样本加不上去，就让实验更灵敏</span></span></h4><div class="notion-text notion-block-2ca7dfbd1f5a452f8180d1a719002e82">第一招叫 CUPED，用老数据把噪声扣掉。这是微软的 Deng 等人 2013 年在 WSDM 发的方法。道理是：每个人的行为本来就有高有低，有人天天搜，有人一周搜一次。如果用实验开始前每个人的历史数据，把这部分「本来就有」的差异扣掉，剩下的波动就小多了。论文总结 Bing 上的结果时说，波动（方差）降一半，就只需要一半的用户或者一半的时间。</div><div class="notion-text notion-block-46d6de3f749544318581e359f74435f9">不过要注意三点：不同指标能扣掉多少差别很大；「时间减半」还要看用户多久回来一次、观察多长时间；拿来扣的历史数据必须是实验开始前的，不能被这次实验影响。另外它不是一种新实验，只是分析 A/B 结果的一种算法。</div><div class="notion-text notion-block-77d54f006e274693a69e04824b5d3309">第二招叫交错实验（interleaving），把两版结果混在一起给同一个人看。普通 A/B 是分两拨人、各看一版；交错实验是同一次搜索里，把两版的结果按一定规则混成一个列表，看用户点的更多来自哪一版。</div><div class="notion-text notion-block-83e8df0fde164c7898df958cb39ee12f">常用的混法叫 Team-Draft，有点像两个队长轮流挑队员：每轮随机决定谁先挑，各自挑自己排序里还没被选走的最好结果，这样哪一版都不会总占着前排。点击记给挑中那条结果的一方。因为是同一个人在同一个列表里比较，人和人之间的差异就不干扰了，比较排序时通常比分组实验灵敏得多。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-366dbea402234ea382bb79455b0cad4c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/366dbea4-0223-4ea3-82bb-79455b0cad4c?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fab-search-ranking-eval-5.jpg%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2e2ae8e5cfd045c6b895bfe55e6b41fa">它的局限是只能告诉你「用户更爱点哪一版」，看不到整页体验、长期留存、收入这些。</div><div class="notion-text notion-block-39b96b012e624abfb8b21d39795b4b68">✻ 04 · OFFLINE</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-7fd4221f231a4604b1e6c3175d0ef794" data-id="7fd4221f231a4604b1e6c3175d0ef794"><span><div id="7fd4221f231a4604b1e6c3175d0ef794" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7fd4221f231a4604b1e6c3175d0ef794" title="线上信号不够，就在线下评相关性"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">线上信号不够，就在线下评相关性</span></span></h4><div class="notion-text notion-block-b4c961f6490b452996b3875502e5e739">还有一种办法是不等用户点，自己准备一批搜索词，给每条结果打「相关不相关」，算个分，两版用同样的词比一比。几个要点：</div><div class="notion-text notion-block-791953b00cc0435f8bfd52149607b980">1.先想好要评什么，再挑词。想知道整体体验，就按真实搜索的频率来挑，热门词多挑；想专门看冷门词，就把热门、中等、冷门分开挑、分开算。两种目的别混在一个平均数里。</div><div class="notion-text notion-block-8d01fe9ed4d44d9eb0d15ad91d9e1c20">2.相关分几档。「很相关、有点相关、不相关」比只分对错更能看出两版的差别。</div><div class="notion-text notion-block-ecb5cff1ced64c6c90e57ac81cc40ae5">3.用 NDCG@k 算总分。每条结果按相关程度给分，越靠前的权重越大，最后除以「理想排法」能拿到的分数。k 是只看前几条，比如前 10 条。两版要用同一批词、同一套打分标准、同一个 k。</div><div class="notion-text notion-block-fae2c6327d844587be3a56e84b2b4db4">4.算一下误差。一批词上分数高一点，可能只是碰巧挑到了好词。可以把这批词反复重新抽样来算，看差值的置信区间有多宽。</div><div class="notion-text notion-block-46bf18796b9642d580b5bd835284ca63">5.简单规则只能粗筛。比如「结果的标签包含全部搜索词就算相关」，算起来快，但包含了不代表用户想要，没包含也不代表不相关。</div><div class="notion-text notion-block-d37bd35203a1433e9fc03245e875ab02">✻ 05 · LABELS</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-43fdbab6254948c08058ad554b0952c3" data-id="43fdbab6254948c08058ad554b0952c3"><span><div id="43fdbab6254948c08058ad554b0952c3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#43fdbab6254948c08058ad554b0952c3" title="打分谁来打：人还是模型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">打分谁来打：人还是模型</span></span></h4><div class="notion-text notion-block-2d8b7fb588f7482a8734cf8b80661b00">人来标最常见，但慢、贵，而且人也会看错，会对规则理解不一。现在有一种做法是让大模型来标。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-5102e1f4cfaf4e07bea03731c89e9bbe"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/5102e1f4-cfaf-4e07-bea0-3731c89e9bbe?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fab-search-ranking-eval-6.jpg%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-ef66c374cc4847e7be1102e573260042">微软的 Paul Thomas 等人在 SIGIR 2024 的论文里讲了 Bing 怎么做：先拿真实搜索者的详细反馈当参照，挑出跟这些反馈最一致的模型和提示词，再让模型大批量地标。在他们的设置下，模型标出来的质量能跟人工差不多，在 Bing 的数据上还比他们对比的外包标注员好。论文也提到，提示词只是换个说法，跟参照的一致程度就会变。</div><div class="notion-text notion-block-f6eb1204d301409da34b3aa57ea1cd64">所以用模型来打分，一定要留一批没用来调提示词的数据做检验：</div><div class="notion-text notion-block-cbd65b29567442659febbd443699f650">1.准备一批人工认真标过的参照答案，尽量贴近真实用户想要什么。</div><div class="notion-text notion-block-0c5e71bf98c24768bf3bca5a59c5ea14">2.按搜索词把它分成两份：一份用来调，一份用来验。同一个词不要两份里都有。</div><div class="notion-text notion-block-8d9520eb6dd7451681c6724c03f13c59">3.在第一份上挑模型、改提示词；定下来以后，只在第二份上看一次准不准。</div><div class="notion-text notion-block-efdeec7434ca4902af2cac1ed54e31c0">4.正式评的时候，把两版结果混在一起、不告诉模型哪条来自哪版，免得它偏心。</div><div class="notion-text notion-block-8b6a938eedbc44298e456b035c52e4f8">5.过一阵子再抽一批让人看一遍，确认标准没有慢慢跑偏。</div><div class="notion-text notion-block-4cf99bcc6afd4974941369df59e2c4b0">还有一个坑：如果简单规则和模型其实看的是同一份标签，它俩说法一致也证明不了什么，标签一错，两边一起错。这也是为什么要单独留一批人工检验的数据。</div><div class="notion-text notion-block-9f7480f99f694fc7803872dfee3361e4">✻ ∞ · EPILOGUE</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-7caddc4ce76443f6832d3a37dbae737a" data-id="7caddc4ce76443f6832d3a37dbae737a"><span><div id="7caddc4ce76443f6832d3a37dbae737a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7caddc4ce76443f6832d3a37dbae737a" title="最后"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">最后</span></span></h4><div class="notion-text notion-block-f89b1dbee7b64be6ab1d9015a97a6dd9">这些办法回答的不是同一个问题。线下评相关性，看的是搜得准不准；交错实验，看的是用户更爱哪一版；A/B 加上 CUPED，看的是业务数据有没有变。流量够，三件事都能做。流量不够，A/B 最后可能还是给不出明确结论，这时候老老实实写「还不确定」，比硬下结论强。</div><div class="notion-text notion-block-dcd44894302e4cbbbd172b46a2cf3c55">我自己还没想明白的一点：线下评下来相关性变好了，线上点击却变差了，这时候该信哪个？你们碰到过吗？</div><div class="notion-text notion-block-d28ef7931b6b44c485e351e3ad5e0d1b">✻ ✻ ✻</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI 写代码变快以后，我卡在了哪里]]></title>
            <link>https://hllqk.cn/article/ai-coding-faster-stuck</link>
            <guid>https://hllqk.cn/article/ai-coding-faster-stuck</guid>
            <pubDate>Wed, 21 Oct 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[✻ 写代码已经不是瓶颈了，瓶颈到了 git、构建和 CI 这些环节。 —— 转述自 Anthropic 工程博客 10 月 13 日，Anthropic 发了一]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-36efccfee8794f35912ec777d6e27ad7"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-733423384af54e2f9810b8a1a8f92aa0">✻</div><div class="notion-text notion-block-cbf8b50d21a4432a9d2da77c61dc5d9a">写代码已经不是瓶颈了，瓶颈到了 git、构建和 CI 这些环节。</div><div class="notion-text notion-block-63c915bb7f5a441a9e586eba2fc00669">—— 转述自 Anthropic 工程博客</div><div class="notion-text notion-block-9bd5bf886c0a40679c87c32e6a9eed44">10 月 13 日，Anthropic 发了一篇工程博客，讲他们为什么自己做了一套版本控制系统。</div><div class="notion-text notion-block-4680c48b8044421797694cac048b9504">起因是合并量。今年 5 月，他们的主仓库每天大约合并 2500 次，到 9 月超过了 3 万次，Claude 让代码产出涨得太快。主分支历史大约 100GB，CI 每天要 checkout 约 2500 万次，原来的 git 镜像在容量和运维上都吃不消。新系统把提交、合并、rebase 放到服务端执行，文件用到才拉，CI 拉代码从几分钟缩到几秒。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-da08184ec7824c5a833952f7cc6c9c67"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/da08184e-c782-4c5a-8339-52f7cc6c9c67?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fai-coding-faster-stuck-1.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-23fb1406e13a4a47abda1f837fb24af9">我在一家公司做后端实习，量级跟他们没法比，卡住的原因也不一样。他们是机器扛不住吞吐，我这边多半是拿不准 AI 写的东西到底对不对。相同的一点是，代码写完之后的那些环节，开始比写代码本身更费时间。</div><div class="notion-text notion-block-87e4215105ba4b89bf1a28dbc6acfc6a">本文看点</div><div class="notion-text notion-block-a909b07d77b0450bb5959ecf0f8f4e3e">01测试是绿的，不代表真测过</div><div class="notion-text notion-block-ff4101edb98a48679c374025f3df6371">02三篇 agent 工程文章，和我的对照</div><div class="notion-text notion-block-bdcab02b608e44ac8a1d2e9016acabd8">03评估这件事，我还没做好</div><div class="notion-text notion-block-d5d3536d37ad4763be2c6737c9f08e37">✻ 01 · IN PRACTICE</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-981666d70e1f4896a89ca4c71183569e" data-id="981666d70e1f4896a89ca4c71183569e"><span><div id="981666d70e1f4896a89ca4c71183569e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#981666d70e1f4896a89ca4c71183569e" title="我这边的情况"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">我这边的情况</span></span></h4><div class="notion-text notion-block-8331e63d7cde492a8911d65f2a1eb967">实习三个多月，我合了 140 多个 PR，分在 11 个仓库，大部分代码是 Claude Code 和 Codex 写的。我的时间越来越多花在三件事上：看它改了什么，核对测试环境里跑的是不是这版代码，决定这次改动要验到什么程度才算完。这是体感，我没拿数据算过。</div><div class="notion-text notion-block-b6d71939bf0a43779b6a16cac361827b">踩得最多的几个坑：</div><div class="notion-text notion-block-cce89b6631bf4ef69020c9f9b7239c0c">●本地跑 lint 太吃内存，两个同时跑会被系统杀掉。后来我就不在本地跑了，交给 CI。</div><div class="notion-text notion-block-9140f9e07aa440cf96d606a74e6e9eed">●测试显示通过，不代表真跑过。缺一个依赖工具，相关的那几条测试会自动跳过，结果照样是绿的。</div><div class="notion-text notion-block-e1c0b38703424388831d75c427eb2195">●测试环境就绪了，跑的也不一定是我这次的提交。我会先核对版本号，对上了再测。</div><div class="notion-text notion-block-bd9a452838074ef4bf8864758531260f">✻ 02 · READING NOTES</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-16fc193dd737490fbabba05cea7af234" data-id="16fc193dd737490fbabba05cea7af234"><span><div id="16fc193dd737490fbabba05cea7af234" class="notion-header-anchor"></div><a class="notion-hash-link" href="#16fc193dd737490fbabba05cea7af234" title="读到的几篇文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">读到的几篇文章</span></span></h4><div class="notion-text notion-block-67acb28daa9a46d7bf4317574abe8fa3">最近几个月读了些讲 agent 工程的文章，有几篇正好能对上。</div><div class="notion-text notion-block-0c8e4bc1f2654546ae8db20cbbf806f1">✻ 出一次错，补一处环境</div><div class="notion-text notion-block-0122cf917326447b948fe604afed4c21">Terraform 的作者 Mitchell Hashimoto 今年 2 月写了自己用 AI 的经历，提到“engineer the harness”：agent 每犯一次错，就在它的工作环境里补一样东西，让这类错少犯。补法有两种，一是写进 AGENTS.md 这类说明文件，二是给它写专门的工具，比如截图、只跑相关测试、做验证。</div><div class="notion-text notion-block-a078e19aad38430c8cc06a98e6129cb3">我也是这么一条条补上来的，分两类。一类是说明文件：每个模块目录下有一份 AGENTS.md，要求动代码前先读。它只起提醒作用，AI 偶尔还是会漏看。另一类是钩子，由程序直接拦：数据库迁移有个校验文件只能用命令生成，为了防止 AI 手改，碰它就拦下；一轮对话结束时还有没提交的改动，也会被拦住提醒。</div><div class="notion-text notion-block-823cbfb5df1d42e4aa8f41c63e3eff55">能写成钩子的我尽量写成钩子。说明文件靠模型自觉，钩子不用。</div><div class="notion-text notion-block-5c558b2e74df4e96baeebd250f8c5ccf">✻ 上下文要管</div><div class="notion-text notion-block-83e5924d9a984b1ca9c8487efaaa5f28">LangChain 10 月 14 日写了他们的 Deep Agents 怎么管理记忆。按文中的默认配置：工具返回超过约 2 万 token 就存成文件，模型只看一段预览和路径；上下文用到 85% 时把旧消息压成摘要，完整记录另存，需要时能翻回去；skill 平时只给简介，用到才读全文；长期记忆放在一个 markdown 文件里，每次调用模型都带上。文件在自己手里，换了模型也能接着用。</div><div class="notion-text notion-block-3e27489e7abf41e3a69afb3d4a5d2e7c">我给 Claude Code 也攒了一个记忆文件夹，现在 141 条，一条记一件事：哪个环境的地址是什么，哪个测试本来就会随机失败，哪类消息不许它自己发出去，某个功能上线后该看哪条日志。另有一个索引，每条一行。开新对话时先读索引，具体内容用到再打开。</div><div class="notion-text notion-block-056b7d07d71744efa6f47f24b3098cf8">好处是不用每次从头交代背景。问题是会过期，我隔一阵就得清一遍，不然它会把三周前的状态当成现在。</div><div class="notion-text notion-block-42a9eea965664ff5a9db441d5872b5bb">✻ 一个写，一个审</div><div class="notion-text notion-block-3f2bb8cb3543474a97c2442ef03831d7">Cognition（做 Devin 的公司）去年 6 月写过《Don’t Build Multi-Agents》，反对让多个 agent 同时改代码，理由是每个 agent 都会做别人看不到的决定，合到一起就冲突。今年 4 月同一位作者写了续篇，说法有了调整：多个 agent 一起改代码，现在仍然不太行；只让一个 agent 改，其他 agent 负责审查或者在难题上出主意，这种做法已经能用了。</div><div class="notion-text notion-block-7ac485aa205240d484d7a2c0130ac1e8">他们 6 月推出的 Fusion 就是这个思路，9 月又放进了桌面端和命令行。一个强模型当 lead，定计划、审结果；一个便宜的模型当 sidekick，翻代码、改代码、跑测试，两边只传任务说明和结果。按他们贴出的数据，成本降了一到四成多。得分方面，Fable 那组和单用强模型基本持平，Astra 那组有两项掉了 5 到 6 分，比如 Terminal-Bench 4 从 55.6 降到 50.0。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-ad163d962b6c4f4082e088d23d8323cf"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/ad163d96-2b6c-4f40-82e0-88d23d8323cf?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fwechat%2Fai-coding-faster-stuck-2.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-cf433b31bd8f4c4e994991038d85f058">我平时的做法简单得多：Claude Code 写完，让 Codex 用高推理强度看一遍这次改动的文件，它提的问题我核过再决定改不改，接近续篇里说的“上下文干净的审查者”。至于效果来自换了个模型，还是来自换了一个没被前面对话带偏的上下文，我没对比过，说不准。</div><div class="notion-text notion-block-b83576ea952443a9ad0c0a63c511ade2">✻ 03 · OPEN QUESTIONS</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-9bcc8fce611c41bd99acf7d0f00d42fb" data-id="9bcc8fce611c41bd99acf7d0f00d42fb"><span><div id="9bcc8fce611c41bd99acf7d0f00d42fb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9bcc8fce611c41bd99acf7d0f00d42fb" title="还没解决的"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">还没解决的</span></span></h4><div class="notion-text notion-block-9699c703666d4546a1d96ab24ae96a11">最难的还是判断一件事做完了没有。</div><div class="notion-text notion-block-9aa3837310d444bb906d0f478ee3df7d">LangChain 10 月 15 日讲 agent 评估的那篇，建议从一个具体行为入手：从真实运行记录里挑 10 到 20 个例子做成测试集，先跑出基线，之后每次改动都跟基线比，线上发现的新失败再补进去。能用代码判断的用代码，判断不了的让模型打分，再用人工抽查这两者。</div><div class="notion-text notion-block-2e7b6993e02549a8b17fb13e9285360f">我做搜索排序时用过类似的办法：拿一批真实的搜索结果，先用规则打分，再让模型抽查，两边一致才往下推。现在回头看，缺了人工校准这一步。规则和模型可能偏向同一种错，两边一致也说明不了结果就是对的。</div><div class="notion-text notion-block-2fa05e24ffb844b6bb1224c716430ce8">Anthropic 那篇最后提到，做这套系统的工程师把更多精力放在了定设计约束和审查改动意图上，因为 agent 有时会违反系统约束，或者写一堆没必要的防御代码。我现在花时间最多的，也是想清楚这次要验什么、验到哪一步。</div><div class="notion-text notion-block-7a37a1d78a8a426c829ed06a4e3ddea2">你们用 AI 写代码以后，有没有被“测试是绿的，但其实没测到”坑过？</div><div class="notion-text notion-block-c4f3010c7f9041639e848fda5b68e41e">✻ ✻ ✻</div><div class="notion-text notion-block-afbbf3f1d0994a53b302ffa34baace48">我是 hllqkb，一名后端实习生，在这里记录用 AI 写代码时踩过的坑。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Claude Code 进阶使用指南]]></title>
            <link>https://hllqk.cn/article/claude-code-guide</link>
            <guid>https://hllqk.cn/article/claude-code-guide</guid>
            <pubDate>Wed, 29 Jul 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[本文档基于 Claude Code 官方文档（code.claude.com/docs）核实整理，整理日期 2026-07-29。每节末尾附来源链接，可点击查看最新版本。 1. CLI 命令与常用 Flags 1.1 启动方式 1.2 核心…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-3accdaa272b681be8644de2a165ead94"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><blockquote class="notion-quote notion-block-d42bae78658a4789af006b9ca2422264"><div>本文档基于 Claude Code 官方文档（<a class="notion-link" href="https://code.claude.com/docs" target="_blank" rel="noopener noreferrer">code.claude.com/docs）核实整理，整理日期</a> 2026-07-29。每节末尾附来源链接，可点击查看最新版本。</div></blockquote><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-8e2f434fb04d4558b700b8ad663ec647" data-id="8e2f434fb04d4558b700b8ad663ec647"><span><div id="8e2f434fb04d4558b700b8ad663ec647" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8e2f434fb04d4558b700b8ad663ec647" title="1. CLI 命令与常用 Flags"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. CLI 命令与常用 Flags</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-ebd7d3322ec64e2ab798fc315a4469aa" data-id="ebd7d3322ec64e2ab798fc315a4469aa"><span><div id="ebd7d3322ec64e2ab798fc315a4469aa" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ebd7d3322ec64e2ab798fc315a4469aa" title="1.1 启动方式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.1 启动方式</span></span></h3><table class="notion-simple-table notion-block-d2180e90cb3d488bbf49c65fdc2fc37e"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-e6e20aa4094749e0921b3265ba33522a"><td class="" style="width:120px"><div class="notion-simple-table-cell">方式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">命令</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-5b6f2cd1c27a4362ac5d3353e6beae56"><td class="" style="width:120px"><div class="notion-simple-table-cell">交互模式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">claude</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">启动交互式会话</div></td></tr><tr class="notion-simple-table-row notion-block-0e45ab9a7fdb4d8089d3151ad7e24e7c"><td class="" style="width:120px"><div class="notion-simple-table-cell">交互 + 初始提示</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">claude &quot;query&quot;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">启动会话并附加初始提示</div></td></tr><tr class="notion-simple-table-row notion-block-da4670714a18406fbc05c3a2297f2f7b"><td class="" style="width:120px"><div class="notion-simple-table-cell">无头模式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">claude -p &quot;query&quot;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">执行后退出，返回结果</div></td></tr><tr class="notion-simple-table-row notion-block-88c0357ec9ab4dba9f1493b06eb39062"><td class="" style="width:120px"><div class="notion-simple-table-cell">管道输入</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">cat file.txt | claude -p &quot;query&quot;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">从 stdin 读取，处理后退出</div></td></tr><tr class="notion-simple-table-row notion-block-3424c11ffe9b4cac97a644b0552bb5e5"><td class="" style="width:120px"><div class="notion-simple-table-cell">继续最近会话</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">claude -c</code> / <code class="notion-inline-code">claude --continue</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">继续最近对话</div></td></tr><tr class="notion-simple-table-row notion-block-9d062c83b92b40128dc8dd62a3cbb465"><td class="" style="width:120px"><div class="notion-simple-table-cell">恢复指定会话</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">claude -r &quot;session-id&quot;</code> / <code class="notion-inline-code">claude --resume</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">恢复指定会话或显示选择器</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e1fc22a208504e4083a3b1937bdf360d" data-id="e1fc22a208504e4083a3b1937bdf360d"><span><div id="e1fc22a208504e4083a3b1937bdf360d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e1fc22a208504e4083a3b1937bdf360d" title="1.2 核心 Flags"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.2 核心 Flags</span></span></h3><div class="notion-text notion-block-9df45ff3fa0c48229624bd37b50708aa"><b>会话管理</b></div><table class="notion-simple-table notion-block-2e1c54dbc35f444e86785e738b8ee996"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-be2c92005d7e4d68bed12337ba951101"><td class="" style="width:120px"><div class="notion-simple-table-cell">Flag</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">短形式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-5baaee88540549d9995accd03ec9e21e"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--continue</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">-c</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">加载最近对话</div></td></tr><tr class="notion-simple-table-row notion-block-dc95a319d53f4dee81f16346b3f67b34"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--resume</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">-r</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">按 ID 或名称恢复会话</div></td></tr><tr class="notion-simple-table-row notion-block-eeb1ca47b63c49a59f5df32e75efa4c3"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--name</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">-n</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">设置会话显示名称</div></td></tr><tr class="notion-simple-table-row notion-block-4f0d9fe52a6947b1aed8ad8cf5229795"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--session-id</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">—</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">使用特定 UUID 会话</div></td></tr><tr class="notion-simple-table-row notion-block-21094080a6144bcc9b41b213072a2d05"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--fork-session</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">—</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">恢复时创建新会话 ID，不覆盖原会话</div></td></tr></tbody></table><div class="notion-text notion-block-9cda8ea5174644e5b088961b95152569"><b>输入 / 输出</b></div><table class="notion-simple-table notion-block-faba3f166eca4692b1408a26c9f0feb1"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-76c2c1c13f654a21bb166ff653ea2349"><td class="" style="width:120px"><div class="notion-simple-table-cell">Flag</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-f1b45ce068fd496c806e3887da964b22"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--print</code> / <code class="notion-inline-code">-p</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">非交互模式，打印结果后退出</div></td></tr><tr class="notion-simple-table-row notion-block-29070bd3462a44f28f7e0f116321a72f"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--output-format</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">text</code> / <code class="notion-inline-code">json</code> / <code class="notion-inline-code">stream-json</code></div></td></tr><tr class="notion-simple-table-row notion-block-8165b23079d0499da2299931da56c4fb"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--input-format</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">text</code> / <code class="notion-inline-code">stream-json</code></div></td></tr><tr class="notion-simple-table-row notion-block-86831b2f7daf45048420896b289442d7"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--json-schema</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用 JSON Schema 约束结构化输出</div></td></tr><tr class="notion-simple-table-row notion-block-85d8c670afa4414e8203e75da43ee0c2"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--verbose</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">详细日志</div></td></tr></tbody></table><div class="notion-text notion-block-0ffbb70a614e4bedbcadd4fe3df2e085"><b>模型与推理深度</b></div><table class="notion-simple-table notion-block-2ce259e53aa4457f8784d49f8820bade"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-557690cb70c3451d8d943fde59ced79f"><td class="" style="width:120px"><div class="notion-simple-table-cell">Flag</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">有效值</div></td></tr><tr class="notion-simple-table-row notion-block-60cb3d0e05284441a4a1702d2285886d"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--model</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">指定模型</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">完整模型名或别名 <code class="notion-inline-code">opus</code> / <code class="notion-inline-code">sonnet</code> / <code class="notion-inline-code">haiku</code></div></td></tr><tr class="notion-simple-table-row notion-block-a00022ba0bb94fd9af8e9cc9bf117284"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--effort</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">推理努力级别</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">low</code> / <code class="notion-inline-code">medium</code> / <code class="notion-inline-code">high</code> / <code class="notion-inline-code">xhigh</code> / <code class="notion-inline-code">max</code></div></td></tr><tr class="notion-simple-table-row notion-block-85891d5c6dae4373aa7785d4defae9fd"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--fallback-model</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">主模型不可用时的备用模型</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">逗号分隔模型名</div></td></tr></tbody></table><div class="notion-text notion-block-29a77771d7824d86a3d552c8c8d7ce68"><b>权限与安全</b></div><table class="notion-simple-table notion-block-c36f520258f44aed8bb001fff37c9c00"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-417b207746494a88988ba7f1ba3670b9"><td class="" style="width:120px"><div class="notion-simple-table-cell">Flag</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-ae14057122c24f8e96e36b22c84a83b5"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--permission-mode</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">default</code> / <code class="notion-inline-code">acceptEdits</code> / <code class="notion-inline-code">plan</code> / <code class="notion-inline-code">auto</code> / <code class="notion-inline-code">dontAsk</code> / <code class="notion-inline-code">bypassPermissions</code></div></td></tr><tr class="notion-simple-table-row notion-block-e93640b235904340a74afc7d20497a41"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--dangerously-skip-permissions</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">跳过所有权限提示，等同 bypassPermissions，仅在完全信任输入时使用</div></td></tr><tr class="notion-simple-table-row notion-block-dfe18e777b67463088089eb94d21d990"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--allowedTools</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">无需提示即可执行的工具，支持前缀匹配，如 <code class="notion-inline-code">&quot;Bash(git diff *),Read&quot;</code></div></td></tr><tr class="notion-simple-table-row notion-block-74d8a07765bd40bc86825660fb10855f"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--disallowedTools</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">禁用指定工具</div></td></tr><tr class="notion-simple-table-row notion-block-9e391263787f441a8fe237f816cb46ee"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--tools</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">限制可用的内置工具集</div></td></tr></tbody></table><div class="notion-text notion-block-56547edd4fed4802a94d2403ff0ec50d"><b>流控制与自动化</b></div><table class="notion-simple-table notion-block-571dd4c97d9f4756a7156b783756f16a"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-1e3e2ccf60fd44599ad5d5452c976227"><td class="" style="width:120px"><div class="notion-simple-table-cell">Flag</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-6bfa0efaad584f7f8e04596d449e5f4a"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--max-turns</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">限制 agent 轮次（无头模式常用）</div></td></tr><tr class="notion-simple-table-row notion-block-79c177a279984e5081ced1076ca1f473"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--max-budget-usd</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">最大支出限制，超过即停止</div></td></tr><tr class="notion-simple-table-row notion-block-302ce5e451de426d9120072ebb504a40"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--bare</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">跳过 hooks / skills / MCP / <a class="notion-link" href="http://CLAUDE.md" target="_blank" rel="noopener noreferrer">CLAUDE.md</a> 等自动发现，用于 CI 可重现执行</div></td></tr><tr class="notion-simple-table-row notion-block-760abb01cd874cc1bb6f9d22a59abc0d"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--mcp-config</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">指定 MCP 配置文件或 JSON</div></td></tr><tr class="notion-simple-table-row notion-block-e0d91a2bc3274b648adb9670ed3b98d0"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--strict-mcp-config</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">只用指定的 MCP 配置，忽略自动发现</div></td></tr></tbody></table><div class="notion-text notion-block-c986b5a6eca94477aea0359bd1e92c3c"><b>工作树与并行</b></div><table class="notion-simple-table notion-block-dfbc9adf2cf14437ab66e8de5f49a1c9"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-1718b9b9d5204798a90e87c69f5de312"><td class="" style="width:120px"><div class="notion-simple-table-cell">Flag</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-a3d8c0b2256d4e3f9ad3cf374d0c1cae"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--worktree</code> / <code class="notion-inline-code">-w</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">创建或进入隔离 git worktree</div></td></tr><tr class="notion-simple-table-row notion-block-5377a676a1e042448adbeef03be3248e"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--tmux</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">为工作树创建 tmux 会话</div></td></tr><tr class="notion-simple-table-row notion-block-4619416833f845c3b7e22fd07afa496d"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--background</code> / <code class="notion-inline-code">--bg</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">启动后台会话</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5b76048da0ca4353a4eab0e90391a9d1" data-id="5b76048da0ca4353a4eab0e90391a9d1"><span><div id="5b76048da0ca4353a4eab0e90391a9d1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5b76048da0ca4353a4eab0e90391a9d1" title="1.3 实用组合示例"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.3 实用组合示例</span></span></h3><pre class="notion-code language-bash notion-code-id-c6dc7c4d4d8c4c88bc1b86810bdd45bd" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash"># 无头 + 限定工具 + 限制轮次：一次性修复任务
claude -p &quot;Find and fix type errors in src/&quot; \
  --allowedTools &quot;Bash,Read,Edit&quot; \
  --max-turns 5

# 无头 + JSON 输出 + 成本追踪
claude -p &quot;Analyze this codebase&quot; \
  --output-format json | jq &#x27;.total_cost_usd&#x27;

# 工作树隔离 + 计划模式：大改动前先出方案
claude --worktree feature-x --permission-mode plan

# 管道处理日志
cat error.log | claude -p &quot;解释这个报错的根因&quot;</code></pre><div class="notion-text notion-block-5b119e060f0f4af098ccbe64248edf94">来源：<a class="notion-link" href="https://code.claude.com/docs/en/cli-reference.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/cli-reference.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-c3524b798a0f44128e4695c557940bd4" data-id="c3524b798a0f44128e4695c557940bd4"><span><div id="c3524b798a0f44128e4695c557940bd4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c3524b798a0f44128e4695c557940bd4" title="2. 交互模式进阶"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 交互模式进阶</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-64669501a10b4c0daca12e63c841cd29" data-id="64669501a10b4c0daca12e63c841cd29"><span><div id="64669501a10b4c0daca12e63c841cd29" class="notion-header-anchor"></div><a class="notion-hash-link" href="#64669501a10b4c0daca12e63c841cd29" title="2.1 常用内置斜杠命令"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 常用内置斜杠命令</span></span></h3><table class="notion-simple-table notion-block-31e39eca308146a89f15bec922bdb27d"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-dfadf3712541436fa94943cf2dd29413"><td class="" style="width:120px"><div class="notion-simple-table-cell">命令</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-ece528c0d24d4752bcb82ba17cd0b718"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/init</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">生成或改进项目 <a class="notion-link" href="http://CLAUDE.md" target="_blank" rel="noopener noreferrer">CLAUDE.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-171dd13e1e174f159ae23cf745e4b1ab"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/clear</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">清空上下文开始新对话（保留项目记忆）</div></td></tr><tr class="notion-simple-table-row notion-block-5e93a6816f3b40cfaf5932553d4285f6"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/compact [说明]</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">总结压缩上下文，可附压缩侧重点</div></td></tr><tr class="notion-simple-table-row notion-block-4d4be87da0b64668a3551797cf16efc9"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/context</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">可视化当前上下文占用</div></td></tr><tr class="notion-simple-table-row notion-block-f6c3ed5739554be9bd062cf868e46bc8"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/memory</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">编辑 <a class="notion-link" href="http://CLAUDE.md" target="_blank" rel="noopener noreferrer">CLAUDE.md</a> 与自动记忆</div></td></tr><tr class="notion-simple-table-row notion-block-a87e9480ece74384ac58d8d2c2af726c"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/model [name]</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">切换模型</div></td></tr><tr class="notion-simple-table-row notion-block-eea69aa0f6e947efa096612b803e2886"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/effort [level]</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">设置推理努力级别</div></td></tr><tr class="notion-simple-table-row notion-block-85039d444ee24ca3ab6768a301909fcf"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/plan</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">切换到计划模式</div></td></tr><tr class="notion-simple-table-row notion-block-83d23eaee2584c698461d50d524a3de5"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/rewind</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">回滚代码与对话到检查点</div></td></tr><tr class="notion-simple-table-row notion-block-cc4ac2630f6b4708ae93af787177eb39"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/resume</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">会话选择器</div></td></tr><tr class="notion-simple-table-row notion-block-5e7ee8d7b2904caf9fa1c01186e17dc7"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/fork</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">复制当前对话到新后台会话</div></td></tr><tr class="notion-simple-table-row notion-block-8de7197ed9d84db4832e3c31da5c1959"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/diff</code> </div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">交互式差异查看器</div></td></tr><tr class="notion-simple-table-row notion-block-c4a9272f30b145c189dd5fd2c59d2b60"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/code-review [--fix]</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">审查当前差异，可自动应用修复</div></td></tr><tr class="notion-simple-table-row notion-block-24c289b9e4ff45de9fe7cb86d0ac4f44"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/security-review</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">检查差异中的安全问题</div></td></tr><tr class="notion-simple-table-row notion-block-22bcf60e040441f79ba6a1bb10261afb"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/usage</code> / <code class="notion-inline-code">/cost</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">查看 token 使用与成本</div></td></tr><tr class="notion-simple-table-row notion-block-90b8c1b18df24ac086fa1dc2a1d9a5ea"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/permissions</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">管理批准规则</div></td></tr><tr class="notion-simple-table-row notion-block-a35259fbb9f041769779608dde58cdbb"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/mcp</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">MCP 服务器管理</div></td></tr><tr class="notion-simple-table-row notion-block-0916f5dca2954cacb34af79f8df43e18"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/hooks</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">查看 hook 配置</div></td></tr><tr class="notion-simple-table-row notion-block-7c111e33a061475e861bbc2dded54c1c"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/doctor</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">环境诊断</div></td></tr><tr class="notion-simple-table-row notion-block-ffc6b2ec46d745d8851080fb84acbd68"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/export [文件名]</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">导出对话为纯文本</div></td></tr><tr class="notion-simple-table-row notion-block-d10c2a1766a046ed89fd2f9c10be2880"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/add-dir &lt;path&gt;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">添加额外工作目录</div></td></tr><tr class="notion-simple-table-row notion-block-0be60c1b1c424bddbc78cfba37153c70"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">/config</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">打开设置界面</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d2e2608844af4026ad71d56e009e35ae" data-id="d2e2608844af4026ad71d56e009e35ae"><span><div id="d2e2608844af4026ad71d56e009e35ae" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d2e2608844af4026ad71d56e009e35ae" title="2.2 键盘与输入技巧"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 键盘与输入技巧</span></span></h3><table class="notion-simple-table notion-block-9e7801e0dbaa49ac9b2167b8ecb7b74f"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-64f5b891a91a490caf2bcaf384a6f71a"><td class="" style="width:120px"><div class="notion-simple-table-cell">操作</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td></tr><tr class="notion-simple-table-row notion-block-cf6712219da740f38f4b420ad48fef27"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">!&lt;command&gt;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">直接在会话内执行 bash 命令，输出进入上下文</div></td></tr><tr class="notion-simple-table-row notion-block-3d4924a0d4804474a3f6d45565c6b8d9"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">#&lt;note&gt;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">添加记忆备注（写入自动记忆）</div></td></tr><tr class="notion-simple-table-row notion-block-b74a22716d694ad0889a5935c50b9713"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">@&lt;filepath&gt;</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">引用文件，缩小问题空间</div></td></tr><tr class="notion-simple-table-row notion-block-35a2c56fe91c432f8b00e327ce54d1cb"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Esc</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">中断当前生成</div></td></tr><tr class="notion-simple-table-row notion-block-6de2d4e8837944f88e6118320a2f5621"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Shift+Tab</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">循环切换权限模式</div></td></tr><tr class="notion-simple-table-row notion-block-e012a65201f94d0caf61f2e0033ec5fd"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Ctrl+R</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">搜索命令历史</div></td></tr><tr class="notion-simple-table-row notion-block-f4866f8180b141d98ec9a51c1aa05098"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Ctrl+G</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用外部编辑器编辑当前输入</div></td></tr><tr class="notion-simple-table-row notion-block-622a2a347d0a455584f0189f05e5b5e2"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Ctrl+V</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">粘贴图像</div></td></tr><tr class="notion-simple-table-row notion-block-a8d67a9b1db3443eb294408276ea34ab"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Ctrl+T</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">切换待办列表显示</div></td></tr><tr class="notion-simple-table-row notion-block-005eb3b00d6a4c9e9a5a550f435d438b"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Ctrl+O</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">切换详细转录</div></td></tr><tr class="notion-simple-table-row notion-block-c06c3740fbc24297a7285c61c78d1739"><td class="" style="width:120px"><div class="notion-simple-table-cell">Tab</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">补全命令、文件路径</div></td></tr></tbody></table><div class="notion-text notion-block-ddf612fa70a34472b4e8aea7c6892368">Vim 模式：<code class="notion-inline-code">/config</code> 中 Editor mode 设为 vim；用 <code class="notion-inline-code">vimInsertModeRemaps</code> 可配置如 <code class="notion-inline-code">jj</code> 映射 Escape。</div><div class="notion-text notion-block-fa7b3d9d100c486ab902c1560dace4ca">来源：<a class="notion-link" href="https://code.claude.com/docs/en/interactive-mode.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/interactive-mode.md</a> 、<a class="notion-link" href="https://code.claude.com/docs/en/keybindings.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/keybindings.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-89aaaddfb4c3473dbdac802fb245589a" data-id="89aaaddfb4c3473dbdac802fb245589a"><span><div id="89aaaddfb4c3473dbdac802fb245589a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#89aaaddfb4c3473dbdac802fb245589a" title="3. 记忆体系（CLAUDE.md）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 记忆体系（<a class="notion-link" href="http://CLAUDE.md" target="_blank" rel="noopener noreferrer">CLAUDE.md</a>）</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-b698ddfec04d47a0aa8a645d172666ae" data-id="b698ddfec04d47a0aa8a645d172666ae"><span><div id="b698ddfec04d47a0aa8a645d172666ae" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b698ddfec04d47a0aa8a645d172666ae" title="3.1 层级与加载顺序（优先级从低到高）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1 层级与加载顺序（优先级从低到高）</span></span></h3><table class="notion-simple-table notion-block-0d16765525ac4b74a9c1c744e6a81491"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-264ff01c3c9a4f2096c5a43f2be5216d"><td class="" style="width:120px"><div class="notion-simple-table-cell">优先级</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">作用域</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">位置</div></td></tr><tr class="notion-simple-table-row notion-block-df799ea37ee141a6b2c3f792f3582d38"><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用户全局</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">~/.claude/CLAUDE.md</code></div></td></tr><tr class="notion-simple-table-row notion-block-ed3507aaa1504eccb738baa83b0e2692"><td class="" style="width:120px"><div class="notion-simple-table-cell">2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">项目</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">./CLAUDE.md</code>（随 git 提交，团队共享）</div></td></tr><tr class="notion-simple-table-row notion-block-cea443e6ee384c9ca614e1c194e5b01a"><td class="" style="width:120px"><div class="notion-simple-table-cell">3</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">项目本地</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">./CLAUDE.local.md</code>（gitignored，个人私有）</div></td></tr><tr class="notion-simple-table-row notion-block-88675f8755c04830a4572214ef4dd462"><td class="" style="width:120px"><div class="notion-simple-table-cell">4</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">嵌套目录</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">&lt;subdir&gt;/CLAUDE.md</code>（读到该目录文件时按需加载）</div></td></tr><tr class="notion-simple-table-row notion-block-8c83fc8b4390402b8d07e22e08290450"><td class="" style="width:120px"><div class="notion-simple-table-cell">5</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">项目规则</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">./.claude/rules/*.md</code>（支持路径作用域）</div></td></tr><tr class="notion-simple-table-row notion-block-51e68ce45cac482aace217744ae3372c"><td class="" style="width:120px"><div class="notion-simple-table-cell">6</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用户规则</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">~/.claude/rules/*.md</code></div></td></tr><tr class="notion-simple-table-row notion-block-1fe3c7a594d94ee1bce17bb3dc0ca303"><td class="" style="width:120px"><div class="notion-simple-table-cell">7</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">托管策略</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">IT 管理下发，不可排除</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-ad069cede4794a0f9ca28b68db424b32" data-id="ad069cede4794a0f9ca28b68db424b32"><span><div id="ad069cede4794a0f9ca28b68db424b32" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ad069cede4794a0f9ca28b68db424b32" title="3.2 Import 语法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.2 Import 语法</span></span></h3><pre class="notion-code language-markdown notion-code-id-2a1a4c6db745488891fb27c556c49877" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">@README.md                      # 相对路径
@~/.claude/shared-rules.md      # 主目录展开</code></pre><ul class="notion-list notion-list-disc notion-block-b73fa70ab7b54f1ebbcba5ce2640c539"><li>最大递归 4 层；代码块和反引号内的 @ 视为字面量</li></ul><ul class="notion-list notion-list-disc notion-block-36969589419b443285bec75db297d756"><li>项目目录之外的导入首次加载需确认</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-3a72c8706f1d4a14b94176e9867214e8" data-id="3a72c8706f1d4a14b94176e9867214e8"><span><div id="3a72c8706f1d4a14b94176e9867214e8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3a72c8706f1d4a14b94176e9867214e8" title="3.3 自动记忆"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.3 自动记忆</span></span></h3><ul class="notion-list notion-list-disc notion-block-fdb8449f294045c5b05be90decf9d945"><li>存储位置：<code class="notion-inline-code">~/.claude/projects/&lt;project&gt;/memory/</code>，<code class="notion-inline-code">MEMORY.md</code> 为索引</li></ul><ul class="notion-list notion-list-disc notion-block-65f5471ee6c2477abe8871d087466eb6"><li>每次会话只加载索引前 200 行或 25 KB（先到为准），主题文件按需读取</li></ul><ul class="notion-list notion-list-disc notion-block-100dd391e459463898af176502a44b06"><li>用 <code class="notion-inline-code">/memory</code> 管理，或设置 <code class="notion-inline-code">autoMemoryEnabled: false</code> 关闭</li></ul><div class="notion-text notion-block-22e23cd01cab4b46994480526c468975">来源：<a class="notion-link" href="https://code.claude.com/docs/en/memory.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/memory.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-3b14202ba6e747709c4238d81b8a8f0a" data-id="3b14202ba6e747709c4238d81b8a8f0a"><span><div id="3b14202ba6e747709c4238d81b8a8f0a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3b14202ba6e747709c4238d81b8a8f0a" title="4. Skills（自定义斜杠命令）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. Skills（自定义斜杠命令）</span></span></h2><ul class="notion-list notion-list-disc notion-block-cc2fa34045464b9684472f618b47076f"><li>自定义命令已合并进 Skills；<code class="notion-inline-code">.claude/commands/</code> 仍向后兼容，但推荐用 Skills</li></ul><ul class="notion-list notion-list-disc notion-block-2a8a7f271bd444328cb8a80099ffc6ec"><li>位置：<code class="notion-inline-code">.claude/skills/&lt;name&gt;/SKILL.md</code>（项目级）或 <code class="notion-inline-code">~/.claude/skills/</code>（用户级），可带支持脚本和子目录</li></ul><pre class="notion-code language-yaml notion-code-id-433632aa58fc4b95a51c59d128852b04" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-yaml">---
name: deploy
description: 何时触发的说明，Claude 据此自动调用
model: haiku            # 可选，专用模型
tools: [&quot;Read&quot;, &quot;Bash&quot;] # 可选，限制工具
invocation: user        # auto 自动触发 / user 仅手动 / never 禁用
---

技能正文：具体指令与流程...</code></pre><div class="notion-text notion-block-be26f9b45286460ab1b3dfaaad5c9b22">来源：<a class="notion-link" href="https://code.claude.com/docs/en/skills.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/skills.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-33080cf055ef42858aefd73b73ba58cc" data-id="33080cf055ef42858aefd73b73ba58cc"><span><div id="33080cf055ef42858aefd73b73ba58cc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#33080cf055ef42858aefd73b73ba58cc" title="5. Subagents（子代理）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. Subagents（子代理）</span></span></h2><ul class="notion-list notion-list-disc notion-block-7fa12ed81c5e4f4ab58cab7a783b688a"><li>位置：<code class="notion-inline-code">.claude/agents/&lt;name&gt;.md</code> 或 <code class="notion-inline-code">~/.claude/agents/</code></li></ul><ul class="notion-list notion-list-disc notion-block-b3049ef4784c4951b1ffe9f3c3632c8e"><li>Claude 遇到匹配 description 的任务时自动派发；子代理有独立上下文、工具集与权限，完成后只把摘要带回主会话</li></ul><ul class="notion-list notion-list-disc notion-block-e5ef38e47f384fdd9de5a754d9764120"><li>典型场景：探索性搜索（隔离上下文污染）、代码审查、并行实现</li></ul><pre class="notion-code language-yaml notion-code-id-43f5b4653d4441acb3add4d56ac846f4" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-yaml">---
name: code-reviewer
description: 审查代码改动时使用
model: sonnet
tools: [&quot;Read&quot;, &quot;Bash&quot;]
isolation: worktree     # 可选，独立工作树防止文件冲突
---

代理系统提示...</code></pre><div class="notion-text notion-block-07d8aadaa10840e29a1e31320ff8304f">来源：<a class="notion-link" href="https://code.claude.com/docs/en/sub-agents.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/sub-agents.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-182bc0824d674eb38a93e82e54271149" data-id="182bc0824d674eb38a93e82e54271149"><span><div id="182bc0824d674eb38a93e82e54271149" class="notion-header-anchor"></div><a class="notion-hash-link" href="#182bc0824d674eb38a93e82e54271149" title="6. Hooks（钩子）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6. Hooks（钩子）</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e3413657d8354a338951047d226f041e" data-id="e3413657d8354a338951047d226f041e"><span><div id="e3413657d8354a338951047d226f041e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e3413657d8354a338951047d226f041e" title="6.1 常用事件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6.1 常用事件</span></span></h3><table class="notion-simple-table notion-block-ee920af8e9d4485890223a543a05a3c5"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-7c944f1e51e446929b81b3db281b1d21"><td class="" style="width:120px"><div class="notion-simple-table-cell">事件</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">触发时机</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">exit 2 行为</div></td></tr><tr class="notion-simple-table-row notion-block-6e6c4f85d5824a2c9d13756fffda83c4"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">PreToolUse</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">工具执行前</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">阻止该工具调用</div></td></tr><tr class="notion-simple-table-row notion-block-e10a12d39af6436f956b0e343e110b18"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">PostToolUse</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">工具成功后</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">不阻止，stderr 反馈给 Claude</div></td></tr><tr class="notion-simple-table-row notion-block-ea264b087c03431b91745297738e5c58"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">UserPromptSubmit</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用户提交提示前</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">阻止该提示处理</div></td></tr><tr class="notion-simple-table-row notion-block-164bc0cdc722421d8068a96c878b58b7"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Stop</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Claude 准备结束响应时</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">阻止停止，强制继续</div></td></tr><tr class="notion-simple-table-row notion-block-2851c69e10ed4833bcac92b7be47d316"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">SessionStart</code> / <code class="notion-inline-code">SessionEnd</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">会话开始 / 结束</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">不可阻止</div></td></tr><tr class="notion-simple-table-row notion-block-05e938ce08494ed0a4378797f98a2b95"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">SubagentStop</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">子代理完成</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">可阻止</div></td></tr><tr class="notion-simple-table-row notion-block-9d1d4624c1ae44839839aa651b0e290d"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">PreCompact</code> / <code class="notion-inline-code">PostCompact</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">上下文压缩前后</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">—</div></td></tr><tr class="notion-simple-table-row notion-block-fad5c5812d5c4ebf9fbb0d8e6c7fedcd"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">PermissionRequest</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">需要权限决策时</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">拒绝权限</div></td></tr><tr class="notion-simple-table-row notion-block-fc31378a615f41c6af6b4c122501fcf3"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">Notification</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Claude 发送通知时</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">—</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-46be0f4951e7435cad6938805a589689" data-id="46be0f4951e7435cad6938805a589689"><span><div id="46be0f4951e7435cad6938805a589689" class="notion-header-anchor"></div><a class="notion-hash-link" href="#46be0f4951e7435cad6938805a589689" title="6.2 配置格式（settings.json）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6.2 配置格式（settings.json）</span></span></h3><pre class="notion-code language-json notion-code-id-e9c0c4fdfd6445c7bc555d5501758aff" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-json">{
  &quot;hooks&quot;: {
    &quot;PreToolUse&quot;: [
      {
        &quot;matcher&quot;: &quot;Bash|Edit|Write&quot;,
        &quot;hooks&quot;: [
          { &quot;type&quot;: &quot;command&quot;, &quot;command&quot;: &quot;/path/to/check.sh&quot; }
        ]
      }
    ]
  }
}</code></pre><ul class="notion-list notion-list-disc notion-block-8980244bc23546ffb0d4f0b03467e9a1"><li>matcher 支持精确名（<code class="notion-inline-code">Bash</code>）、多选（<code class="notion-inline-code">Bash|Edit</code>）、正则（<code class="notion-inline-code">mcp__.*__write.*</code>）、全部（<code class="notion-inline-code">*</code>）</li></ul><ul class="notion-list notion-list-disc notion-block-16583899fe78486cac652fe935ff6ac6"><li>hook 类型：<code class="notion-inline-code">command</code>（本地脚本）与 <code class="notion-inline-code">http</code>（POST 到远程 URL）</li></ul><ul class="notion-list notion-list-disc notion-block-bd2398e72db04413a1e24fc5e29731d2"><li>输入通过 stdin 传 JSON（含 <code class="notion-inline-code">session_id</code>、<code class="notion-inline-code">tool_name</code>、<code class="notion-inline-code">tool_input</code> 等）</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-05607e66ef5545988136b794b7db2413" data-id="05607e66ef5545988136b794b7db2413"><span><div id="05607e66ef5545988136b794b7db2413" class="notion-header-anchor"></div><a class="notion-hash-link" href="#05607e66ef5545988136b794b7db2413" title="6.3 Exit code 语义"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6.3 Exit code 语义</span></span></h3><table class="notion-simple-table notion-block-9e3717c5100c4e1b8a2229e5b120f44e"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-4b0bdc0dba674ac4bb7164923e3fc9ce"><td class="" style="width:120px"><div class="notion-simple-table-cell">Exit code</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">含义</div></td></tr><tr class="notion-simple-table-row notion-block-2ae6a3245f834aca997e876ec34b4ad9"><td class="" style="width:120px"><div class="notion-simple-table-cell">0</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">成功，解析 stdout 中的 JSON</div></td></tr><tr class="notion-simple-table-row notion-block-760caf4472094d7096d440ecf9fb6f6c"><td class="" style="width:120px"><div class="notion-simple-table-cell">2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">阻止性错误，stderr 内容作为原因</div></td></tr><tr class="notion-simple-table-row notion-block-f9178c70992b457c81f53c11a1f73992"><td class="" style="width:120px"><div class="notion-simple-table-cell">其他</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">非阻止错误，继续执行</div></td></tr></tbody></table><div class="notion-text notion-block-55aa6e3a8f66420b9c42bcc4ab248341">提示：<a class="notion-link" href="http://CLAUDE.md" target="_blank" rel="noopener noreferrer">CLAUDE.md</a> 里的规则是「建议」，Claude 可能遗忘；hooks 是「硬约束」，由 harness 强制执行。硬性纪律（如禁止 push main、提交前必须 lint）应沉淀为 hooks。</div><div class="notion-text notion-block-69c8cba27909477da2601a5c5d482f2b">来源：<a class="notion-link" href="https://code.claude.com/docs/en/hooks-guide.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/hooks-guide.md</a> 、<a class="notion-link" href="https://code.claude.com/docs/en/hooks.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/hooks.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-bece711a7d5f414a990f9edff43eb8a1" data-id="bece711a7d5f414a990f9edff43eb8a1"><span><div id="bece711a7d5f414a990f9edff43eb8a1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bece711a7d5f414a990f9edff43eb8a1" title="7. MCP（Model Context Protocol）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7. MCP（Model Context Protocol）</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-58b9ef24691e474491af6f92d1592d43" data-id="58b9ef24691e474491af6f92d1592d43"><span><div id="58b9ef24691e474491af6f92d1592d43" class="notion-header-anchor"></div><a class="notion-hash-link" href="#58b9ef24691e474491af6f92d1592d43" title="7.1 常用命令"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.1 常用命令</span></span></h3><pre class="notion-code language-bash notion-code-id-976c97766ffc4353b462236338b4dfd6" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">claude mcp add &lt;name&gt; stdio -- node /path/to/server.js   # 本地 stdio
claude mcp add &lt;name&gt; http https://example.com/mcp       # 远程 HTTP
claude mcp add &lt;name&gt; sse https://example.com/sse        # 远程 SSE
claude mcp list                                          # 列出服务器
claude mcp login &lt;name&gt;                                  # OAuth 认证
claude mcp remove &lt;name&gt;                                 # 移除</code></pre><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-6f56e10bef7849e3a552267531dd5fb8" data-id="6f56e10bef7849e3a552267531dd5fb8"><span><div id="6f56e10bef7849e3a552267531dd5fb8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6f56e10bef7849e3a552267531dd5fb8" title="7.2 作用域"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2 作用域</span></span></h3><table class="notion-simple-table notion-block-9166f7ca3cb844ff9680bc1b9eedfeb9"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-dcaee61884854f3a8174bb8eebb84cc8"><td class="" style="width:120px"><div class="notion-simple-table-cell">Scope</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">位置</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">共享方式</div></td></tr><tr class="notion-simple-table-row notion-block-fd629aa5a50843eca72e07cc84e53cc8"><td class="" style="width:120px"><div class="notion-simple-table-cell">local</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">~/.claude.json</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">个人所有项目</div></td></tr><tr class="notion-simple-table-row notion-block-12689882ca924e6ea06684b94e048ed1"><td class="" style="width:120px"><div class="notion-simple-table-cell">project</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">.mcp.json</code>（随 git 提交）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">团队共享</div></td></tr><tr class="notion-simple-table-row notion-block-3739d97853524bf1b9a1eef0eba75cc2"><td class="" style="width:120px"><div class="notion-simple-table-cell">managed</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">服务器下发</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">IT 管理</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f210ffa4fd2d49349dd69f695540bc6d" data-id="f210ffa4fd2d49349dd69f695540bc6d"><span><div id="f210ffa4fd2d49349dd69f695540bc6d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f210ffa4fd2d49349dd69f695540bc6d" title="7.3 .mcp.json 示例"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.3 .mcp.json 示例</span></span></h3><pre class="notion-code language-json notion-code-id-e4c6e540b0284eb0a3e3952b0ce0c482" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-json">{
  &quot;mcpServers&quot;: {
    &quot;github&quot;: {
      &quot;type&quot;: &quot;stdio&quot;,
      &quot;command&quot;: &quot;node&quot;,
      &quot;args&quot;: [&quot;/path/to/github-mcp/index.js&quot;],
      &quot;env&quot;: { &quot;GITHUB_TOKEN&quot;: &quot;$GITHUB_TOKEN&quot; }
    },
    &quot;remote-api&quot;: { &quot;type&quot;: &quot;sse&quot;, &quot;url&quot;: &quot;https://api.example.com/mcp&quot; }
  }
}</code></pre><div class="notion-text notion-block-99f4ed67f3334268841c270fae85108a">来源：<a class="notion-link" href="https://code.claude.com/docs/en/mcp.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/mcp.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6c6579b7723b43638d5e95610c23b03d" data-id="6c6579b7723b43638d5e95610c23b03d"><span><div id="6c6579b7723b43638d5e95610c23b03d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6c6579b7723b43638d5e95610c23b03d" title="8. 设置与权限（settings.json）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8. 设置与权限（settings.json）</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1bdb6f1c0b434fa2b20aee6fd0823fcf" data-id="1bdb6f1c0b434fa2b20aee6fd0823fcf"><span><div id="1bdb6f1c0b434fa2b20aee6fd0823fcf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1bdb6f1c0b434fa2b20aee6fd0823fcf" title="8.1 层级优先级（从低到高）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8.1 层级优先级（从低到高）</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-6ec6600f5fdf4120aa93ba61251ed15b" style="list-style-type:decimal"><li><code class="notion-inline-code">~/.claude/settings.json</code>（用户全局）</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-57e45c809a514da1a906e733858ec178" style="list-style-type:decimal"><li><code class="notion-inline-code">.claude/settings.json</code>（项目，git 提交）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-4d17360dc3194f67a4c8d6d3edefd26b" style="list-style-type:decimal"><li><code class="notion-inline-code">.claude/settings.local.json</code>（项目本地，gitignored）</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-be36b77ed1d74429b39989113958f875" style="list-style-type:decimal"><li><code class="notion-inline-code">--settings</code> 参数</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-93c350e9f54e4622acb5360b834eed69" style="list-style-type:decimal"><li>托管设置（IT 下发，最高）</li></ol><div class="notion-text notion-block-c1c6d443929f46c290708736ad3749eb">CLI flags（<code class="notion-inline-code">--model</code> 等）临时覆盖当次调用。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-b32a015c85f7449eb5f78202c13e38c2" data-id="b32a015c85f7449eb5f78202c13e38c2"><span><div id="b32a015c85f7449eb5f78202c13e38c2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b32a015c85f7449eb5f78202c13e38c2" title="8.2 权限规则语法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8.2 权限规则语法</span></span></h3><pre class="notion-code language-json notion-code-id-8c63e7500e16440d9cbb2a4921e3a550" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-json">{
  &quot;permissions&quot;: {
    &quot;allow&quot;: [
      &quot;Bash(npm run lint)&quot;,
      &quot;Bash(npm run test *)&quot;,
      &quot;Read(~/.zshrc)&quot;
    ],
    &quot;deny&quot;: [
      &quot;Bash(curl *)&quot;,
      &quot;Read(./.env)&quot;,
      &quot;Read(./.env.*)&quot;
    ]
  }
}</code></pre><ul class="notion-list notion-list-disc notion-block-4cd1c41b9dfc46ac8e11dec60f13468d"><li>Bash 规则用前缀匹配（<code class="notion-inline-code">*</code> 通配参数）；文件规则支持 glob（<code class="notion-inline-code">Edit(src/**)</code>）</li></ul><ul class="notion-list notion-list-disc notion-block-78fbfb3364234cd4b6dfac10ff1e3306"><li>deny 优先于 allow；敏感文件（.env、密钥）建议显式 deny</li></ul><ul class="notion-list notion-list-disc notion-block-670a9a1255ec4be78e30cafdcaa3eb6d"><li>MCP 工具可整体匹配：<code class="notion-inline-code">mcp__github__*</code></li></ul><div class="notion-text notion-block-4832824e9e5c42ae80a5735dbcada985">来源：<a class="notion-link" href="https://code.claude.com/docs/en/settings.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/settings.md</a> 、<a class="notion-link" href="https://code.claude.com/docs/en/permissions.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/permissions.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-47c7c8d1beed476c91f8e697bf017810" data-id="47c7c8d1beed476c91f8e697bf017810"><span><div id="47c7c8d1beed476c91f8e697bf017810" class="notion-header-anchor"></div><a class="notion-hash-link" href="#47c7c8d1beed476c91f8e697bf017810" title="9. 无头模式与自动化"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">9. 无头模式与自动化</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f2fe54f1836044ada57d2a4cdc3fb62e" data-id="f2fe54f1836044ada57d2a4cdc3fb62e"><span><div id="f2fe54f1836044ada57d2a4cdc3fb62e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f2fe54f1836044ada57d2a4cdc3fb62e" title="9.1 Print mode 脚本化"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">9.1 Print mode 脚本化</span></span></h3><pre class="notion-code language-bash notion-code-id-107bf56bf0434d1cac185536d6097215" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash"># 结构化输出
claude -p &quot;Extract all function names&quot; \
  --output-format json \
  --json-schema &#x27;{&quot;type&quot;:&quot;object&quot;,&quot;properties&quot;:{&quot;functions&quot;:{&quot;type&quot;:&quot;array&quot;,&quot;items&quot;:{&quot;type&quot;:&quot;string&quot;}}}}&#x27;

# 流式输出（适合接入其他程序）
claude -p &quot;Explain&quot; --output-format stream-json --include-partial-messages

# 批量并行任务
for f in $(cat files.txt); do
  claude -p &quot;迁移 $f&quot; --allowedTools &quot;Edit,Bash&quot; &amp;
done</code></pre><div class="notion-text notion-block-7b6e42a9d8e8475cb9e014180e000c38">JSON 输出包含 <code class="notion-inline-code">structured_output</code>、<code class="notion-inline-code">session_id</code>、<code class="notion-inline-code">total_cost_usd</code> 等字段，方便脚本消费。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e7b49a1b7e0545c59315b68b8b384aad" data-id="e7b49a1b7e0545c59315b68b8b384aad"><span><div id="e7b49a1b7e0545c59315b68b8b384aad" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e7b49a1b7e0545c59315b68b8b384aad" title="9.2 Bare mode（CI 推荐）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">9.2 Bare mode（CI 推荐）</span></span></h3><div class="notion-text notion-block-b7b9472e1526465b824458da163b785b"><code class="notion-inline-code">--bare</code> 跳过 hooks、skills、MCP 自动发现、auto memory、<a class="notion-link" href="http://CLAUDE.md" target="_blank" rel="noopener noreferrer">CLAUDE.md</a> 加载，保证 CI 中行为可重现；需要的配置用 <code class="notion-inline-code">--settings</code> / <code class="notion-inline-code">--mcp-config</code> / <code class="notion-inline-code">--append-system-prompt</code> 显式传入。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5aad182581f447229ac6cb09a45286a0" data-id="5aad182581f447229ac6cb09a45286a0"><span><div id="5aad182581f447229ac6cb09a45286a0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5aad182581f447229ac6cb09a45286a0" title="9.3 GitHub Actions"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">9.3 GitHub Actions</span></span></h3><div class="notion-text notion-block-c26393b86adc4b6d84ac6f240d96015e">在 Claude Code 交互模式运行 <code class="notion-inline-code">/install-github-app</code> 一键安装，或手动配置：</div><pre class="notion-code language-yaml notion-code-id-1fb5c2216dcd48d6af44cfdc41473386" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-yaml">jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: &quot;Review this PR for security issues&quot;
          claude_args: &quot;--max-turns 5 --model claude-sonnet-5&quot;</code></pre><div class="notion-text notion-block-928eef28fa6c430f9848d0118e75249b">来源：<a class="notion-link" href="https://code.claude.com/docs/en/headless.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/headless.md</a> 、<a class="notion-link" href="https://code.claude.com/docs/en/github-actions.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/github-actions.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7d45b6af08f94c6a844525cffb1fa24f" data-id="7d45b6af08f94c6a844525cffb1fa24f"><span><div id="7d45b6af08f94c6a844525cffb1fa24f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7d45b6af08f94c6a844525cffb1fa24f" title="10. 其他进阶技巧"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">10. 其他进阶技巧</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5c6480599a744f268f411958c20bf515" data-id="5c6480599a744f268f411958c20bf515"><span><div id="5c6480599a744f268f411958c20bf515" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5c6480599a744f268f411958c20bf515" title="10.1 Worktree 并行开发"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">10.1 Worktree 并行开发</span></span></h3><pre class="notion-code language-bash notion-code-id-9e4f9ff7899a497cb88adf30e37d9f56" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">claude -w feature-auth            # 创建或进入隔离工作树
claude -w feature-auth --tmux     # 配合 tmux</code></pre><ul class="notion-list notion-list-disc notion-block-f4a1ff21b9fe4bcb8e776037272d1ee6"><li>多个功能互不干扰，可同时开多个 Claude 会话并行开发</li></ul><ul class="notion-list notion-list-disc notion-block-0562a86979384ff0b766b10a8ff93950"><li>gitignored 但构建必需的文件（如 .env、嵌入资源）可通过 <code class="notion-inline-code">.worktreeinclude</code> 声明自动复制</li></ul><ul class="notion-list notion-list-disc notion-block-1ac0074132034367b1d6fa09ac151898"><li>settings.json 中 <code class="notion-inline-code">worktree.baseRef</code> 控制基于远程默认分支（fresh）还是当前 HEAD</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e36ebbde8b554c45a1a3cbdb04eb5391" data-id="e36ebbde8b554c45a1a3cbdb04eb5391"><span><div id="e36ebbde8b554c45a1a3cbdb04eb5391" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e36ebbde8b554c45a1a3cbdb04eb5391" title="10.2 Plan mode"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">10.2 Plan mode</span></span></h3><div class="notion-text notion-block-c1b1a67c0e8f4ce8a1336e44dd127930">大改动前用 <code class="notion-inline-code">/plan</code> 或 <code class="notion-inline-code">--permission-mode plan</code>：先只读探索并产出方案，批准后再动手，避免方向错了浪费轮次。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-ee9d05a93d154e609c836ffb0e10ffed" data-id="ee9d05a93d154e609c836ffb0e10ffed"><span><div id="ee9d05a93d154e609c836ffb0e10ffed" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ee9d05a93d154e609c836ffb0e10ffed" title="10.3 成本控制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">10.3 成本控制</span></span></h3><ul class="notion-list notion-list-disc notion-block-0dc21bac203a450ba6e50fcfb2c246ef"><li><code class="notion-inline-code">/cost</code> 查看当前会话花费；<code class="notion-inline-code">--max-budget-usd</code> 给无头任务设硬上限</li></ul><ul class="notion-list notion-list-disc notion-block-8e18b871f49743719cf439925f2d74d5"><li>模型选择：简单任务用 Haiku，日常用 Sonnet，复杂推理和审查用 Opus</li></ul><ul class="notion-list notion-list-disc notion-block-fbf53de1f7a047638bfce25e50d91b26"><li>上下文优化：<code class="notion-inline-code">/context</code> 看占用、<code class="notion-inline-code">/compact</code> 主动压缩、不相关任务之间 <code class="notion-inline-code">/clear</code></li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e899f2fb5b8047729b2cafa6d52195b3" data-id="e899f2fb5b8047729b2cafa6d52195b3"><span><div id="e899f2fb5b8047729b2cafa6d52195b3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e899f2fb5b8047729b2cafa6d52195b3" title="10.4 会话管理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">10.4 会话管理</span></span></h3><pre class="notion-code language-bash notion-code-id-867230824ae545249d770beacd282bec" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">claude -n &quot;auth-refactor&quot;         # 命名当前会话
claude --resume &quot;auth-refactor&quot;   # 按名称恢复
claude --resume abc123 --fork-session   # 恢复并分叉，不影响原会话</code></pre><div class="notion-text notion-block-9d629dcc17c24e8ea60397bed915c452">来源：<a class="notion-link" href="https://code.claude.com/docs/en/worktrees.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/worktrees.md</a> 、<a class="notion-link" href="https://code.claude.com/docs/en/sessions.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/sessions.md</a> 、<a class="notion-link" href="https://code.claude.com/docs/en/costs.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/costs.md</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-eaf5e32520a648b1b3d0ddfb2d0ce291" data-id="eaf5e32520a648b1b3d0ddfb2d0ce291"><span><div id="eaf5e32520a648b1b3d0ddfb2d0ce291" class="notion-header-anchor"></div><a class="notion-hash-link" href="#eaf5e32520a648b1b3d0ddfb2d0ce291" title="附：官方文档索引"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">附：官方文档索引</span></span></h2><table class="notion-simple-table notion-block-4ce98c657ca84465ae36aefa2fe29a51"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-8fea817f3566416a82231f60a109bdb2"><td class="" style="width:120px"><div class="notion-simple-table-cell">主题</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">URL</div></td></tr><tr class="notion-simple-table-row notion-block-361e26f08d664b31981ee2c1a00293ac"><td class="" style="width:120px"><div class="notion-simple-table-cell">文档地图</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/claude_code_docs_map.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/claude_code_docs_map.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-5fddf8002dec4801b838291a1c32501e"><td class="" style="width:120px"><div class="notion-simple-table-cell">CLI 参考</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/cli-reference.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/cli-reference.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-7fbd18d1b2f94db9ab8cc9c91a1fbd05"><td class="" style="width:120px"><div class="notion-simple-table-cell">交互模式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/interactive-mode.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/interactive-mode.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-3f231705efc142baafefcc1500b1093c"><td class="" style="width:120px"><div class="notion-simple-table-cell">记忆系统</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/memory.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/memory.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-95845ff2dc804a2fb0b8d8ba822ef6fb"><td class="" style="width:120px"><div class="notion-simple-table-cell">Skills</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/skills.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/skills.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-dcec20c686f14cf1941e5d1ab170ba95"><td class="" style="width:120px"><div class="notion-simple-table-cell">Subagents</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/sub-agents.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/sub-agents.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-bbd2491b8b264e2b87a10283f9912720"><td class="" style="width:120px"><div class="notion-simple-table-cell">Hooks</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/hooks.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/hooks.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-de62bc6d8e0341dc9a839e65964769f5"><td class="" style="width:120px"><div class="notion-simple-table-cell">MCP</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/mcp.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/mcp.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-6947e50413064f2ebddceed4b1d49cc3"><td class="" style="width:120px"><div class="notion-simple-table-cell">设置</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/settings.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/settings.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-e042c83757384f02b12ed017352ed72f"><td class="" style="width:120px"><div class="notion-simple-table-cell">权限</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/permissions.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/permissions.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-2cefbca35e1f4148bc569ac95a23e28e"><td class="" style="width:120px"><div class="notion-simple-table-cell">无头模式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/headless.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/headless.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-f377b16db4404d058ac08a530d64970f"><td class="" style="width:120px"><div class="notion-simple-table-cell">GitHub Actions</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/github-actions.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/github-actions.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-9c1cabb03f344a90b26e26a875a8b439"><td class="" style="width:120px"><div class="notion-simple-table-cell">Worktrees</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/worktrees.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/worktrees.md</a></div></td></tr><tr class="notion-simple-table-row notion-block-5711ab1b73c34ec98d72c2a8ff529a11"><td class="" style="width:120px"><div class="notion-simple-table-cell">Agent SDK</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><a class="notion-link" href="https://code.claude.com/docs/en/agent-sdk/overview.md" target="_blank" rel="noopener noreferrer">https://code.claude.com/docs/en/agent-sdk/overview.md</a></div></td></tr></tbody></table></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Matt Pocock Skills 使用指南]]></title>
            <link>https://hllqk.cn/article/matt-pocock-skills</link>
            <guid>https://hllqk.cn/article/matt-pocock-skills</guid>
            <pubDate>Fri, 24 Jul 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[mattpocock-skills 插件怎么用。2026-07-24 整理自官方仓库和网络资料，2026-07-29 用大白话重写了一遍。 一套给 Claude Code 用的工程纪律 skills，作者 Matt Pocock，就是写 T…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-3a7cdaa272b681988ea3eda2549aae28"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><blockquote class="notion-quote notion-block-c9791ea4c1634153b2c6ab2404c24356"><div>mattpocock-skills 插件怎么用。2026-07-24 整理自官方仓库和网络资料，2026-07-29 用大白话重写了一遍。</div></blockquote><div class="notion-text notion-block-ab331bbd0b064fb8b908440a972c294d">一套给 Claude Code 用的工程纪律 skills，作者 Matt Pocock，就是写 Total TypeScript 的那位。GitHub 上很火，不同来源统计 54k 到 80k+ star。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-e70cc50cf6da4178b2ef40a97f56b19c" data-id="e70cc50cf6da4178b2ef40a97f56b19c"><span><div id="e70cc50cf6da4178b2ef40a97f56b19c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e70cc50cf6da4178b2ef40a97f56b19c" title="这是什么"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">这是什么</span></span></h3><div class="notion-text notion-block-efa58c8fa9864a49805e8a97641baea4">核心想法就一句话：别让 AI 凭感觉瞎写（所谓 vibe coding），把它按进正经软件工程的流程里。写之前先把需求盘清楚，写的时候走 TDD，写完自己 review，隔几天治理一次架构。</div><div class="notion-text notion-block-9c111536eea54357abe7211b0dab97cd">它跟 GSD、BMAD、Spec-Kit 那类框架的区别是不接管你的流程。每个 skill 都很小，能单独用，能自己改，换个模型也能跑。</div><div class="notion-text notion-block-1034c2eb13be405ca515149a2a28106f">本机已经用 Claude Code 插件方式装好了：marketplace 是 mattpocock（仓库 <a class="notion-link" href="https://github.com/mattpocock/skills" target="_blank" rel="noopener noreferrer">github.com/mattpocock/skills），插件</a> mattpocock-skills@mattpocock，v1.2.0，启用 22 个 skills。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-94d7cfd1341c4467b9442788715f5639" data-id="94d7cfd1341c4467b9442788715f5639"><span><div id="94d7cfd1341c4467b9442788715f5639" class="notion-header-anchor"></div><a class="notion-hash-link" href="#94d7cfd1341c4467b9442788715f5639" title="为什么需要它"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">为什么需要它</span></span></h3><div class="notion-text notion-block-e79505068fad4d0aa81a53f05628c351">Matt 把 AI 写代码的翻车归成四类，每类给一个解法：</div><table class="notion-simple-table notion-block-93aa3e5733e54ad18653c3c37be31cdc"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-19e399af95fe48a58f1799daa9e8602d"><td class="" style="width:120px"><div class="notion-simple-table-cell">翻车现场</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">根因</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">解法</div></td></tr><tr class="notion-simple-table-row notion-block-29ac3c1a3a514f54952d47234b3c7dfc"><td class="" style="width:120px"><div class="notion-simple-table-cell">AI 做的不是我想要的</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">你没说清楚，或者你自己也没想清楚</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/grill-me、/grill-with-docs，动手前让 agent 反过来拷问你</div></td></tr><tr class="notion-simple-table-row notion-block-b6746b22ee754f638bee18b53f4d93d1"><td class="" style="width:120px"><div class="notion-simple-table-cell">AI 老是理解偏、说话绕</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">项目黑话没有共享定义</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/grill-with-docs 顺手建一份 <a class="notion-link" href="http://CONTEXT.md" target="_blank" rel="noopener noreferrer">CONTEXT.md</a> 术语表</div></td></tr><tr class="notion-simple-table-row notion-block-d2866a5e5e78426aaef65e20c7211a8b"><td class="" style="width:120px"><div class="notion-simple-table-cell">代码跑不对</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">写完没有反馈回路去验证</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/tdd 红绿重构、/diagnosing-bugs 调试循环</div></td></tr><tr class="notion-simple-table-row notion-block-902844afe7e148fab7f98f8861412e40"><td class="" style="width:120px"><div class="notion-simple-table-cell">架构越写越烂</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">AI 只是把熵增加速了</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/improve-codebase-architecture，隔几天跑一次</div></td></tr></tbody></table><div class="notion-text notion-block-4d34c49fa5c54f5b8e5b21648eb16c73">最出名的是 grilling（拷问）系列。用法很简单：每次要动手改东西，先被拷问一轮，agent 会追着问，直到需求的每个分支都清楚为止。别嫌烦，这一步收益最大。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-5a971a5d2784453ab70d221f17747d43" data-id="5a971a5d2784453ab70d221f17747d43"><span><div id="5a971a5d2784453ab70d221f17747d43" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5a971a5d2784453ab70d221f17747d43" title="先做 setup，一个仓库一次"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">先做 setup，一个仓库一次</span></span></h3><div class="notion-text notion-block-b88a668585f6427390219fc688914437">每个仓库第一次用之前跑：</div><pre class="notion-code language-typescript notion-code-id-8314e6eb49d7407791f7abc0fbe817e2" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-typescript">/setup-matt-pocock-skills</code></pre><div class="notion-text notion-block-f14b179a1953474f89a2048b09faa003">它问三件事然后落成配置：用哪个 issue tracker（GitHub / Linear / 本地文件）、triage 给 ticket 打什么标签、生成的 spec / ADR / 术语表放哪。不跑这一步，工程类 skills 缺配置干不了活。</div><div class="notion-text notion-block-d4ab90f9b10043038972d5d214245e9a">ps. 插件装的 skills 是只读的，跟着作者更新走。想改成自己的版本，用 npx skills@latest add mattpocock/skills 把文件拷进项目里再改。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-50592e14ce20453fa6d608447d019670" data-id="50592e14ce20453fa6d608447d019670"><span><div id="50592e14ce20453fa6d608447d019670" class="notion-header-anchor"></div><a class="notion-hash-link" href="#50592e14ce20453fa6d608447d019670" title="核心工作流(常规开发流程)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><span class="notion-yellow_background">核心工作流(常规开发流程)</span></span></span></h3><div class="notion-text notion-block-385f907f41da4fc78a8a4a902e401ac4">从想法到合并，一条链路把 skills 串起来：</div><pre class="notion-code language-typescript notion-code-id-6e446b55a6ed4849bcfe82e2919a900f" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-typescript">想清楚          →  /grill-me 或 /grill-with-docs   拷问对齐，顺手建领域文档
产出规格        →  /to-spec                        把对话固化成 spec 发到 tracker
拆任务          →  /to-tickets                     拆成一个个小 ticket，带阻塞关系(很少使用)
动手实现        →  /implement                      按 spec/ticket 写，内部走 /tdd
写代码走 TDD    →  /tdd                            红-绿-重构，一次一个纵切片
调试            →  /diagnosing-bugs                复现、最小化、假设、插桩、修、回归测试
提交前审查      →  /code-review or 叫ai review一下（如果有review工作流）                  规范和需求两个轴并行审
定期治理架构    →  /improve-codebase-architecture  扫改进点，出可视化报告</code></pre><div class="notion-text notion-block-2d16ad619402496fa56469b1c3866e84">活太大、一个会话装不下，用 /wayfinder：把工作拆成 tracker 上的一张决策 ticket 地图，一个个啃，直到通往目标的路清晰。</div><div class="notion-text notion-block-2eced901764340f89d044414f8de6be2">拿不准该用哪个，直接问 /ask-matt，它就是个路由器。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-c1c6a54d3a29451aa28fd56ac826f4c9" data-id="c1c6a54d3a29451aa28fd56ac826f4c9"><span><div id="c1c6a54d3a29451aa28fd56ac826f4c9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c1c6a54d3a29451aa28fd56ac826f4c9" title="Skills 全清单"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Skills 全清单</span></span></h3><div class="notion-text notion-block-d16382150a58486ca7f0c408c2ab2d8e">skills 分两种调用方式。user-invoked 只能你手打 /xxx 触发，负责编排流程；model-invoked 你能手动调，agent 匹配到任务时也会自己调，装的是可复用的纪律。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-9983b2b578354b57b3e6cb996e10a4ad" data-id="9983b2b578354b57b3e6cb996e10a4ad"><span><div id="9983b2b578354b57b3e6cb996e10a4ad" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9983b2b578354b57b3e6cb996e10a4ad" title="工程类，日常写代码用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">工程类，日常写代码用</span></span></h4><div class="notion-text notion-block-72f80f1eff934333b4f6f35e6f2e29c5">user-invoked：</div><table class="notion-simple-table notion-block-e2033508a45644dabcb6ebdab014ef51"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-632b3d13dcf14977beb047368e791a22"><td class="" style="width:120px"><div class="notion-simple-table-cell">Skill</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">干嘛的</div></td></tr><tr class="notion-simple-table-row notion-block-d0b8be40280b4db2925e558eed22fe18"><td class="" style="width:120px"><div class="notion-simple-table-cell">/ask-matt</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">路由器，告诉你当前情况该用哪个 skill</div></td></tr><tr class="notion-simple-table-row notion-block-e53d760af3744fb48a50760530aed090"><td class="" style="width:120px"><div class="notion-simple-table-cell">/grill-with-docs</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">拷问的同时建领域模型，更新 <a class="notion-link" href="http://CONTEXT.md" target="_blank" rel="noopener noreferrer">CONTEXT.md</a> 和 ADR，作者自称本仓库最酷的技巧</div></td></tr><tr class="notion-simple-table-row notion-block-5bd62b3d26b64e6abd1b93a0f79e673c"><td class="" style="width:120px"><div class="notion-simple-table-cell">/triage</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用状态机给 issue 和外部 PR 分类、验证，产出 agent 能直接执行的简报</div></td></tr><tr class="notion-simple-table-row notion-block-0eda5311ebc04e92b437614497c310c7"><td class="" style="width:120px"><div class="notion-simple-table-cell">/improve-codebase-architecture</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">扫描架构改进点，出可视化 HTML 报告，挑一个拷问细化</div></td></tr><tr class="notion-simple-table-row notion-block-83348859c17748278ddb7c44bfba5a55"><td class="" style="width:120px"><div class="notion-simple-table-cell">/setup-matt-pocock-skills</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">每个仓库首次使用前的一次性配置</div></td></tr><tr class="notion-simple-table-row notion-block-46318a8c30b645288fbe60c7fb2fa0e7"><td class="" style="width:120px"><div class="notion-simple-table-cell">/to-spec</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">把当前对话直接合成规格发到 tracker，不再访谈</div></td></tr><tr class="notion-simple-table-row notion-block-a2b0c88d2ed642bf806a684bc326e2c0"><td class="" style="width:120px"><div class="notion-simple-table-cell">/to-tickets</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">把计划或规格拆成小 ticket，带阻塞边</div></td></tr><tr class="notion-simple-table-row notion-block-74d81e633c8e4294b653465211dc6803"><td class="" style="width:120px"><div class="notion-simple-table-cell">/implement</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">按 spec 或 ticket 实现，接缝处驱动 /tdd，收尾走 /code-review</div></td></tr><tr class="notion-simple-table-row notion-block-334ebabdd0f445e990ab2b45df695a8a"><td class="" style="width:120px"><div class="notion-simple-table-cell">/wayfinder</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">超大工作量的规划，产出决策 ticket 地图</div></td></tr></tbody></table><div class="notion-text notion-block-ca02a6afa3f447e0ab0be563173fdf0e">model-invoked：</div><table class="notion-simple-table notion-block-e199c93d88d34be1a8c66398029aeea3"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-c9813d61b20849d4a86b92d308e053c4"><td class="" style="width:120px"><div class="notion-simple-table-cell">Skill</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">干嘛的</div></td></tr><tr class="notion-simple-table-row notion-block-ff0406c7aa3345d6b5f5a2f1cf02f34c"><td class="" style="width:120px"><div class="notion-simple-table-cell">/tdd</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">测试驱动开发，红绿重构，一次一个纵切片</div></td></tr><tr class="notion-simple-table-row notion-block-4cfa7f435e0241c4a1b4b31ecffdb776"><td class="" style="width:120px"><div class="notion-simple-table-cell">/diagnosing-bugs</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">硬骨头 bug 和性能回归的纪律化诊断循环</div></td></tr><tr class="notion-simple-table-row notion-block-60d66a8ef7db46c1b9cb128432d9265b"><td class="" style="width:120px"><div class="notion-simple-table-cell">/code-review</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">双轴审查 diff：守没守规范，有没有忠实实现需求，并行子 agent 跑</div></td></tr><tr class="notion-simple-table-row notion-block-c79988e1e78b47a39694610a4aa58112"><td class="" style="width:120px"><div class="notion-simple-table-cell">/research</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">只查高可信一手来源，产出带引用的 md，后台 agent 跑</div></td></tr><tr class="notion-simple-table-row notion-block-3dcaccd1e8054f06ae692cf81f8f20a6"><td class="" style="width:120px"><div class="notion-simple-table-cell">/domain-modeling</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">构建和打磨领域模型，拿术语表和边界场景压测</div></td></tr><tr class="notion-simple-table-row notion-block-6ce687b7392d4405b778246c2c818d6a"><td class="" style="width:120px"><div class="notion-simple-table-cell">/codebase-design</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">深模块设计的共享词汇：小接口藏大行为、放在干净接缝、可测</div></td></tr><tr class="notion-simple-table-row notion-block-a7704f318b794aa1893d550fa28cbb7a"><td class="" style="width:120px"><div class="notion-simple-table-cell">/prototype</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">建一次性原型回答设计问题，可跑的终端 app 或多套 UI 变体</div></td></tr><tr class="notion-simple-table-row notion-block-93cf0be50ff446a4931908da7b414a66"><td class="" style="width:120px"><div class="notion-simple-table-cell">/resolving-merge-conflicts</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">逐 hunk 解 merge/rebase 冲突，按意图溯源，绝不 --abort</div></td></tr></tbody></table><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-2e90e54b15514ebcb4188114843bf50f" data-id="2e90e54b15514ebcb4188114843bf50f"><span><div id="2e90e54b15514ebcb4188114843bf50f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2e90e54b15514ebcb4188114843bf50f" title="生产力类，不限代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">生产力类，不限代码</span></span></h4><div class="notion-text notion-block-083926520fe24275842e9111cb4b0693">user-invoked 有四个：/grill-me 纯拷问对齐、/handoff 把对话压缩成交接文档给下一个 agent、/teach 多会话教你一个概念、/writing-great-skills 是写 skill 的参考。</div><div class="notion-text notion-block-58f94d794a3c4cd4b398f82a83e143ef">model-invoked 一个：/grilling，拷问循环的本体，grill-me 和 grill-with-docs 背后复用的就是它。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3aa937d738814987ba4b88a8d22d004b" data-id="3aa937d738814987ba4b88a8d22d004b"><span><div id="3aa937d738814987ba4b88a8d22d004b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3aa937d738814987ba4b88a8d22d004b" title="杂项"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">杂项</span></span></h4><div class="notion-text notion-block-fe557845f55e42e8bf517e446033381a">/git-guardrails-claude-code 装 hook 拦危险 git 命令（push、reset --hard、clean、branch -D 这些）、/setup-pre-commit 配 Husky + lint-staged + 类型检查 + 测试、/migrate-to-shoehorn、/scaffold-exercises。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-331dc75a86a74227b81bae52049dab08" data-id="331dc75a86a74227b81bae52049dab08"><span><div id="331dc75a86a74227b81bae52049dab08" class="notion-header-anchor"></div><a class="notion-hash-link" href="#331dc75a86a74227b81bae52049dab08" title="其它，谨慎用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">其它，谨慎用</span></span></h4><ul class="notion-list notion-list-disc notion-block-8ff8171e16624bad9772fc65f6ee7316"><li>personal：/edit-article、/obsidian-vault，Matt 个人写作和笔记用的</li></ul><ul class="notion-list notion-list-disc notion-block-625057bdf2e141efba32c4851e886857"><li>in-progress 实验性：/loop-me、/wizard、/claude-handoff、/batch-grill-me、/to-questionnaire、/writing-*、/setup-ts-deep-modules</li></ul><ul class="notion-list notion-list-disc notion-block-b04a53cafd384a82a172128375f144d0"><li>deprecated 别用：/qa、/ubiquitous-language、/design-an-interface、/request-refactor-plan</li></ul><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-3fff4e3345ec4734a1dbc68fa795b897" data-id="3fff4e3345ec4734a1dbc68fa795b897"><span><div id="3fff4e3345ec4734a1dbc68fa795b897" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3fff4e3345ec4734a1dbc68fa795b897" title="常见场景速查"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">常见场景速查</span></span></h3><table class="notion-simple-table notion-block-b610379cc13248cd98510e62075dbe53"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-67f53470a1494ca99e15a75312437993"><td class="" style="width:120px"><div class="notion-simple-table-cell">你想干嘛</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">用这个</div></td></tr><tr class="notion-simple-table-row notion-block-f7b785dc34604add97e21aa9208896fd"><td class="" style="width:120px"><div class="notion-simple-table-cell">开始一个新功能，需求还很模糊</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/grill-me 或 /grill-with-docs</div></td></tr><tr class="notion-simple-table-row notion-block-c180217368ee4949be2838fff4a5b908"><td class="" style="width:120px"><div class="notion-simple-table-cell">讨论完了，固化成正式规格</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/to-spec 然后 /to-tickets</div></td></tr><tr class="notion-simple-table-row notion-block-b65bb31865bf4baa80825273f890fcd6"><td class="" style="width:120px"><div class="notion-simple-table-cell">有 spec 或 ticket，开始写</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/implement，内部会用 /tdd</div></td></tr><tr class="notion-simple-table-row notion-block-0f59fd5bd574485c8f797771986d8759"><td class="" style="width:120px"><div class="notion-simple-table-cell">想测试先行地写代码</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/tdd</div></td></tr><tr class="notion-simple-table-row notion-block-532fa302033245329d7fff6ddfe948c1"><td class="" style="width:120px"><div class="notion-simple-table-cell">有个诡异 bug 或变慢了</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/diagnosing-bugs</div></td></tr><tr class="notion-simple-table-row notion-block-23ef9cadfa2345b88b77abf00432109b"><td class="" style="width:120px"><div class="notion-simple-table-cell">提 PR 前自查</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/code-review</div></td></tr><tr class="notion-simple-table-row notion-block-27c56ec2f7c8457881077ab30328052d"><td class="" style="width:120px"><div class="notion-simple-table-cell">感觉代码越来越难改</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/improve-codebase-architecture</div></td></tr><tr class="notion-simple-table-row notion-block-4d62de0cf63e48e5900aa2d1d97595f8"><td class="" style="width:120px"><div class="notion-simple-table-cell">活太大一个会话装不下</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/wayfinder</div></td></tr><tr class="notion-simple-table-row notion-block-a77ae536e65644268d7265a3d073ddff"><td class="" style="width:120px"><div class="notion-simple-table-cell">不知道该用哪个</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/ask-matt</div></td></tr><tr class="notion-simple-table-row notion-block-46ecde1976e04f929fe40d82e6b6feca"><td class="" style="width:120px"><div class="notion-simple-table-cell">会话要结束，交给下一个 agent</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">/handoff</div></td></tr></tbody></table><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-8c7f1d200e4a4a3fa5661fbde7aeef22" data-id="8c7f1d200e4a4a3fa5661fbde7aeef22"><span><div id="8c7f1d200e4a4a3fa5661fbde7aeef22" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8c7f1d200e4a4a3fa5661fbde7aeef22" title="注意事项"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">注意事项</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-37ae1659579440ddbf0259cf10fee2f8" style="list-style-type:decimal"><li>刚装完的会话里 skills 可能还没加载，下次启动才完全生效。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-9432ba698c3c49349925b444353c60f3" style="list-style-type:decimal"><li>新仓库先跑 /setup-matt-pocock-skills，不然工程类 skills 缺 tracker 和文档配置。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-c592b8dddbe4482599f6b149196890c4" style="list-style-type:decimal"><li>token 开销：整套常驻大约 1.4k tokens 每会话，单个 skill 被调用时另算，diagnosing-bugs 约 2.8k，triage 约 2.2k。claude plugin details mattpocock-skills@mattpocock 能看明细，不用的可以 claude plugin disable 关掉。</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-d8635aeef5444bdea55a44593e1456e0" style="list-style-type:decimal"><li>插件版是只读的，想 hack 就用 <a class="notion-link" href="http://skills.sh" target="_blank" rel="noopener noreferrer">skills.sh</a> 的安装器把文件拷进项目。</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-2bf2491988fe4d448bde60e514001337" style="list-style-type:decimal"><li>再说一遍，grilling 是精髓，改动前先被拷问一轮，收益最大。</li></ol><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-58d905eb56df425687e1f8a2307a1d4b" data-id="58d905eb56df425687e1f8a2307a1d4b"><span><div id="58d905eb56df425687e1f8a2307a1d4b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#58d905eb56df425687e1f8a2307a1d4b" title="参考来源"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考来源</span></span></h3><ul class="notion-list notion-list-disc notion-block-aa611a2b7a9648aca4db33b25208b3c8"><li>官方仓库：<a class="notion-link" href="https://github.com/mattpocock/skills" target="_blank" rel="noopener noreferrer">github.com/mattpocock/skills</a> · <a class="notion-link" href="https://skills.sh/mattpocock/skills" target="_blank" rel="noopener noreferrer">skills.sh 页面</a></li></ul><ul class="notion-list notion-list-disc notion-block-6b95b374347849479d5f7ab65ea6118d"><li><a class="notion-link" href="https://medium.com/@anmjawad007/the-two-matt-pocock-skills-i-use-in-almost-every-ai-coding-session-57c468938145" target="_blank" rel="noopener noreferrer">The Two Matt Pocock Skills I Use in Almost Every AI Coding Session — Medium</a></li></ul><ul class="notion-list notion-list-disc notion-block-812a2732a9af4dd4b8190ccdd0d65de4"><li>Matt Pocock&#x27;s 5 Claude Code skills made me rewrite how I work with AI agents — Medium</li></ul><ul class="notion-list notion-list-disc notion-block-36d9a6d1f19247499525643c968a22b5"><li>Claude Code Skills: mattpocock&#x27;s 80K-Star Framework — AI Agents First</li></ul><ul class="notion-list notion-list-disc notion-block-dda822a2f6534255821e1e8fb48529fc"><li><a class="notion-link" href="https://andrew.ooo/posts/matt-pocock-skills-claude-code-review/" target="_blank" rel="noopener noreferrer">Matt Pocock&#x27;s Skills Review — andrew.ooo</a></li></ul><ul class="notion-list notion-list-disc notion-block-844a1c22c1824e1c978178e07f08c8a2"><li><a class="notion-link" href="https://knightli.com/en/2026/05/15/matt-pocock-skills-ai-engineering-workflow/" target="_blank" rel="noopener noreferrer">mattpocock/skills Explained — knightli.com</a></li></ul><ul class="notion-list notion-list-disc notion-block-78d885485a6d467bac87fd5e576f0ecf"><li><a class="notion-link" href="https://tosea.ai/blog/matt-pocock-skills-claude-code-guide" target="_blank" rel="noopener noreferrer">How to Use Matt Pocock&#x27;s Skills for Claude Code: A Complete Guide — Tosea.ai</a></li></ul><ul class="notion-list notion-list-disc notion-block-f0547775238540559cec958b0cbb15dc"><li><a class="notion-link" href="https://www.developersdigest.tech/blog/github-trending-skills-2026-05-13" target="_blank" rel="noopener noreferrer">Matt Pocock&#x27;s Skills Repo Is a Better Pattern Than Vibe Coding — Developers Digest</a></li></ul><ul class="notion-list notion-list-disc notion-block-73ba1ff6c8d942a79ca09d7312a55fb3"><li><a class="notion-link" href="https://www.claudepluginhub.com/plugins/hgxszhj-mattpocock-skills" target="_blank" rel="noopener noreferrer">mattpocock-skills — Claude Plugin Hub</a></li></ul><div class="notion-text notion-block-3accdaa272b6800c9142dd10f6f2e702">补充：建议cc使用插件
Opus 5 high 常驻；复杂或高风险任务升 xhigh；Fable 5 留给大型长期任务；max 只做最后攻坚</div><div class="notion-text notion-block-3accdaa272b680c09f9efc706d9260af">cli要安装claude hud</div><div class="notion-text notion-block-3adcdaa272b680ee8390ea9813d4a17c">插件要安装<b>Claude Code Usage</b></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[我的AI原生开发实践]]></title>
            <link>https://hllqk.cn/article/ai-native-development</link>
            <guid>https://hllqk.cn/article/ai-native-development</guid>
            <pubDate>Mon, 06 Jul 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[用工作流驯服 AI 跟 AI 结对编程这事儿，大家都摸索过一阵子。一开始，我们总是习惯性地在对话框里敲下“帮我写个 XX 功能”，然后满心欢喜地看着它咔咔输出代码。但现实往往是，它写着写着就放飞自我，最后给你留下一堆跑不通的烂摊子。 痛定思…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-395cdaa272b68051b838c156188a41f2"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-395cdaa272b68092a8c1e05d30afb926" data-id="395cdaa272b68092a8c1e05d30afb926"><span><div id="395cdaa272b68092a8c1e05d30afb926" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b68092a8c1e05d30afb926" title="用工作流驯服 AI"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">用工作流驯服 AI</span></span></h2><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-395cdaa272b6809bba01c8845853e938"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/395cdaa2-72b6-809b-ba01-c8845853e938?src=attachment%3Adca0ecba-6c2e-4f46-8875-1dd8f2d8177a%3AChatGPT_Image_2026%E5%B9%B47%E6%9C%886%E6%97%A5_15_58_44.png"/></div></figure><div class="notion-text notion-block-395cdaa272b680dcb165d4ba7fb7161d">跟 AI 结对编程这事儿，大家都摸索过一阵子。一开始，我们总是习惯性地在对话框里敲下“帮我写个 XX 功能”，然后满心欢喜地看着它咔咔输出代码。但现实往往是，它写着写着就放飞自我，最后给你留下一堆跑不通的烂摊子。</div><div class="notion-text notion-block-395cdaa272b680828f6dda81229ebeff">痛定思痛后，我日常琢磨出了一套能让 AI 在整个开发流程里不偏离方向的实践方案。</div><div class="notion-text notion-block-395cdaa272b68055af8be88da49a5402"><b>核心理念其实就一句话：别跟 AI 聊天，用文档驱动它。</b></div><div class="notion-text notion-block-395cdaa272b680e898c9cf7fa9241fa5">具体怎么操作呢？思路很简单：先用 OpenSpec 把需求和设计定死，绝不让它自由发挥；接着用 SuperPower 把控执行过程，按规矩写代码跑测试；最后挂上 proxy 智能路由，根据任务难度自动选模型，对于opus我会转发到GLM5.2，对于sonnet用kimi2.7，haiku用v4flash，减少API成本。</div><div class="notion-text notion-block-395cdaa272b68041bb0fdc983da4eb8f">提到动态路由，我选择的项目是Proxy, <a class="notion-external notion-external-mention" href="https://github.com/routatic/proxy/pull/111" target="_blank" rel="noopener noreferrer"><div class="notion-external-image"><svg viewBox="0 0 260 260"><g><path d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z" fill="#161614"></path></g></svg></div><div class="notion-external-description"><div class="notion-external-title">Fix: Narrow complex scenario keywords to prevent false-positive routing</div><div class="notion-external-subtitle"><div class="notion-preview-card-domain-warp"><div class="notion-preview-card-logo"><svg viewBox="0 0 260 260"><g><path d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z" fill="#161614"></path></g></svg></div><div class="notion-preview-card-domain">Github</div></div><div class="notion-preview-card-title">Fix: Narrow complex scenario keywords to prevent false-positive routing</div><div class="notion-external-subtitle-item"><div class="notion-external-subtitle-item-name">Updated</div><span class="notion-external-subtitle-item-desc">Jul 6, 2026</span></div><div class="notion-preview-card-github-shields"><img src="https://img.shields.io/github/stars/undefined/Fix: Narrow complex scenario keywords to prevent false-positive routing?logo=github" alt=""/><img src="https://img.shields.io/github/last-commit/undefined/Fix: Narrow complex scenario keywords to prevent false-positive routing" alt=""/></div></div></div></a>，专门适配opencode的go计划，期间遇到了cc只会调用glm5.2的问题，最终分析发现在complex任务中，把tool调用也算入了complex任务，还有很多不相干的关键词，解决上面问题并且pr后。成功实现了低消费的动态路由，如下图：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-395cdaa272b680999409f9769ec623b0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/395cdaa2-72b6-8099-9409-f9769ec623b0?src=attachment%3Acbce2c88-ebf9-4b9a-b2a3-5cd1a8ee4b05%3Aimage.png"/></div></figure><div class="notion-text notion-block-395cdaa272b6805a9de5db2aef16901c">这么一套组合拳走下来，AI 终于消停了，从一个到处埋雷和费钱的NPC，变成了一个能干活、好验证、还不怎么费钱的靠谱工具人。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b680f080d7de3389e54a9f" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart LR
    A[模糊想法] --&gt; B[OpenSpec&lt;br/&gt;蓝图与规格]
    B --&gt; C[SuperPower&lt;br/&gt;按规矩执行]
    C --&gt; D[Proxy 智能路由&lt;br/&gt;管住成本]
    D --&gt; E[可交付的代码]
    B -.文档先行.-&gt; C
    C -.成本约束.-&gt; D
    style B fill:#e3f2fd,stroke:#1976d2
    style C fill:#fff3e0,stroke:#f57c00
    style D fill:#e8f5e9,stroke:#388e3c</code></pre><hr class="notion-hr notion-block-395cdaa272b6806d8b2fc885e503a9c1"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-395cdaa272b680448df6f0285abef4d3" data-id="395cdaa272b680448df6f0285abef4d3"><span><div id="395cdaa272b680448df6f0285abef4d3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680448df6f0285abef4d3" title="工具选型：不选最贵的，只选最对的"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">工具选型：不选最贵的，只选最对的</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680d685a4c91f13dbb319" data-id="395cdaa272b680d685a4c91f13dbb319"><span><div id="395cdaa272b680d685a4c91f13dbb319" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680d685a4c91f13dbb319" title="AI Agent 框架：为啥我死磕 Claude Code？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">AI Agent 框架：为啥我死磕 Claude Code？</span></span></h4><div class="notion-text notion-block-395cdaa272b6804d923bd2e91d5a4e14">市面上的 Agent 框架不少，我做过几轮横评：</div><ul class="notion-list notion-list-disc notion-block-395cdaa272b68038ab51ca45e2255783"><li><b>Hermes Agent</b>：啥都好，就是写代码拉胯，更适合干点自动化，重复的活。</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b680728103c039e56d9cdf"><li><b>OpenCode+Omo</b>： Omo插件与OpenCode其他插件严重冲突导致功能失效，且长时间运行后模型会停止输出任何可见文本，使整个会话完全不可用。</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b680abadebc56b6eb310b4"><li><b>AmpCode</b>：不计成本，完全放权给AI</li></ul><div class="notion-text notion-block-395cdaa272b680ff850be3ecb8ab4837">最后发现，还得是 <b>Claude Code</b>。它理解代码的深度和工程化能力确实没得挑，虽然前几天出现了在cc里面埋雷事件，但论能力，还是数一数二的，把它当“首席工程师”用，能自己看懂全局上下文自主干活，<b>省心又省力</b>。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680708119fc214b746af8" data-id="395cdaa272b680708119fc214b746af8"><span><div id="395cdaa272b680708119fc214b746af8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680708119fc214b746af8" title="工作流框架：GSD 太重，OpenSpec + SuperPower 刚刚好"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">工作流框架：GSD 太重，OpenSpec + SuperPower 刚刚好</span></span></h4><div class="notion-text notion-block-395cdaa272b6806983f4c2ba265a9979">试过了GSD，流程太重，中小项目用起来有种杀鸡用牛刀的憋屈感。后来换了 <b>OpenSpec</b> 和 <b>SuperPower</b> 的组合拳，瞬间清爽了。</div><div class="notion-text notion-block-395cdaa272b680188817f65c4125a1ec">这俩为啥必须一起用？因为它们完美互补：</div><ul class="notion-list notion-list-disc notion-block-395cdaa272b6809fb0e8fcb9d1adb2b6"><li><b>OpenSpec 负责“想清楚”</b>：把模糊的想法变成清晰的文档，做技术选型，写设计文档。也就是搞定“做什么”和“为什么做”。</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b680eb8244c4b220d95b1e"><li><b>SuperPower 负责“干漂亮”</b>：写具体代码，搞测试驱动开发（TDD），做代码审查。也就是落实“怎么做”并保证质量。</li></ul><pre class="notion-code language-mermaid notion-code-id-395cdaa272b680a9924af56b37f2199c" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart TB
    subgraph OS[&quot;OpenSpec — 规格层&quot;]
        O1[&quot;proposal 提议&quot;]
        O2[&quot;design 设计&quot;]
        O3[&quot;tasks 任务&quot;]
        O4[&quot;spec 规格&quot;]
        O1 --&gt; O2 --&gt; O3 --&gt; O4
    end
    subgraph SP[&quot;SuperPower — 执行层&quot;]
        S1[&quot;/sp:plan 规划&quot;]
        S2[&quot;/sp:apply 实现&quot;]
        S3[&quot;/sp:verify 验证&quot;]
        S4[&quot;/sp:review 审查&quot;]
        S1 --&gt; S2 --&gt; S3 --&gt; S4
    end
    O4 --&gt;|文档基线| S1
    S4 --&gt;|交付反馈| O4
    style OS fill:#e3f2fd,stroke:#1976d2
    style SP fill:#fff3e0,stroke:#f57c00</code></pre><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680378467ce1162735fd4" data-id="395cdaa272b680378467ce1162735fd4"><span><div id="395cdaa272b680378467ce1162735fd4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680378467ce1162735fd4" title="省钱方案：proxy 智能路由真香"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">省钱方案：proxy 智能路由真香</span></span></h4><div class="notion-text notion-block-395cdaa272b680c88a85db7b528a4d5f">刚开始不懂事，直接拿智谱 GLM-5.1 跑规划，模型确实强，但光做一次规划就花了小三十块，眼看着账单数字往上飙，那叫一个肉疼。后来学乖了，轻量活儿改用 GLM-4.7，勉强拉回一点成本。</div><div class="notion-text notion-block-395cdaa272b680fe9b6bf4d8f3bef64a">真正的转折点是我在 <a class="notion-link" href="http://linux.do/" target="_blank" rel="noopener noreferrer">Linux.do</a> 社区挖到了一个开源项目：<b>routatic/proxy</b>。它能把 Claude Code 的请求按场景智能分流到不同的国产模型上。启用流式场景路由后，一切自动化，它自己就能判断啥时候需要深度思考，啥时候只需简单补全。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b68047a38bc4eb403c0e20" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart LR
    R[Claude Code 请求] --&gt; P{Proxy 路由&lt;br/&gt;按场景分流}
    P --&gt;|深度推理/复杂规划| M1[GLM-5.2&lt;br/&gt;旗舰]
    P --&gt;|日常通用编码| M2[Kimi K2.7&lt;br/&gt;性价比]
    P --&gt;|轻量补全/快速问答| M3[DeepSeek V4 Flash&lt;br/&gt;极低成本]
    M1 --&gt; Cost
    M2 --&gt; Cost
    M3 --&gt; Cost
    Cost[整体成本下降 80%+]
    style P fill:#e8f5e9,stroke:#388e3c
    style Cost fill:#fff9c4,stroke:#f9a825</code></pre><hr class="notion-hr notion-block-395cdaa272b68000a2ffc0aa4bc852a0"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-395cdaa272b6806bb237d7bb3165774d" data-id="395cdaa272b6806bb237d7bb3165774d"><span><div id="395cdaa272b6806bb237d7bb3165774d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b6806bb237d7bb3165774d" title="实战流程：13步拿捏 AI"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">实战流程：13步拿捏 AI</span></span></h3><div class="notion-text notion-block-395cdaa272b680c4bdadd7f45da75209">这套工作流最特殊的地方在于，它把开发拆成了 13 个步骤，每一步谁来做、为啥做都明明白白。装好工具后，Claude Code 里会多出一堆自定义命令。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b680c1b9abe9fb9873e175" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart TD
    S1[1. /opsx:propose&lt;br/&gt;生成四份文档] --&gt; S2[2. 人工评审方案]
    S2 --&gt; S3[3. /opsx:explore&lt;br/&gt;AI 反问+澄清]
    S3 --&gt; S4[4. 锁定文档基线]
    S4 --&gt; S5[5. /sp:plan&lt;br/&gt;详细实现计划]
    S5 --&gt; S6[6. 确认任务粒度]
    S6 --&gt; S7[7. /sp:apply&lt;br/&gt;TDD 红绿重构]
    S7 --&gt; S8[8. 手动业务验证]
    S8 --&gt; S9[9. /sp:verify&lt;br/&gt;自动化验证]
    S9 --&gt; S10[10. /sp:review&lt;br/&gt;代码审查]
    S10 --&gt; S11[11. /sp:finish&lt;br/&gt;合并+PR]
    S11 --&gt; S12[12. /opsx:archive&lt;br/&gt;规格归档]
    S12 --&gt; S13[13. /sp:archive&lt;br/&gt;文档归档]
    S3 -.需求有变更回到这里.-&gt; S3
    style S7 fill:#fff3e0,stroke:#f57c00
    style S10 fill:#e8f5e9,stroke:#388e3c</code></pre><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680a89713f516c3a89a01" data-id="395cdaa272b680a89713f516c3a89a01"><span><div id="395cdaa272b680a89713f516c3a89a01" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680a89713f516c3a89a01" title="挑几个关键步骤说说"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><span class="notion-red_background">挑几个关键步骤说说</span></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b6808f9310c481c30b4590" data-id="395cdaa272b6808f9310c481c30b4590"><span><div id="395cdaa272b6808f9310c481c30b4590" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b6808f9310c481c30b4590" title="从画图纸开始 (/opsx:propose)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">从画图纸开始 (/opsx:propose)</span></span></h4><div class="notion-text notion-block-395cdaa272b680618f2df0a79ef625d1">输入这行命令，AI 会在项目目录下生成四份文档：proposal 讲要做什么，design 讲怎么做，tasks 拆任务，spec 定验收标准。说白了就是让 AI 帮你把脑子里模糊的想法变成白纸黑字——你还没写一行代码，需求文档就已经出来了。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b6800aba3ec76a14c14df5" data-id="395cdaa272b6800aba3ec76a14c14df5"><span><div id="395cdaa272b6800aba3ec76a14c14df5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b6800aba3ec76a14c14df5" title="最磨人的一步：跟 AI 对质 (/opsx:explore)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">最磨人的一步：跟 AI 对质 (/opsx:explore)</span></span></h4><div class="notion-text notion-block-395cdaa272b680899f66f656721efe7b">这一步是整个流程里投入产出比最高的，也是最烦的。AI 会像个不太信任你的架构师一样追着问：&quot;这个边界情况你考虑了吗？&quot;&quot;如果外部服务挂了怎么办？&quot;&quot;你的分页支持 offset 还是游标？&quot;</div><div class="notion-text notion-block-395cdaa272b680119abdd0d13604b682">你得一条条回答。</div><div class="notion-text notion-block-395cdaa272b680e18563d3bedfdb0dd6">烦是真烦，但答完之后你会发现——之前那些&quot;到时候再说&quot;的模糊地带，全被堵死了。后面 AI 写代码的时候想自由发挥都没空间。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b68015af42fa86375f00d6" data-id="395cdaa272b68015af42fa86375f00d6"><span><div id="395cdaa272b68015af42fa86375f00d6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b68015af42fa86375f00d6" title="sp 命令的来历：市面上没有，自己造的"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">sp 命令的来历：市面上没有，自己造的</span></span></h4><div class="notion-text notion-block-395cdaa272b68084a4f1ce7c3992f936">说到这里得坦白一件事：<b>带 </b><code class="notion-inline-code"><b>sp:</b></code><b> 前缀的这些命令，市面上根本找不到。</b></div><div class="notion-text notion-block-395cdaa272b680358cededc5b7fc79a7">OpenSpec 自带的命令管的是&quot;想清楚&quot;——propose、explore、archive 这些都是它原生的。但到了&quot;动手干&quot;这个阶段，我发现 OpenSpec 原生的 plan 太粗了，apply 更是压根没有 TDD 的概念。SuperPower 那边倒是有写代码的能力，但没有标准化的命令体系来约束开发范式。</div><div class="notion-text notion-block-395cdaa272b680478599de6bfc02db24">所以后面的 plan、apply、verify、review、finish、archive 六个命令，全是我自己一个一个手搓出来的。每个命令都是一段精心设计的 prompt 模板，专门用来约束 AI 在对应阶段的行为。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680bc8f09eccf2f0bc351" data-id="395cdaa272b680bc8f09eccf2f0bc351"><span><div id="395cdaa272b680bc8f09eccf2f0bc351" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680bc8f09eccf2f0bc351" title="规划要够细 (/sp:plan)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">规划要够细 (/sp:plan)</span></span></h4><div class="notion-text notion-block-395cdaa272b680d097c5d2f2a58c15ea">OpenSpec 原生的 plan 只是基于 tasks 粗略拆一下，远远不够。我在这个基础上重新实现了一个 plan 命令，它会生成一份 <code class="notion-inline-code">implementation-plan.md</code>——里面不光有任务列表，还有任务之间的依赖关系、每个任务涉及的具体文件路径、可验收的完成标准、风险等级，甚至会分析哪些任务可以并行执行。</div><div class="notion-text notion-block-395cdaa272b680d0abbfec2e97b3d946">为什么要做到这个粒度？因为后面要用 TDD 开发，如果任务拆得不够细，AI 写测试的时候根本不知道该测什么。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680339940e2700bdd79a6" data-id="395cdaa272b680339940e2700bdd79a6"><span><div id="395cdaa272b680339940e2700bdd79a6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680339940e2700bdd79a6" title="TDD 红绿灯 (/sp:apply)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">TDD 红绿灯 (/sp:apply)</span></span></h4><div class="notion-text notion-block-395cdaa272b68017b121f62e99414a04">apply 命令是我花心思最多的一个。我专门把 TDD 的红-绿-重构范式写成了一套完整的 prompt，&quot;教&quot;给 AI 怎么走这个循环：每接一个任务，必须先写一个注定失败的测试（红灯），定义好&quot;正确的行为是什么&quot;；再写最简单的代码让测试通过（绿灯），不多写一行；最后在测试全绿的前提下重构优化。</div><div class="notion-text notion-block-395cdaa272b6804b97d2cc8ff2aaacb8">不能跳步，不能偷懒。AI 想直接写实现代码？不行，先写测试。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b6803baf3ceab8abcd69f5" data-id="395cdaa272b6803baf3ceab8abcd69f5"><span><div id="395cdaa272b6803baf3ceab8abcd69f5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b6803baf3ceab8abcd69f5" title="验证提示词是从各路技术社区淘来的 (/sp:verify)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">验证提示词是从各路技术社区淘来的 (/sp:verify)</span></span></h4><div class="notion-text notion-block-395cdaa272b680c083e0c584784909d0">verify 命令解决的问题是：代码写完了，怎么确认它真的没问题？</div><div class="notion-text notion-block-395cdaa272b68008a024faeca8cc1ba4">我专门去一些技术平台——GitHub 的最佳实践讨论、各种 AI 编程社区——收集了一批专门用来验证代码质量的提示词，然后整合成了一个 verify 函数。它会自动检测项目类型（Java、Python、Go、Node 都认），然后跑对应的单元测试、检查日志里有没有 ERROR、跑回归测试确保没有破坏已有功能、还会对着 implementation-plan 里的边界情况逐条验证。</div><div class="notion-text notion-block-395cdaa272b680788318dcaa787e6189">最终输出一份结构化的报告：PASS 还是 FAIL，哪里有问题，一目了然。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b68055bf88f8b7ee6ef613" data-id="395cdaa272b68055bf88f8b7ee6ef613"><span><div id="395cdaa272b68055bf88f8b7ee6ef613" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b68055bf88f8b7ee6ef613" title="审查不能自己审自己 (/sp:review)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">审查不能自己审自己 (/sp:review)</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-395cdaa272b6808ba8dad961d5ceb425" style="list-style-type:decimal"><li>首先是关于怎么 “审查”</li></ol><div class="notion-text notion-block-395cdaa272b6803b988fc72942c98b54">verify 过了不代表代码质量过关。review 命令做的是代码审查——对照 implementation-plan 里的验收标准，逐条检查代码有没有做到位。覆盖四个维度：正确性（逻辑有没有 bug）、可维护性（命名清不清晰、函数长不长）、安全性（有没有硬编码密钥、注入风险）、性能（有没有 N+1 查询、内存泄漏）。</div><div class="notion-text notion-block-395cdaa272b680b78b28d523952eea3a">审查结果分两级：Must Fix 是阻塞项，不修不能合并；Nice to Have 是建议，可以后续再改。</div><ol start="2" class="notion-list notion-list-numbered notion-block-395cdaa272b680a1a2c6c1d09d40f2c0" style="list-style-type:decimal"><li>关于不能审自己</li></ol><div class="notion-text notion-block-395cdaa272b680a1bb2ae3a565e3d898">我是让cc专门启用一个subagent,调用Glm5模型做一个多层面的审查，避免同一个模型不断自身导致幻觉积累越来越多的问题（<b>就像去ai味一样，ai参与越多越难去掉，还是需要人的参与与决策</b>）</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b68091b964e4a400ebf001" data-id="395cdaa272b68091b964e4a400ebf001"><span><div id="395cdaa272b68091b964e4a400ebf001" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b68091b964e4a400ebf001" title="一键交付 (/sp:finish)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一键交付 (/sp:finish)</span></span></h4><div class="notion-text notion-block-395cdaa272b68049ad24e42994784843">finish 命令干三件事：确认所有任务完成、测试通过；合并代码到目标分支；自动创建 PR（连描述模板都帮你填好了）。如果你用了 worktree 做隔离开发，它还会顺手清理残留的 worktree。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680fda4e6d395b1a51037" data-id="395cdaa272b680fda4e6d395b1a51037"><span><div id="395cdaa272b680fda4e6d395b1a51037" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680fda4e6d395b1a51037" title="规格闭环 (/sp:archive)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">规格闭环 (/sp:archive)</span></span></h4><div class="notion-text notion-block-395cdaa272b6802cb76cf9bc15f4f39d">最后的 archive 命令是我额外加的——OpenSpec 原生的 archive 只是把 spec 文件归档，但我觉得不够。我实现的版本会把归档的文档内容做一个总结，然后自动更新仓库里对应的开发文档或者开发日志。这样每次开发完，仓库里的文档永远是最新状态，不会出现&quot;代码改了但文档没更新&quot;的尴尬。</div><hr class="notion-hr notion-block-395cdaa272b680ef9029d7e4154bab13"/><div class="notion-text notion-block-395cdaa272b680b09ffccadccb0a9d6a">这就是我这套方案的完整面貌。六个 <code class="notion-inline-code">sp:*</code> 命令，每个都是针对一个开发阶段的痛点设计的。OpenSpec 管&quot;想清楚&quot;，<code class="notion-inline-code">sp:*</code> 管&quot;干明白&quot;，两者合在一起才构成一个从需求到交付的完整闭环。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b68080a1f1fa918d1bfac0" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart LR
    R[红灯&lt;br/&gt;先写失败测试] --&gt; G[绿灯&lt;br/&gt;最小实现通过测试]
    G --&gt; Ref[重构&lt;br/&gt;测试全绿下优化]
    Ref -.下一轮.-&gt; R
    style R fill:#ffebee,stroke:#c62828
    style G fill:#e8f5e9,stroke:#2e7d32
    style Ref fill:#e3f2fd,stroke:#1565c0</code></pre><hr class="notion-hr notion-block-395cdaa272b68088a7e9df96d5b8b164"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-395cdaa272b680e99ceec736909aca7c" data-id="395cdaa272b680e99ceec736909aca7c"><span><div id="395cdaa272b680e99ceec736909aca7c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680e99ceec736909aca7c" title="当需求变了？别急着改代码！"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">当需求变了？别急着改代码！</span></span></h3><div class="notion-text notion-block-395cdaa272b680488caaf35ec7160983">开发最怕啥？需求变更。但在这套流程里，有个铁律：<b>“文档先行，代码殿后”</b>。就算只改个字段名，也别手贱去改代码，必须回到第 3 步重走 <code class="notion-inline-code">/opsx:explore</code>。虽然看着繁琐，但这保证了每一次变更都有迹可循，不会把项目变成一锅粥。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b680ec8804c278435f296b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart LR
    Change(&quot;需求变更&quot;) --&gt; Check(&quot;改代码还是改文档&quot;)
    Check --&gt;|错误做法| Bad[&quot;直接改代码 基线崩坏&quot;]
    Check --&gt;|正确做法| Good[&quot;回到 OpenSpec 改文档&quot;]
    Good --&gt; Re[&quot;opsex:explore 重新澄清&quot;]
    Re --&gt; Plan[&quot;sp:plan 重新规划&quot;]
    Plan --&gt; Apply[&quot;sp:apply 重新实现&quot;]
    style Bad fill:#ffebee,stroke:#c62828
    style Good fill:#e8f5e9,stroke:#2e7d32</code></pre><hr class="notion-hr notion-block-395cdaa272b680b5909fca68a400b38f"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-395cdaa272b680fcb380c4b37eec6095" data-id="395cdaa272b680fcb380c4b37eec6095"><span><div id="395cdaa272b680fcb380c4b37eec6095" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680fcb380c4b37eec6095" title="真实案例：给 Apache SeaTunnel 补个Task"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">真实案例：给 Apache SeaTunnel 补个Task</span></span></h3><div class="notion-text notion-block-395cdaa272b68017b9c3df799086eea7">光说不练假把式。拿我最近搞的一个真实项目 <b>seatunnel-hg-connector</b> 举例。</div><div class="notion-text notion-block-395cdaa272b68061975bf0f252263280">相关pr链接：<a class="notion-external notion-external-mention" href="https://github.com/apache/seatunnel/pull/11340" target="_blank" rel="noopener noreferrer"><div class="notion-external-image"><svg viewBox="0 0 260 260"><g><path d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z" fill="#161614"></path></g></svg></div><div class="notion-external-description"><div class="notion-external-title">[Fix][Connector-V2] Normalize edge id to String + Fix HugeGraph Source connector issues</div><div class="notion-external-subtitle"><div class="notion-preview-card-domain-warp"><div class="notion-preview-card-logo"><svg viewBox="0 0 260 260"><g><path d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z" fill="#161614"></path></g></svg></div><div class="notion-preview-card-domain">Github</div></div><div class="notion-preview-card-title">[Fix][Connector-V2] Normalize edge id to String + Fix HugeGraph Source connector issues</div><div class="notion-external-subtitle-item"><div class="notion-external-subtitle-item-name">Updated</div><span class="notion-external-subtitle-item-desc">Sep 5, 2026</span></div><div class="notion-preview-card-github-shields"><img src="https://img.shields.io/github/stars/undefined/[Fix][Connector-V2] Normalize edge id to String + Fix HugeGraph Source connector issues?logo=github" alt=""/><img src="https://img.shields.io/github/last-commit/undefined/[Fix][Connector-V2] Normalize edge id to String + Fix HugeGraph Source connector issues" alt=""/></div></div></div></a></div><div class="notion-text notion-block-395cdaa272b680b0b109d7aadb2fc4ae"><b>背景</b>：Apache SeaTunnel 里的 HugeGraph 连接器只支持写，不支持读。我的任务就是补齐这个 Source 连接器。</div><div class="notion-text notion-block-395cdaa272b6807a8dbbcb6a91719580">走了一遍流程后，AI 在 <code class="notion-inline-code">/opsx:explore</code> 阶段问出的几个问题直接问倒我了：</div><ul class="notion-list notion-list-disc notion-block-395cdaa272b6802c871fe6d36e951729"><li>顶点和边的字段映射要不要包含 <code class="notion-inline-code">id</code>、<code class="notion-inline-code">label</code>？</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b6802e87fce84cf98c8eeb"><li><code class="notion-inline-code">properties</code> 过滤是白名单还是黑名单？空集合代表全要还是全不要？</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b68077b160f8e12e1b7de7"><li><code class="notion-inline-code">limit</code> 达到后是抛异常还是优雅地结束？</li></ul><div class="notion-text notion-block-395cdaa272b68051910ed5d171a5ab47">说实话，有些细节我一开始真没想清楚。逐一回答后，基线锁定，AI 直接把任务切成了 7 组共 27 个任务。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b680399e1fd82610d77a81" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart TD
    G1[Group 1&lt;br/&gt;HugeGraphClient 重构&lt;br/&gt;7 任务] --&gt; G2[Group 2&lt;br/&gt;Source 配置类&lt;br/&gt;2 任务]
    G2 --&gt; G3[Group 3&lt;br/&gt;Source 核心&lt;br/&gt;7 任务]
    G3 --&gt; G4[Group 4&lt;br/&gt;Factory+SPI&lt;br/&gt;4 任务]
    G4 --&gt; G5[Group 5&lt;br/&gt;Schema 推断&lt;br/&gt;2 任务]
    G5 --&gt; G6[Group 6&lt;br/&gt;错误处理&lt;br/&gt;2 任务]
    G6 --&gt; G7[Group 7&lt;br/&gt;测试&lt;br/&gt;5 任务]
    style G1 fill:#e3f2fd,stroke:#1976d2
    style G3 fill:#fff3e0,stroke:#f57c00
    style G7 fill:#e8f5e9,stroke:#388e3c</code></pre><div class="notion-text notion-block-395cdaa272b680bea4fff55153ffbffb">接下来 AI 严格按照 TDD 推进。第一版提交时，21 个单元测试一次通过，<b>1814 行</b>新增代码，干净利落。</div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b6803e80feec36842a1040" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">sequenceDiagram
    participant Reader as SourceReader
    participant Client as HugeGraphClient
    participant HG as HugeGraph 服务端
    Reader-&gt;&gt;Client: listVertices(label, offset, limit)
    Client-&gt;&gt;HG: GET /gremlin or REST 分页
    HG--&gt;&gt;Client: Vertex/Edge 列表
    Client--&gt;&gt;Reader: List&lt;Vertex/Edge&gt;
    Reader-&gt;&gt;Reader: 映射为 SeaTunnelRow&lt;br/&gt;（id/label/属性字段）
    Reader-&gt;&gt;Reader: properties 过滤 + limit 检查
    alt 达到 limit
        Reader--&gt;&gt;Engine: signalNoMoreElement()
    else 还有数据
        Reader-&gt;&gt;Client: offset += page_size（下一轮）
    end</code></pre><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-395cdaa272b680eab1c8c1de847d683f" data-id="395cdaa272b680eab1c8c1de847d683f"><span><div id="395cdaa272b680eab1c8c1de847d683f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680eab1c8c1de847d683f" title="但是，别高兴得太早。"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">但是，别高兴得太早。</span></span></h4><div class="notion-text notion-block-395cdaa272b680238bdcf3e946deee40">AI 的自动化验证全绿，但后续还是暴露了三个问题：</div><ol start="1" class="notion-list notion-list-numbered notion-block-395cdaa272b68052a357f3dd9e5d7b6b" style="list-style-type:decimal"><li><b>schema 推断的运行时类型对不齐</b>，属性单值/集合处理出错。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-395cdaa272b680ef81e1e4b6c6ff806d" style="list-style-type:decimal"><li><b>DATE 转换没用 UTC</b>，时区导致数据偏移。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-395cdaa272b680338d32c5d0c2151c1f" style="list-style-type:decimal"><li><b>测试类命名不符合 CI 检查规则</b>，被 CI 拦下。</li></ol><div class="notion-text notion-block-395cdaa272b6809191e8c1ffed0561e0"><b>这也印证了那条铁律：AI 的测试只验代码逻辑，验不了业务真实场景和项目级约束。该手动测的，该过 CI 的，一步都省不了。</b></div><pre class="notion-code language-mermaid notion-code-id-395cdaa272b68083a5fff2747f4cc96b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-mermaid">flowchart LR
    subgraph 量化
        A1[27 个任务&lt;br/&gt;全部完成]
        A2[1814 行代码&lt;br/&gt;13 个文件]
        A3[21 单测&lt;br/&gt;0 失败]
        A4[4.8/5.0&lt;br/&gt;闭环评分]
    end
    subgraph 收益
        B1[成本下降 80%+&lt;br/&gt;proxy 路由]
        B2[向后兼容&lt;br/&gt;零破坏]
        B3[文档可追溯&lt;br/&gt;openspec 归档]
    end
    量化 --&gt; 收益
    style 量化 fill:#e3f2fd,stroke:#1976d2
    style 收益 fill:#e8f5e9,stroke:#388e3c</code></pre><hr class="notion-hr notion-block-395cdaa272b6805886c5fa3e9cb17e13"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-395cdaa272b680409a7fcdcb344b787c" data-id="395cdaa272b680409a7fcdcb344b787c"><span><div id="395cdaa272b680409a7fcdcb344b787c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b680409a7fcdcb344b787c" title="踩坑吐血换来的四条铁律"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">踩坑吐血换来的四条铁律</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-395cdaa272b68003801fc7af1750b46e" style="list-style-type:decimal"><li><b>AI 测试全绿 ≠ 功能正确</b>：时区、CI 规则这类项目级坑，AI 根本感知不到，必须人工兜底。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-395cdaa272b680f08f10d93f0d819a50" style="list-style-type:decimal"><li><b>向后兼容是底线</b>：重构共享类时，旧 API 必须打 <code class="notion-inline-code">@Deprecated</code> 标签并委托，不然会悄悄搞崩老功能。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-395cdaa272b6808088a5e4713fe52181" style="list-style-type:decimal"><li><b>前期偷懒，后期还债</b>：schema 推断的 cardinality 问题，就是因为 explore 阶段没问清楚，结果硬生生返工了一次。</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-395cdaa272b6803eb51fd286305cccec" style="list-style-type:decimal"><li><b>改需求必须回退改文档</b>：哪怕只改一个字段名，也要走 <code class="notion-inline-code">/opsx:explore</code> 流程，保证可追溯。</li></ol><hr class="notion-hr notion-block-395cdaa272b680708f55c377708bf8ef"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-395cdaa272b6802dbc66ea45078226da" data-id="395cdaa272b6802dbc66ea45078226da"><span><div id="395cdaa272b6802dbc66ea45078226da" class="notion-header-anchor"></div><a class="notion-hash-link" href="#395cdaa272b6802dbc66ea45078226da" title="写在最后"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">写在最后</span></span></h3><div class="notion-text notion-block-395cdaa272b680a1b48ec7e1f3f81ffb">归到底，这套 AI 原生开发工作流的精髓就在于三个“管住”：</div><ul class="notion-list notion-list-disc notion-block-395cdaa272b6808a8240cfa6dc411555"><li>用 <b>OpenSpec</b> 管住需求和设计</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b68053b63fe84bda8accda"><li>用 <b>SuperPower</b> 管住执行和质量</li></ul><ul class="notion-list notion-list-disc notion-block-395cdaa272b680f68b0cdf26e751cde7"><li>用 <b>proxy</b> 管住钱包</li></ul><div class="notion-text notion-block-395cdaa272b6808dbbbad4f1943b51ec">AI 的能力再强，它也只是个算力极高的执行者，真正决定项目成败的，还是制定规则、把控方向的人。这套流程的本质，就是把你从一个手忙脚乱复制粘贴的“提示词工程师”，变成一个运筹帷幄的架构师和项目经理。</div><div class="notion-text notion-block-395cdaa272b68048b196dbc912465c61"><b>未来，不是 AI 取代我们，而是会用 AI 的人，把不会用 AI 的人卷出局。</b></div><div class="notion-blank notion-block-395cdaa272b68093a54dc40797a4bb40"> </div><div class="notion-text notion-block-395cdaa272b680498631c1f1d75d66fb">附件：</div><div class="notion-file notion-block-395cdaa272b680a2bf9cc530f51e1355"><a class="notion-file-link" href="https://file.notion.com/f/f/3770ce44-c347-41ad-9bb8-35b98c17fd91/d781d5b3-1d07-486e-b084-967dd0bd5c15/openspec.zip?table=block&amp;id=395cdaa2-72b6-80a2-bf9c-c530f51e1355&amp;spaceId=3770ce44-c347-41ad-9bb8-35b98c17fd91&amp;expirationTimestamp=1793577600000&amp;signature=Ov01gLyUV-f-cR3tr_hZ9O2gFT3ZVx-OGQCZfh7aB1s" target="_blank" rel="noopener noreferrer"><svg class="notion-file-icon" viewBox="0 0 30 30"><path d="M22,8v12c0,3.866-3.134,7-7,7s-7-3.134-7-7V8c0-2.762,2.238-5,5-5s5,2.238,5,5v12c0,1.657-1.343,3-3,3s-3-1.343-3-3V8h-2v12c0,2.762,2.238,5,5,5s5-2.238,5-5V8c0-3.866-3.134-7-7-7S6,4.134,6,8v12c0,4.971,4.029,9,9,9s9-4.029,9-9V8H22z"></path></svg><div class="notion-file-info"><div class="notion-file-title">openspec.zip</div><div class="notion-file-size">19.7 KiB</div></div></a></div><div class="notion-blank notion-block-395cdaa272b6805bbd3ef487f1a64322"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vibe Coding开发前的 7 个关键步骤]]></title>
            <link>https://hllqk.cn/article/vibe-coding-preparation</link>
            <guid>https://hllqk.cn/article/vibe-coding-preparation</guid>
            <pubDate>Thu, 16 Apr 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[第一步：把想法聊清楚 把你的想法完整地说出来。注意，是“完整地”,不 是"简洁地"。 比如你想做个记账工具，别只说“帮我做个记账 App"。你得说清楚: 为什么要做这个?现有的记账App哪里不满意? 核心功能是什么?记录收支?生成报表?设置…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-344cdaa272b680adab89d6d08f446137"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b6808c9f28e7f04c7ebf46" data-id="344cdaa272b6808c9f28e7f04c7ebf46"><span><div id="344cdaa272b6808c9f28e7f04c7ebf46" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b6808c9f28e7f04c7ebf46" title="第一步：把想法聊清楚"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第一步：把想法聊清楚</span></span></h2><div class="notion-text notion-block-344cdaa272b6806ea04ee65b9c86e876">把你的想法完整地说出来。注意，是“完整地”,不 是&quot;简洁地&quot;。</div><div class="notion-text notion-block-344cdaa272b680f6a1b9d0c36cc7a44c">比如你想做个记账工具，别只说“帮我做个记账 App&quot;。你得说清楚:</div><ul class="notion-list notion-list-disc notion-block-344cdaa272b680afb943eb6286f82e9f"><li><span class="notion-yellow">为什么要做这个?现有的记账App哪里不满意?</span></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680b184c0dfb8c432ac44"><li><span class="notion-yellow">核心功能是什么?记录收支?生成报表?设置预算?</span></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680de9663d43005d7191c"><li><span class="notion-yellow">谁会用这个工具?就你自己，还是想给朋友用?</span></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680809d7dd355be590a4a"><li><span class="notion-yellow">使用场景是什么?每天记一次，还是花钱就记?</span></li></ul><div class="notion-text notion-block-344cdaa272b680818b58c821272b8658">这个过程其实是在帮你自己理清思路。很多时候， 你以为自己想清楚了，真说出来才发现到处是模糊地带。</div><div class="notion-text notion-block-344cdaa272b680329aeffb56557a03a3">于是，第一步就是跟AI聊天，像跟朋友聊天一样，把脑子里的想法全倒出来，细节越多越好。</div><div class="notion-text notion-block-344cdaa272b68003b940d6bda3a7f666">填充下面这份prompt</div><pre class="notion-code language-markdown notion-code-id-344cdaa272b68062890bfc91eb751ea7" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">我想做一个[产品名称]
主要是为了解决[什么问题]
目标用户是[谁]
核心功能包括:
[功能一]
[功能二]
[功能三]
我希望它能 [达到什么效果]</code></pre><div class="notion-text notion-block-344cdaa272b680e3bce2cae7526716d1">然后继续和ai交流，知道ai达到你的理想型</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b680b78d2ccdaa9069a7fb" data-id="344cdaa272b680b78d2ccdaa9069a7fb"><span><div id="344cdaa272b680b78d2ccdaa9069a7fb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b680b78d2ccdaa9069a7fb" title="第二步：要一份 PRD"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第二步：要一份 PRD</span></span></h2><div class="notion-text notion-block-344cdaa272b680329400ef4e2d5f0d7c">聊完之后，别急着写代码。让AI帮你把刚才的对话整理成一份PRD，也就是产品需求文档。</div><div class="notion-text notion-block-344cdaa272b6803c8daefe1f9fefb607">直接说:<code class="notion-inline-code">帮我把刚才聊的内容整理成一份产品需求文档。并且写入PRD.md</code>  AI会给你输出一个结构化的文档</div><div class="notion-text notion-block-344cdaa272b68073b449c1ae827a03e7">然后，<b>认真读这份PRD</b>。</div><div class="notion-text notion-block-344cdaa272b680d6a54dfc83ebaae5f0">这是整个流程里最容易被跳过，但其实<span class="notion-red">最关键的一步</span>。逐条对照你的原始想法，看AI理解的跟你想的是不是一回事。</div><div class="notion-text notion-block-344cdaa272b68029993dc9c233a2be79"><b>发现不对的地方，现在就改。改PRD花5分钟，改代码可能要花5个小时。</b></div><div class="notion-text notion-block-344cdaa272b680c18b67fde3fe3c4eb5">把PRD当作你和AI之间的&quot;合同”，确保双方理解一致。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b68071b8dcd807f79204b9" data-id="344cdaa272b68071b8dcd807f79204b9"><span><div id="344cdaa272b68071b8dcd807f79204b9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b68071b8dcd807f79204b9" title="第三步：明确项目目标"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第三步：明确项目目标</span></span></h2><div class="notion-text notion-block-344cdaa272b68061aa31f977a7080972">做什么搞清楚了，接下来要想清楚：做到什么程度?</div><div class="notion-text notion-block-344cdaa272b680349823ea98877f0b19">这个问题直接决定了技术方案的选择。</div><div class="notion-text notion-block-344cdaa272b680419ea6fa9324b506b3">可以这样说:</div><pre class="notion-code language-markdown notion-code-id-344cdaa272b680f2a47bf05dcfb9fe9d" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">这个项目主要是我自己用，目标是低成本实现，

在本地运行就可以，不需要考虑多人使用的情况</code></pre><div class="notion-text notion-block-344cdaa272b680af93a9ca6874081e7c">或者：</div><pre class="notion-code language-markdown notion-code-id-344cdaa272b6801b8743fce224126f56" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">这个项目我想做成可以release的产品，

需要考虑用户数据安全、性能优化和未来扩展性。</code></pre><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b68064a2d5f86e42f3d3e9" data-id="344cdaa272b68064a2d5f86e42f3d3e9"><span><div id="344cdaa272b68064a2d5f86e42f3d3e9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b68064a2d5f86e42f3d3e9" title="第四步：确定技术"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第四步：确定技术</span></span></h2><div class="notion-text notion-block-344cdaa272b6800eb33ed36f0483a6c9">目标明确了，就可以让AI推荐技术栈了。</div><div class="notion-text notion-block-344cdaa272b680dfac08c23e7a9822a5">一个实用的prompt模板：</div><pre class="notion-code language-markdown notion-code-id-344cdaa272b680d7a4e8ff79547759bb" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">帮我根据上面内容，推荐合适的技术栈，并说明为什么这样选择。  </code></pre><div class="notion-text notion-block-344cdaa272b680faa215e758eec52605">AI会告诉你前端用什么框架、后端用什么语言、 数据库选什么、需要哪些工具库。</div><div class="notion-text notion-block-344cdaa272b6808384fafb9c3b380866">比如做个简单的网页工具，React+Node.js+ SQLite就够了。不需要上Kubernetes、微服务这些大杀器。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b68046b4fdde529c7151cc" data-id="344cdaa272b68046b4fdde529c7151cc"><span><div id="344cdaa272b68046b4fdde529c7151cc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b68046b4fdde529c7151cc" title="第五步：要一份架构设计"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第五步：要一份架构设计</span></span></h2><div class="notion-text notion-block-344cdaa272b68031be9be2df6722cb13">技术栈定了，接下来要一份系统架构设计。</div><div class="notion-text notion-block-344cdaa272b680d19b5cc0a0d2b51b4f"><b>可以这样问AI：</b></div><pre class="notion-code language-markdown notion-code-id-344cdaa272b680d5bfa7f2068ce30511" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">根据这个PRD，请为我设计一个适合个人项目的轻量架构，包括:

- 项目目录结构
- 核心模块划分
- 数据模型设计
- 代码规范建议

我希望这个项目：[本地运行/可部署/需要扩展性]
然后把上面架构设计写入ARCHITECTURE.md</code></pre><div class="notion-text notion-block-344cdaa272b680c8848bcd5b63c38508"><b>AI会给你输出完整的目录结构和划分</b></div><pre class="notion-code language-markdown notion-code-id-344cdaa272b6803b9c90e53398a7597c" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">|project/  
||—————src/  
||  |—————components/ #UI组件
||  |—————services/ #业务逻辑
||  |—————utils/  #工具函数
||  |—————config/  #配置文件
||—————public/  
||—————tests/
|—————README.md</code></pre><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b68096b3d5d06234268083" data-id="344cdaa272b68096b3d5d06234268083"><span><div id="344cdaa272b68096b3d5d06234268083" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b68096b3d5d06234268083" title="第六步：整理项目文档"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第六步：整理项目文档</span></span></h2><div class="notion-text notion-block-344cdaa272b680fdbd7cee03cf226a94">现在你手上有了PRD、技术栈、架构设计，接下来要把这些内容整理成文档，保存在项目里。</div><div class="notion-text notion-block-344cdaa272b680779b9ff63252292800"><b>建议创建这几个文件: </b></div><div class="notion-text notion-block-344cdaa272b680338ca2de24879fd62e">和AI沟通进行创建README.md</div><pre class="notion-code language-markdown notion-code-id-344cdaa272b6807bbdd8d24a90066b8d" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">帮我结合上面内容创建一个README.md
要求：
- 项目简介：这个项目是干什么的
- 如何运行：怎么把项目跑起来
- 技术栈：用了哪些技术
项目内容PRD.md和ARCHITECTURE.md和README.md
都要跟随着项目文件更改进行更新！</code></pre><div class="notion-text notion-block-344cdaa272b680edb032efd6348e96d9">下面文件AI已经创建了</div><div class="notion-text notion-block-344cdaa272b6807f81f1ea7bf037058f"><s><span class="notion-yellow">PRD.md</span></s></div><ul class="notion-list notion-list-disc notion-block-344cdaa272b680a288b7e78398348ba8"><li><s><span class="notion-yellow">产品定位</span></s></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b6805abe20f025ecc22d84"><li><s><span class="notion-yellow">核心功能列表</span></s></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680108b2cc30e32fa4566"><li><s><span class="notion-yellow">用户使用流程</span></s></li></ul><div class="notion-text notion-block-344cdaa272b680a4b094e46988ad6b93"><s><span class="notion-yellow">ARCHITECTURE.md</span></s></div><ul class="notion-list notion-list-disc notion-block-344cdaa272b68015b7c3d95cf8f5024a"><li><s><span class="notion-yellow">技术栈选择及原因</span></s></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b68071bc2df2faaa36edf9"><li><s><span class="notion-yellow">项目目录结构</span></s></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680a698a7ef1995c2765e"><li><s><span class="notion-yellow">核心模块说明</span></s></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680f6999ad2802e0322ac"><li><s><span class="notion-yellow">数据模型设计</span></s></li></ul><ul class="notion-list notion-list-disc notion-block-344cdaa272b680ee8bdcd73b6e6c69f6"><li><s><span class="notion-yellow">代码规范</span></s></li></ul><div class="notion-text notion-block-344cdaa272b6804880a7fec5069643bf">只要使用 <b>Cursor/Claude Code/Trae </b>等工具，它能直接访问你的项目文件夹，会自动读取项目根目录的文档。</div><div class="notion-text notion-block-344cdaa272b680a0ba58d5c002e8d62c">于是每次你和AI对话，它都已经“知道”了你的项目架构和规范。不需要反复上传文档。</div><div class="notion-text notion-block-344cdaa272b68018a28fcb238571578c"><b>最后一个提醒:文档要跟着项目更新。</b></div><div class="notion-text notion-block-344cdaa272b68078a5d4efb340300b3b">如果你调整了架构、改变了某个设计，记得让AI同步更新文档（手动更新）。</div><div class="notion-text notion-block-344cdaa272b680e1a99ee32c2f434abb">否则AI会按照过时的文档理解项目，导致新代码跟现有代码对不上。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b6809c9b30fbe6fe9e13d1" data-id="344cdaa272b6809c9b30fbe6fe9e13d1"><span><div id="344cdaa272b6809c9b30fbe6fe9e13d1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b6809c9b30fbe6fe9e13d1" title="第七步:设置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>第七步:设置</b></span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-344cdaa272b6807591e8fd4d1b685019" data-id="344cdaa272b6807591e8fd4d1b685019"><span><div id="344cdaa272b6807591e8fd4d1b685019" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b6807591e8fd4d1b685019" title="Git 版本管理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Git 版本管理</span></span></h3><div class="notion-text notion-block-344cdaa272b680c7b501e79c76bfd988">在写第一行代码之前，最后一件必须做的事：设置 Git版本管理。</div><div class="notion-text notion-block-344cdaa272b680009a94c531ccae2884"><b>Git是做什么的?</b></div><div class="notion-text notion-block-344cdaa272b68029bf05c778fea1d573">简单说，就是给你的项目创建“存档点”。就像玩游戏时的存档系统，每完成一个阶段就存个档，后面打不过了可以读档重来。</div><h5 class="notion-h notion-h4 notion-h-indent-2 notion-block-344cdaa272b680b3abc9e8c3ff553c88" data-id="344cdaa272b680b3abc9e8c3ff553c88"><span><div id="344cdaa272b680b3abc9e8c3ff553c88" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b680b3abc9e8c3ff553c88" title="Git Skill"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Git Skill</span></span></h5><div class="notion-text notion-block-344cdaa272b680749b5cc5823b2f8c06">这里我们可以使用git相关的skill实现ai自动生成commit，也就是实现自动存档的功能</div><div class="notion-text notion-block-344cdaa272b6804aae52fe6a68296142">比如下面这个Skill:</div><pre class="notion-code language-markdown notion-code-id-344cdaa272b68048a71ef6d7ac9c3788" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">---
name: commit-by-feature
description: Commits code changes by feature with a standardized multi-line commit message. Runs when the user makes code changes and asks to commit, or when the user explicitly requests a commit. Amends the last unpushed commit message when the user switches to another feature and has unpushed commits.
---

# 按功能提交（Commit by Feature）

在用户完成代码修改并要求提交、或用户明确要求提交时，按「功能」进行 git commit，并采用下方固定格式的 commit message。若用户在一个功能已 commit 后又在做另一功能的修改，且存在未 push 的 commit，则对**最近一次未 push 的 commit** 使用 `git commit --amend` 修改其 message，使其描述新功能。

## 何时执行

- 用户说「帮我 commit」「提交一下」「把更改 commit」等，或
- 用户完成一批代码修改后要求提交，或
- 用户说「修改刚才的 commit 说明」「改一下上次的 commit message」等（则执行 amend 流程）。

## Commit Message 格式（必须严格遵循）

整段作为 **commit message 正文**（不要用 `-m` 只写一行，用 `-m &quot;第一行&quot; -m &quot;正文...&quot;` 或写进文件再 `git commit -F`）。格式如下：

```
修改描述： [feat] 或 [fix] 或 [refactor] + 一句话概括（如：精简视频裁剪页面与回灌页面：在视频裁剪页移除xxx；在回灌页将设备 IP 默认改为 0.0.0.0。）
影响分析： all
是否自测： 是
自测内容： ui（或 doc / 接口 / 改动对应的文件夹路径 /等，按实际改动的自测范围填写）
测试建议： all
代码审查： 刘江涛
NOTE： all
项目编号： all
```

- **修改描述**：首行用 `[feat]` / `[fix]` / `[refactor]` 等前缀，后接简洁的功能/修复说明，多块功能用分号或「；」分隔。
- **影响分析 / 测试建议 / NOTE / 项目编号**：无特殊要求时填 `all`。
- **是否自测**：一般为「是」。
- **自测内容**：根据改动填 `ui`、`doc`、`接口`、`导出` 等。
- **代码审查**：固定为「刘江涛」。

## 执行步骤

### 1. 仅修改上一次 commit 的 message（amend）

当用户明确说「改 commit 说明」「修改上次的 commit」「amend」且当前有未 push 的 commit 时：

1. 运行 `git log -1 --oneline` 确认最近一次 commit。
2. 根据**当前工作区+暂存区的最新改动**（或用户口述）归纳「修改描述」。
3. 按上面格式写出完整 commit message。
4. 执行：`git commit --amend -m &quot;修改描述： ...&quot; -m &quot;影响分析： all&quot; -m &quot;是否自测： 是&quot; -m &quot;自测内容： ...&quot; -m &quot;测试建议： all&quot; -m &quot;代码审查： 封凯&quot; -m &quot;NOTE： all&quot; -m &quot;项目编号： all&quot;`
   或使用临时文件：`git commit --amend -F commit_msg.txt`（内容为上述多行）。
5. 告知用户已 amend 完成。

### 2. 按功能提交当前改动（新 commit）

当用户要求提交当前更改时：

1. **查看改动**：`git status`、`git diff`（及 `git diff --staged`）。根据修改的文件路径和 diff 内容判断属于哪一个或哪几个功能（例如：视频裁剪、回灌、帧头导出、日志分析、通用功能、系统设置等）。
2. **决定 commit 数量**：
   - 通常**一个功能一个 commit**；若改动明显属于同一功能，只生成一个 commit。
   - 若改动横跨多个互不相关的功能，可拆成多个 commit（先 add 第一批，commit；再 add 下一批，commit），每个 commit 的 message 都按本格式填写。
3. **撰写「修改描述」**：
   - 用 `[feat]` / `[fix]` / `[refactor]` 等开头。
   - 一句话概括该 commit 涉及的功能或修复，多点时用分号分隔。
   - 仅描述本 commit 包含的改动，不要写未改动的功能。
4. **填写其余字段**：影响分析、是否自测、自测内容、测试建议、代码审查、NOTE、项目编号按格式填好。
5. **执行提交**：
   - 先 `git add` 本功能相关文件，再 `git commit`，message 使用上述多行格式（可用多个 `-m` 或 `-F` 文件）。
   - 若拆多个 commit，重复 add + commit，每个 commit 对应一个功能的描述。

## 示例

**单功能单 commit：**

修改描述： [feat] 帧头导出支持 MP4 视频并修复导出 0 帧问题；导出服务 JSON 改为使用 orjson。
影响分析： all
是否自测： 是
自测内容： 导出、MP4 视频
测试建议： all
代码审查： 刘江涛
NOTE： all
项目编号： all

**Amend 场景：**
用户已为「视频裁剪精简」commit 过一次，未 push，接着又做了「回灌页设备 IP 默认 0.0.0.0」的修改并希望把这两块合进同一个 commit 说明。则对最近一次 commit 执行 `git commit --amend`，将 message 改为同时包含「视频裁剪页精简」和「回灌页设备 IP 默认与选网卡自动填充」的修改描述。

## 注意事项

- 不要用单行 `-m &quot;...&quot;` 把多行格式挤成一行；用多行 message 或 `-F` 文件。
- 若仓库有 `.gitignore` 或未跟踪文件，只 add 用户明确要提交的或与当前功能明显相关的文件。
- 不执行 `git push`，除非用户明确要求推送。
</code></pre><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b680739fdedf38b5ca92a6" data-id="344cdaa272b680739fdedf38b5ca92a6"><span><div id="344cdaa272b680739fdedf38b5ca92a6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b680739fdedf38b5ca92a6" title="从准备到开发"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">从准备到开发</span></span></h2><div class="notion-text notion-block-344cdaa272b680249208cb55199c21ff">准备工作做完，就可以开发了。但记住几个原则:</div><div class="notion-text notion-block-344cdaa272b6808e9114d19f7ffba765"><span class="notion-yellow_background">1.先做MVP(最小可用版本)</span></div><div class="notion-text notion-block-344cdaa272b68030bae1f2ecfb31d56a">不要一开始就追求完美。先做一个能跑、能用、实现核心功能的版本。后面再慢慢优化。</div><div class="notion-text notion-block-344cdaa272b680ae845ad57c5dbbe7bd">比如记账工具，第一版只要能记录收支、能查看列表就够了。报表、预算、数据分析这些可以后面加。</div><div class="notion-text notion-block-344cdaa272b680cabed3c3fda664be31"><span class="notion-yellow_background">2.小步迭代</span></div><div class="notion-text notion-block-344cdaa272b6808aa6aff4f342f1eb6a">每次只做一个功能，做完测试没问题，再做下一 个。</div><div class="notion-text notion-block-344cdaa272b6803d8c8bc1143d6db744">别一口气让AI写一大堆代码，那样出问题很难定位。</div><div class="notion-text notion-block-344cdaa272b680d7ab74c253830f5360"><span class="notion-yellow_background">3.勤 commit</span></div><div class="notion-text notion-block-344cdaa272b680828547f6be304b7410">每完成一个小功能就commit一次。这是我们的安全网，别省。</div><div class="notion-text notion-block-344cdaa272b680958745e1a84c1793fa"><span class="notion-yellow_background">4. 验证AI的代码</span></div><div class="notion-text notion-block-344cdaa272b680389da5d66e562604b6">AI写的代码要自己测试。不要盲目相信，也不要过度怀疑,测试是最好的验证方式。</div><div class="notion-text notion-block-344cdaa272b680898fc4f2b916cba7b3"><span class="notion-yellow_background">5.完成项目后沉淀技术文档</span></div><div class="notion-text notion-block-344cdaa272b680e6a1d3fd188be2dab4">每次写完一个项目，沉淀一个技术文档和一些可复用的Skill，方便后面项目的开发和技术回顾</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-344cdaa272b680afba8cec481ce67391" data-id="344cdaa272b680afba8cec481ce67391"><span><div id="344cdaa272b680afba8cec481ce67391" class="notion-header-anchor"></div><a class="notion-hash-link" href="#344cdaa272b680afba8cec481ce67391" title="如果是完全零基础的新手，建议:"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">如果是完全零基础的新手，建议:</span></span></h2><div class="notion-text notion-block-344cdaa272b680ea968defa2285b62ce">从简单项目开始。</div><div class="notion-text notion-block-344cdaa272b6802a9d7cda19fa5e5cec">别一上来就做复杂的。先做个待办事项管理、简易记账本、个人博客这种简单项目。</div><div class="notion-text notion-block-344cdaa272b680b286e1d04a53c8c3d9">目的不是做出多牛的产品,而是把整个流程走一遍，体会每个步骤的作用。  做完一个项目,流程就刻在脑子里了，也有了 Vibe Coding的感觉。</div><div class="notion-text notion-block-344cdaa272b680f3bf1ec9110874f4dd">别害怕出错。</div><div class="notion-text notion-block-344cdaa272b6800384d6c42b2a1590e6">有Git在,出错了就回滚，没什么大不了的。多试几次，或者选择更厉害的模型。</div><div class="notion-text notion-block-344cdaa272b68024b8e2cca515184364"><b>附上前端美化Skill:</b></div><a class="notion-external notion-external-block notion-row notion-block-344cdaa272b680e0bfbcc1edd5a80674" href="https://github.com/anthropics/skills/blob/main/skills/frontend-design/SKILL.md" target="_blank" rel="noopener noreferrer"><div class="notion-external-image"><svg viewBox="0 0 260 260"><g><path d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z" fill="#161614"></path></g></svg></div><div class="notion-external-description"><div class="notion-external-title">SKILL.md</div><div class="notion-external-block-desc">anthropics</div></div></a><div class="notion-text notion-block-344cdaa272b680f69a57c446224c3890"><b>和每次变更的流水线(CHANGELOG.md)放在项目根目录就可以了，然后告诉AI你添加了变更流水线</b></div><pre class="notion-code language-markdown notion-code-id-344cdaa272b68027a189fcf67a086126" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown"># Changelog

本文件用于记录每次版本发布的“代码改动 + 文档改动”，并作为固定发布流程的执行清单。

遵循规范：
- 版本格式：`[主版本.次版本.修订]`，例如 `v1.0.0`
- 日期格式：`YYYY-MM-DD`
- 发布原则：没有文档更新说明的功能改动，不应发布

## 发布流程（固定）
1. 完成代码改动并本地验证（功能、接口、构建）。
2. 更新文档：至少检查 `PRD.md`、`ARCHITECTURE.md`、`README.md` 是否需要变更。
3. 填写本文件对应版本条目，明确“代码改动 + 文档改动”。
4. 复核发布清单，确认通过后再打版本标签/归档。

## 发布清单（每次发布必查）
- [ ] 代码改动已完成并自测通过
- [ ] 需求变化已同步到 `PRD.md`（如适用）
- [ ] 架构变化已同步到 `ARCHITECTURE.md`（如适用）
- [ ] 运行方式/依赖变化已同步到 `README.md`（如适用）
- [ ] 本次版本记录已写入 `CHANGELOG.md`

---

## [Unreleased]
### Added
- 待补充

### Changed
- 待补充

### Fixed
- 待补充

### Docs
- 待补充（必须填写文档变更；若无，请写“无”并说明原因）

### Release Checklist
- [ ] 代码改动已完成并验证
- [ ] 文档改动已同步
- [ ] 风险项已评估

---

## [v1.0.0] - 2026-04-16
### Added
- 初始化项目文档体系：`PRD.md`、`ARCHITECTURE.md`、`README.md`、`CHANGELOG.md`

### Changed
- 建立个人本地低成本架构基线，明确可扩展路线

### Fixed
- 无

### Docs
- 新增 `README.md`，补充项目简介、运行方式、技术栈
- 更新 `PRD.md`，补充文档联动维护要求
- 更新 `ARCHITECTURE.md`，补充文档联动更新约定

### Release Checklist
- [x] 代码改动已完成并验证
- [x] 文档改动已同步
- [x] 风险项已评估
</code></pre><div class="notion-text notion-block-344cdaa272b680c8b435ea0bfb4d594c"><span class="notion-inline-underscore">作者：hllqk</span></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[实用工具推荐合集]]></title>
            <link>https://hllqk.cn/article/useful-tools</link>
            <guid>https://hllqk.cn/article/useful-tools</guid>
            <pubDate>Tue, 03 Feb 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[💾 软件推荐 Macos必备：https://github.com/runjuu/InputSourcePro 🔧 编程开发 Visual Studio Code]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-2fccdaa272b6801e885ccaf4de3a7bf8"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-blue_background_co notion-block-3640363c12314ee298d007053fe7552b"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="🎯">🎯</span></div><div class="notion-callout-text"><div class="notion-text notion-block-86d45a597615452f8ff4b482c705a1db">这里汇集了各类优质的<b>软件、网站、插件和扩展</b>推荐，帮助你提升工作效率和使用体验！</div></div></div><hr class="notion-hr notion-block-6ef8bae7d1d9490d9bc7c7276f48708c"/><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-69e501d66f484dc69374fe409b03185c" data-id="69e501d66f484dc69374fe409b03185c"><span><div id="69e501d66f484dc69374fe409b03185c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#69e501d66f484dc69374fe409b03185c" title="💾 软件推荐"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">💾 软件推荐</span></span></h3><div class="notion-text notion-block-33fcdaa272b680578f88f20dc7850e1b">Macos必备：<a class="notion-link" href="https://github.com/runjuu/InputSourcePro" target="_blank" rel="noopener noreferrer">https://github.com/runjuu/InputSourcePro</a></div><div class="notion-blank notion-block-33fcdaa272b6802b8570db85a236b5ae"> </div><div class="notion-blank notion-block-33fcdaa272b6800296aded7497f0ded7"> </div><h4 class="notion-h notion-h3 notion-blue notion-h-indent-1 notion-block-a4478b4cc30d453d80e7ab77169629f9" data-id="a4478b4cc30d453d80e7ab77169629f9"><span><div id="a4478b4cc30d453d80e7ab77169629f9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a4478b4cc30d453d80e7ab77169629f9" title="🔧 编程开发"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🔧 编程开发</span></span></h4><details class="notion-toggle notion-block-a1379dafe5b84be08b2a072dfa118d7c"><summary><b>Visual Studio Code</b></summary><div><div class="notion-text notion-block-df883b6ff2e04812bbd23cc455b90cff">轻量级但功能强大的代码编辑器，支持多种编程语言和丰富的插件扩展</div><div class="notion-text notion-block-7b39d77c3e8a43ffae2bd1f6c95bc5dd"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-1a75bdd4f27d4c3b92c5f408c828a195"><summary><b>PyCharm</b></summary><div><div class="notion-text notion-block-d1b6b4d2ef8740b7becba36da980cde6">专业的Python IDE，提供智能代码补全、调试和测试工具</div><div class="notion-text notion-block-4af2d8c12288455c846b0e06868e0830"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-3e21e8a7dfcc4534a293314fa511498b"><summary><b>IntelliJ IDEA</b></summary><div><div class="notion-text notion-block-75368ab2552149e88db70f992b6ba0a9">强大的Java开发工具，支持多种JVM语言和框架</div><div class="notion-text notion-block-7e80c26c1b3a4568a128c5023651fed1"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-f34a6863065443778ce1b1a23bbac4b5"><summary><b>Git / Git Bash</b></summary><div><div class="notion-text notion-block-ef240fb66f3c4d54b1dc0a0cb70ee885">分布式版本控制系统，用于代码管理和协作开发</div><div class="notion-text notion-block-4662f0e4d2d04dd7a1d95b12f9a89c6a"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-e8a6b47fe0dc478aab06f82378d204be"><summary><b>Docker</b></summary><div><div class="notion-text notion-block-784ac6147881406091c8699801e1fbb9">容器化平台，简化应用部署和环境配置</div><div class="notion-text notion-block-bdb9bbfc039041168d80bb4120820321"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-4bf6683340e641b8bad03324bc0f5ecc"><summary><b>Apifox / Postman</b></summary><div><div class="notion-text notion-block-01e459dd70b5463db517469b3e8288a2">API开发和测试工具，支持REST、GraphQL等</div><div class="notion-text notion-block-53f9fe253adc428d85d3b16fa433115c"><em>适用系统：Windows/Mac/Linux</em></div></div></details><h4 class="notion-h notion-h3 notion-purple notion-h-indent-1 notion-block-0eb5e3dd992f4bd587e2ccd974e6a527" data-id="0eb5e3dd992f4bd587e2ccd974e6a527"><span><div id="0eb5e3dd992f4bd587e2ccd974e6a527" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0eb5e3dd992f4bd587e2ccd974e6a527" title="🤖 AI编程助手"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🤖 AI编程助手</span></span></h4><details class="notion-toggle notion-block-1b655206c94b46c0a3cb1c46ec25a16a"><summary><b>Cursor</b></summary><div><div class="notion-text notion-block-602d28f655774fbb8b49750d3e3f9f1d">AI驱动的代码编辑器，智能代码生成和补全</div><div class="notion-text notion-block-049391ee3d6a41e38e12057b7e8505ab"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-b266417f4e514778ae6a5a6842ccbc9e"><summary><b>Kiro / Codex</b></summary><div><div class="notion-text notion-block-0df84c0802d74edfb86c8dcebd321be3">AI辅助编程工具，提升代码编写效率</div><div class="notion-text notion-block-6ea7c272f19a40088bbce40926ebcfa8"><em>适用系统：Windows</em></div></div></details><h4 class="notion-h notion-h3 notion-orange notion-h-indent-1 notion-block-f6c25d5e52b845daa9e17c0ec137e5b7" data-id="f6c25d5e52b845daa9e17c0ec137e5b7"><span><div id="f6c25d5e52b845daa9e17c0ec137e5b7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f6c25d5e52b845daa9e17c0ec137e5b7" title="⚡ 效率工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">⚡ 效率工具</span></span></h4><details class="notion-toggle notion-block-7a748fdedc754e6981376716bf820fde"><summary><b>uTools</b></summary><div><div class="notion-text notion-block-cceee70bb9bf4b12bbdcdbb5118f7908">强大的桌面快速启动和搜索工具，支持丰富的插件扩展</div><div class="notion-text notion-block-760d92d7cc154925bc307bb748714d7f"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-7181c5be52c34090bdff99eee1c2bcc6"><summary><b>Everything</b></summary><div><div class="notion-text notion-block-3043ae9bb8954480bd644c7648848c67">极速文件搜索工具，实时索引电脑文件</div><div class="notion-text notion-block-281b4d979e344cfe86ab5a97f732631e"><em>适用系统：Windows</em></div></div></details><details class="notion-toggle notion-block-6453ac36ec5443f880161d2c3569506f"><summary><b>Snipaste</b></summary><div><div class="notion-text notion-block-79ae91905649499e86bda0ca6e79d256">强大的截图和贴图工具，支持图片标注、取色和屏幕贴图功能</div><div class="notion-text notion-block-d13bf3cec1dc49c2b6919a38e33de9d2"><em>适用系统：Windows/Mac</em></div></div></details><h4 class="notion-h notion-h3 notion-teal notion-h-indent-1 notion-block-ecb07834a4954ba0ab432e1285c02a20" data-id="ecb07834a4954ba0ab432e1285c02a20"><span><div id="ecb07834a4954ba0ab432e1285c02a20" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ecb07834a4954ba0ab432e1285c02a20" title="📝 笔记与文档"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 笔记与文档</span></span></h4><details class="notion-toggle notion-block-5f48dcedd2d246e9ac931341dac53de9"><summary><b>Notion</b></summary><div><div class="notion-text notion-block-3f0e3b186b454b2a98f6e243f9ad63b5">一体化工作空间，集笔记、文档、数据库和项目管理于一体</div><div class="notion-text notion-block-c5272168f0f245b2b51bd4fef42e42b7"><em>适用系统：Windows/Mac/Web</em></div></div></details><details class="notion-toggle notion-block-3214c0ee9d724d5cbb67e206a0c50151"><summary><b>Typora</b></summary><div><div class="notion-text notion-block-012aa10fb6c04ccd892b0cce2fb893cd">简洁优雅的Markdown编辑器，所见即所得</div><div class="notion-text notion-block-ca6be9a0b82848868435b7b48d72067a"><em>适用系统：Windows/Mac/Linux</em></div></div></details><h4 class="notion-h notion-h3 notion-yellow notion-h-indent-1 notion-block-2d27fc09a8ff427d87b7d7d881a6626f" data-id="2d27fc09a8ff427d87b7d7d881a6626f"><span><div id="2d27fc09a8ff427d87b7d7d881a6626f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2d27fc09a8ff427d87b7d7d881a6626f" title="🛠️ 系统工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🛠️ 系统工具</span></span></h4><details class="notion-toggle notion-block-8cbcc8ed0b4148b1ad8fdc289534d18d"><summary><b>WinRAR / 7-Zip</b></summary><div><div class="notion-text notion-block-0ff11f7d55b04d749779171753e68d15">文件压缩和解压缩软件</div><div class="notion-text notion-block-77d5f638e779405187ccea6dc32d19e6"><em>适用系统：Windows</em></div></div></details><details class="notion-toggle notion-block-0c5540aa410d4bb29ace623768af253e"><summary><b>Geek Uninstaller</b></summary><div><div class="notion-text notion-block-2b1b90ef834445338a64e58d5523822d">轻量级软件卸载工具，可彻底清除软件残留文件和注册表</div><div class="notion-text notion-block-8148696e6373486894319378d25c7026"><em>适用系统：Windows</em></div></div></details><details class="notion-toggle notion-block-25db78e2c63a4849aa8aa1b227b9b975"><summary><b>WizTree</b></summary><div><div class="notion-text notion-block-b0ce44f1865341fbac9b747ba7581e7e">快速扫描和可视化硬盘空间使用情况，帮助查找占用空间的大文件</div><div class="notion-text notion-block-7b7a5311e4b243c58ee39656b62b6200"><em>适用系统：Windows</em></div></div></details><details class="notion-toggle notion-block-65ad50e4d67847fe86bf4d9a9af5ca20"><summary><b>驱动精灵</b></summary><div><div class="notion-text notion-block-cf7cfab346b0490097401a035cc08335">驱动程序管理和更新工具，自动检测和安装硬件驱动</div><div class="notion-text notion-block-b70e93768b4d4fdfb1d8b718fbc08e17"><em>适用系统：Windows</em></div></div></details><h4 class="notion-h notion-h3 notion-blue notion-h-indent-1 notion-block-95599bcc81e64039acff2af2b6ef7c19" data-id="95599bcc81e64039acff2af2b6ef7c19"><span><div id="95599bcc81e64039acff2af2b6ef7c19" class="notion-header-anchor"></div><a class="notion-hash-link" href="#95599bcc81e64039acff2af2b6ef7c19" title="🌐 网络与终端"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🌐 网络与终端</span></span></h4><details class="notion-toggle notion-block-16d3d605a2c1491690df18d5d5b40e21"><summary><b>Chrome</b></summary><div><div class="notion-text notion-block-4d52a4993dbd44169244ce6425ae2482">快速、安全的浏览器，拥有丰富的开发者工具和扩展</div><div class="notion-text notion-block-6d539e3d8f394941af01a8a7fbc5aebf"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-71e31186f50744f8b88093918f406107"><summary><b>FlClash</b></summary><div><div class="notion-text notion-block-dbfaf57eaa6b4a33aa77e82b5785a1e7">基于Clash的代理工具，支持多种代理协议</div><div class="notion-text notion-block-40574c0c275749e89bab503dbec3d9ea"><em>适用系统：Windows/Mac/Linux</em></div></div></details><details class="notion-toggle notion-block-4a1ca2705e6c4ad68012f3f28770230f"><summary><b>WindTerm</b></summary><div><div class="notion-text notion-block-f6b33843834e4021927f739dcab41863">免费的SSH/Telnet/Serial/Shell终端工具，速度快且功能强大</div><div class="notion-text notion-block-5add4c8155584ab4955c257c310e83ac"><em>适用系统：Windows/Mac/Linux</em></div></div></details><h4 class="notion-h notion-h3 notion-red notion-h-indent-1 notion-block-9a7db8cdcce347a9b83a47f5b3dac7d9" data-id="9a7db8cdcce347a9b83a47f5b3dac7d9"><span><div id="9a7db8cdcce347a9b83a47f5b3dac7d9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9a7db8cdcce347a9b83a47f5b3dac7d9" title="🎬 媒体工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🎬 媒体工具</span></span></h4><details class="notion-toggle notion-block-826de2881e1340ed89282d73ae0e3437"><summary><b>PotPlayer</b></summary><div><div class="notion-text notion-block-c1f94d2cff544da4b2f912fe29f47222">功能强大的多媒体播放器，支持几乎所有视频格式</div><div class="notion-text notion-block-572fb8adda60407a8bbc8ec1140f4e7e"><em>适用系统：Windows</em></div></div></details><h4 class="notion-h notion-h3 notion-purple notion-h-indent-1 notion-block-a62712dd4e6441528f246511420c15ee" data-id="a62712dd4e6441528f246511420c15ee"><span><div id="a62712dd4e6441528f246511420c15ee" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a62712dd4e6441528f246511420c15ee" title="📊 对比工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📊 对比工具</span></span></h4><details class="notion-toggle notion-block-0f7647e859794ddc9f214c51a993ea52"><summary><b>Beyond Compare 4</b></summary><div><div class="notion-text notion-block-16ce912333fb47fe9c92c2dafa7a8317">专业的文件和文件夹对比工具，支持代码对比和合并</div><div class="notion-text notion-block-7ffec6cb3c2a44c482dbe5b44e3e0e4e"><em>适用系统：Windows/Mac/Linux</em></div></div></details><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-2fecdaa272b68042929ac631f6953a09" data-id="2fecdaa272b68042929ac631f6953a09"><span><div id="2fecdaa272b68042929ac631f6953a09" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2fecdaa272b68042929ac631f6953a09" title="📍驱动相关"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📍<span class="notion-pink">驱动相关</span></span></span></h4><details class="notion-toggle notion-block-2fecdaa272b680a19c63c663f9967d82"><summary><b>驱动总裁</b></summary><div><div class="notion-text notion-block-2fecdaa272b68063b86bf5dd1850b619">free and useful</div></div></details><hr class="notion-hr notion-block-b064a3ff71e44ba7983c58b79107031f"/><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-24e36726076f4bc8836091b6de343117" data-id="24e36726076f4bc8836091b6de343117"><span><div id="24e36726076f4bc8836091b6de343117" class="notion-header-anchor"></div><a class="notion-hash-link" href="#24e36726076f4bc8836091b6de343117" title="🌐 网站推荐"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🌐 网站推荐</span></span></h3><h4 class="notion-h notion-h3 notion-blue notion-h-indent-1 notion-block-f5fe13b50295434c9a776778a3304b3e" data-id="f5fe13b50295434c9a776778a3304b3e"><span><div id="f5fe13b50295434c9a776778a3304b3e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f5fe13b50295434c9a776778a3304b3e" title="📚 学习资源"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📚 学习资源</span></span></h4><div class="notion-row notion-block-746631f422e04a0989724bd127e2ad7c"><div class="notion-column notion-block-d3266adbd832460ea22fd3043910a6bc" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-555a9f4044cd49039524d491cb3b18cf"><b><a class="notion-link" href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub</a></b></div><div class="notion-text notion-block-9c04b5ae1edc492b8f2826582dbfd827">全球最大的代码托管平台，开源项目集中地</div><div class="notion-text notion-block-0d08e0ed57714b49969babc5df302f98"><b><a class="notion-link" href="https://stackoverflow.com" target="_blank" rel="noopener noreferrer">Stack Overflow</a></b></div><div class="notion-text notion-block-dac6ef2d99564ec39df9c99f134911ef">程序员问答社区，解决编程问题必备</div><div class="notion-text notion-block-043f51ef23d444a9bf6c2addec6b63f0"><b><a class="notion-link" href="https://developer.mozilla.org" target="_blank" rel="noopener noreferrer">MDN Web Docs</a></b></div><div class="notion-text notion-block-129f76d0f8164a59960b9a7ff47c14b6">权威的Web开发文档和教程</div><div class="notion-text notion-block-02001367ee72439ab06473a655cec46a"><b><a class="notion-link" href="https://www.runoob.com" target="_blank" rel="noopener noreferrer">菜鸟教程</a></b></div><div class="notion-text notion-block-271b6daf4c4f405dbd69207cca455414">中文编程教程网站，适合初学者</div></div><div class="notion-spacer"></div><div class="notion-column notion-block-666209bcbfe24bffa0f82f73a17e89aa" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-2532fbba6c064c6bb3789fe9e0a6ccb6"><b><a class="notion-link" href="https://leetcode.com" target="_blank" rel="noopener noreferrer">LeetCode</a></b></div><div class="notion-text notion-block-d4c2443eacf142b991a511a6f64cc62f">算法练习平台，面试刷题必备</div><div class="notion-text notion-block-3829a589547d4d0aa4fe57a7e3225f61"><b><a class="notion-link" href="https://www.bilibili.com" target="_blank" rel="noopener noreferrer">哔哩哔哩</a></b></div><div class="notion-text notion-block-f6c9359ccefb4369a8698154463e45cd">丰富的技术学习视频资源</div><div class="notion-text notion-block-ba5cce7db2e44fa1b292916eaac86b9f"><b><a class="notion-link" href="https://juejin.cn" target="_blank" rel="noopener noreferrer">掘金</a></b></div><div class="notion-text notion-block-44b8f0ad99b0496aa6acac4c6ab4b52e">优质的中文技术社区和博客平台</div><div class="notion-text notion-block-16be29fba33c4c0781a345aabe25225e"><b><a class="notion-link" href="https://segmentfault.com" target="_blank" rel="noopener noreferrer">SegmentFault</a></b></div><div class="notion-text notion-block-33151cdf45ce40e181f16d1acea8ce8b">中文技术问答和分享社区</div></div><div class="notion-spacer"></div></div><h4 class="notion-h notion-h3 notion-purple notion-h-indent-1 notion-block-6dd8ade16f8240e296f8d0f06618d69e" data-id="6dd8ade16f8240e296f8d0f06618d69e"><span><div id="6dd8ade16f8240e296f8d0f06618d69e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6dd8ade16f8240e296f8d0f06618d69e" title="🎨 设计资源"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🎨 设计资源</span></span></h4><div class="notion-row notion-block-0abba77c64b64258ba1bd4c6cf5c83cb"><div class="notion-column notion-block-85dd30fde69344e0823c21b4fe5ec8f1" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-b3c31c7bff0b46259d5ca9dd8d92b669"><b><a class="notion-link" href="https://dribbble.com" target="_blank" rel="noopener noreferrer">Dribbble</a></b></div><div class="notion-text notion-block-df16fea18c674666ab6e35f34ac23306">设计师作品展示与灵感平台</div><div class="notion-text notion-block-ba6923690f1843459dbe1addc305ad51"><b><a class="notion-link" href="https://www.behance.net" target="_blank" rel="noopener noreferrer">Behance</a></b></div><div class="notion-text notion-block-f816934eb5c548ccb70ffaa7a2bea992">Adobe旗下创意作品展示平台</div><div class="notion-text notion-block-5b1c85a1fc2e4e3f91ac0a1b0bf02e5b"><b><a class="notion-link" href="https://www.figma.com/community" target="_blank" rel="noopener noreferrer">Figma Community</a></b></div><div class="notion-text notion-block-8b5a266d9c5b40d683a8b0b07aff22c7">免费的设计资源和模板</div></div><div class="notion-spacer"></div><div class="notion-column notion-block-c5bb7da5b6e24c308a3b673ce2e5f0e5" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-83a7afafb47b43e9a0754dab20928390"><b><a class="notion-link" href="https://unsplash.com" target="_blank" rel="noopener noreferrer">Unsplash</a></b></div><div class="notion-text notion-block-0a02795bbd3846c680a5c3f9a67ddd50">高质量免费图片素材库</div><div class="notion-text notion-block-fa6968c7d46b4b74959e9a04ee4f6b99"><b><a class="notion-link" href="https://www.iconfont.cn" target="_blank" rel="noopener noreferrer">Iconfont</a></b></div><div class="notion-text notion-block-c66ccce34d5e4043a18b9fe583462cd0">阿里巴巴矢量图标库</div><div class="notion-text notion-block-a4d4004c303f4ae3b7faab7628960bd7"><b><a class="notion-link" href="https://www.flaticon.com" target="_blank" rel="noopener noreferrer">flaticon</a></b></div><div class="notion-text notion-block-085af2888ac34247b957cc00ef9a3303">海量免费图标资源</div></div><div class="notion-spacer"></div></div><h4 class="notion-h notion-h3 notion-teal notion-h-indent-1 notion-block-2f019586e1fc43e2a64e06d9926097be" data-id="2f019586e1fc43e2a64e06d9926097be"><span><div id="2f019586e1fc43e2a64e06d9926097be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f019586e1fc43e2a64e06d9926097be" title="🔧 开发工具网站"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🔧 开发工具网站</span></span></h4><div class="notion-row notion-block-d354b4735f0a43b4a014f649626e9ea7"><div class="notion-column notion-block-d077068741404a3eb2ae72d279f4a002" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-b04880e235a642a69bad60c88f85e86c"><b><a class="notion-link" href="https://caniuse.com" target="_blank" rel="noopener noreferrer">Can I use</a></b></div><div class="notion-text notion-block-c76af660847a447889629c00aa219b39">查询浏览器对Web特性的支持情况</div><div class="notion-text notion-block-0752e3b78e794302bd765585508b0bff"><b><a class="notion-link" href="https://regexr.com" target="_blank" rel="noopener noreferrer">RegExr</a></b></div><div class="notion-text notion-block-22ec44ed9ad54fcf9051bd10c1a683d6">正则表达式在线测试和学习工具</div><div class="notion-text notion-block-9f2cead5954c49029f6b82cf712c67e4"><b><a class="notion-link" href="https://www.json.cn" target="_blank" rel="noopener noreferrer">JSON在线解析</a></b></div><div class="notion-text notion-block-0c40bd70c6ff45f1b0be4efd0aa389cb">JSON格式化和验证工具</div></div><div class="notion-spacer"></div><div class="notion-column notion-block-bad707f120254b42ae89371ab7e7a4a4" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-cf949467479e4ac287e8322114a10cb5"><b><a class="notion-link" href="https://www.bootcdn.cn" target="_blank" rel="noopener noreferrer">BootCDN</a></b></div><div class="notion-text notion-block-54a44f7f5c854a7ca9f9795aa08454b0">稳定、快速、免费的前端开源项目CDN加速服务</div><div class="notion-text notion-block-e08adb4629db4518b74b28bb108eb96f"><b><a class="notion-link" href="https://tinypng.com" target="_blank" rel="noopener noreferrer">TinyPNG</a></b></div><div class="notion-text notion-block-491deb8350934a1eab41fdcb4f501e1f">在线图片压缩工具，保持质量的同时减小文件大小</div><div class="notion-text notion-block-dd91610ba1a94576983aa2ed90bb1824"><b><a class="notion-link" href="https://codepen.io" target="_blank" rel="noopener noreferrer">CodePen</a></b></div><div class="notion-text notion-block-307329aeeb1d462ab7b270fe09e1193d">前端代码在线编辑和展示平台</div></div><div class="notion-spacer"></div></div><h4 class="notion-h notion-h3 notion-orange notion-h-indent-1 notion-block-c4d4eb07fb874214a23f828b802c9393" data-id="c4d4eb07fb874214a23f828b802c9393"><span><div id="c4d4eb07fb874214a23f828b802c9393" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c4d4eb07fb874214a23f828b802c9393" title="📦 资源下载"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📦 资源下载</span></span></h4><div class="notion-callout notion-yellow_background_co notion-block-b9c47fc66a974cb78616e4f7e233afbf"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="⚠️">⚠️</span></div><div class="notion-callout-text"><div class="notion-text notion-block-22cb6e3fe0bc44a8b4dd26499b91343e"><b>提示：</b> 下载软件时请选择官方渠道，注意安全！</div></div></div><ul class="notion-list notion-list-disc notion-block-43dd5c3d6432463f930f5d1582145884"><li><b><a class="notion-link" href="https://msdn.itellyou.cn" target="_blank" rel="noopener noreferrer">MSDN, 我告诉你</a></b> - Windows系统镜像下载</li></ul><ul class="notion-list notion-list-disc notion-block-d4a24bc33dd246699ddab77dc82a818a"><li><b><a class="notion-link" href="https://www.iplaysoft.com" target="_blank" rel="noopener noreferrer">异次元软件世界</a></b> - 优质软件推荐和下载</li></ul><ul class="notion-list notion-list-disc notion-block-197dfb293e854a49b23899c2716996b8"><li><b><a class="notion-link" href="https://sspai.com" target="_blank" rel="noopener noreferrer">少数派</a></b> - 数字生活方式和效率工具推荐</li></ul><ul class="notion-list notion-list-disc notion-block-8ad6f5329b07424aa932c87fca86db15"><li><b><a class="notion-link" href="https://www.52pojie.cn" target="_blank" rel="noopener noreferrer">吾爱破解</a></b> - 软件分享和技术交流论坛</li></ul><hr class="notion-hr notion-block-0926cf2e312f44f599defeeadc2d92b1"/><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-17e31c18985d4740b705235f80a06da7" data-id="17e31c18985d4740b705235f80a06da7"><span><div id="17e31c18985d4740b705235f80a06da7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#17e31c18985d4740b705235f80a06da7" title="🔌 VSCode 插件推荐"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🔌 VSCode 插件推荐</span></span></h3><div class="notion-callout notion-purple_background_co notion-block-0fd10df51b274b9294b6a27471b99d33"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="✨">✨</span></div><div class="notion-callout-text"><div class="notion-text notion-block-a50297d795e144f2a8a81f25aa4905f4">以下是精选的VSCode插件，可以大幅提升开发效率和体验！</div></div></div><h4 class="notion-h notion-h3 notion-purple notion-h-indent-1 notion-block-348e8790322f49499944b24a305d33c8" data-id="348e8790322f49499944b24a305d33c8"><span><div id="348e8790322f49499944b24a305d33c8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#348e8790322f49499944b24a305d33c8" title="🎨 界面美化"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🎨 界面美化</span></span></h4><ul class="notion-list notion-list-disc notion-block-4e8133210467478780a7acc2f30c67b0"><li><b>Chinese (Simplified) Language Pack</b> - 中文语言包</li></ul><ul class="notion-list notion-list-disc notion-block-7a6d321316744d28a6da869d1603a39c"><li><b>Material Icon Theme</b> - 精美的文件图标主题</li></ul><ul class="notion-list notion-list-disc notion-block-e512afde592e4f31b7cd3fca7fa86917"><li><b>One Dark Pro</b> - 流行的暗色主题</li></ul><ul class="notion-list notion-list-disc notion-block-f6d9f660022d4f6991fdc69e447971b2"><li><b>Bracket Pair Colorizer 2</b> - 彩色括号配对（已内置，可选）</li></ul><ul class="notion-list notion-list-disc notion-block-1bd6d7e430ac4b54815d0b05d8394528"><li><b>Indent Rainbow</b> - 缩进彩虹高亮</li></ul><h4 class="notion-h notion-h3 notion-blue notion-h-indent-1 notion-block-509aecf643b4423a91a564768ac1a530" data-id="509aecf643b4423a91a564768ac1a530"><span><div id="509aecf643b4423a91a564768ac1a530" class="notion-header-anchor"></div><a class="notion-hash-link" href="#509aecf643b4423a91a564768ac1a530" title="🚀 效率提升"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🚀 效率提升</span></span></h4><ul class="notion-list notion-list-disc notion-block-f3c311175e9747acada24ff93df387ad"><li><b>Path Intellisense</b> - 路径自动补全</li></ul><ul class="notion-list notion-list-disc notion-block-8d012b5a890c49418666d307925ba646"><li><b>Auto Rename Tag</b> - 自动重命名配对的HTML/XML标签</li></ul><ul class="notion-list notion-list-disc notion-block-3af5f7796cc849a68bb19a8b47a3235b"><li><b>Auto Close Tag</b> - 自动闭合HTML/XML标签</li></ul><ul class="notion-list notion-list-disc notion-block-ee924969d36d4dd2b02889ae2acb2f94"><li><b>Multiple cursor case preserve</b> - 多光标保持大小写</li></ul><ul class="notion-list notion-list-disc notion-block-2718339ff1d94a239d964fe87c18f436"><li><b>Better Comments</b> - 增强注释显示效果</li></ul><ul class="notion-list notion-list-disc notion-block-f09d1fb9772f4c07b0d260c5f721fa62"><li><b>TODO Highlight</b> - 高亮TODO、FIXME等标记</li></ul><ul class="notion-list notion-list-disc notion-block-f966179633074e3ba71a3c34a4b2b99d"><li><b>Bookmarks</b> - 代码书签，快速跳转</li></ul><h4 class="notion-h notion-h3 notion-teal notion-h-indent-1 notion-block-6aa20362bdb94034841c6bcd0e28abe2" data-id="6aa20362bdb94034841c6bcd0e28abe2"><span><div id="6aa20362bdb94034841c6bcd0e28abe2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6aa20362bdb94034841c6bcd0e28abe2" title="💻 编程语言支持"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">💻 编程语言支持</span></span></h4><div class="notion-text notion-block-6cd5d6fd3e5c475c8eb2a293dcbfa5cb"><b>前端开发</b></div><ul class="notion-list notion-list-disc notion-block-587407b87f4e4ee7b19caa1d81c06b84"><li><b>ESLint</b> - JavaScript代码检查</li></ul><ul class="notion-list notion-list-disc notion-block-fd623a7b0aed49378812c2288df6eae2"><li><b>Prettier</b> - 代码格式化工具</li></ul><ul class="notion-list notion-list-disc notion-block-dff1a3418bcb40e29cbec1cf8e9322ae"><li><b>Live Server</b> - 实时预览HTML页面</li></ul><ul class="notion-list notion-list-disc notion-block-b173b9bb6b90428dafb98c8c7c8811cd"><li><b>HTML CSS Support</b> - HTML中CSS类名智能提示</li></ul><ul class="notion-list notion-list-disc notion-block-bd3da89f7d8e41799239205a581f8cf2"><li><b>JavaScript (ES6) code snippets</b> - ES6代码片段</li></ul><div class="notion-text notion-block-7f1d8d30beab47899f21bc1dc362d4b0"><b>Python开发</b></div><ul class="notion-list notion-list-disc notion-block-1c65347895dd4f33bcf9b7157d9a78bd"><li><b>Python</b> - Python语言支持（必装）</li></ul><ul class="notion-list notion-list-disc notion-block-3ca4df70ecd4443e9ba31310fcce446e"><li><b>Pylance</b> - 高性能Python语言服务器</li></ul><ul class="notion-list notion-list-disc notion-block-5839cae942944dffa2dc1660c5acb0bb"><li><b>Python Docstring Generator</b> - 自动生成Python文档字符串</li></ul><div class="notion-text notion-block-0dc15aef35f241d1b87cec5672a8fa4f"><b>其他语言</b></div><ul class="notion-list notion-list-disc notion-block-05220fbc96954f62b0bc4ca97d40ee3c"><li><b>C/C++</b> - C/C++语言支持</li></ul><ul class="notion-list notion-list-disc notion-block-284e8f037feb4b57b6cd876d86e690cd"><li><b>Java Extension Pack</b> - Java开发扩展包</li></ul><ul class="notion-list notion-list-disc notion-block-210c0a5c738841aebc3dd65ff37f249a"><li><b>Go</b> - Go语言支持</li></ul><h4 class="notion-h notion-h3 notion-orange notion-h-indent-1 notion-block-4b750e57af1f4f8ab2a5def80f51c2d4" data-id="4b750e57af1f4f8ab2a5def80f51c2d4"><span><div id="4b750e57af1f4f8ab2a5def80f51c2d4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4b750e57af1f4f8ab2a5def80f51c2d4" title="🤖 AI辅助"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🤖 AI辅助</span></span></h4><ul class="notion-list notion-list-disc notion-block-bf423a93f2aa4b6fbe208b2597fcf057"><li><b>GitHub Copilot</b> - AI代码补全助手（需订阅）</li></ul><ul class="notion-list notion-list-disc notion-block-aa71bda1c2bf464c9e171fe6a7c73cde"><li><b>Tabnine</b> - AI代码补全（免费版可用）</li></ul><ul class="notion-list notion-list-disc notion-block-68c00f66f0dc4b799064fc7ca1403f60"><li><b>CodeGeeX</b> - 免费的AI编程助手，支持中文</li></ul><h4 class="notion-h notion-h3 notion-yellow notion-h-indent-1 notion-block-b0f5e685021e439e8cc7033a274db668" data-id="b0f5e685021e439e8cc7033a274db668"><span><div id="b0f5e685021e439e8cc7033a274db668" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b0f5e685021e439e8cc7033a274db668" title="🔧 版本控制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🔧 版本控制</span></span></h4><ul class="notion-list notion-list-disc notion-block-28c08f2b49764b9a868c1e314b4ff93a"><li><b>GitLens</b> - 增强Git功能，显示代码作者和历史</li></ul><ul class="notion-list notion-list-disc notion-block-070affe15a3f4158ac3f8605587689e8"><li><b>Git Graph</b> - 可视化Git提交历史</li></ul><ul class="notion-list notion-list-disc notion-block-09d6bfc5db8340509ca770126b67c3fa"><li><b>Git History</b> - 查看文件和行的Git历史记录</li></ul><h4 class="notion-h notion-h3 notion-red notion-h-indent-1 notion-block-92f54e378d7b4a0686a78a7132de3924" data-id="92f54e378d7b4a0686a78a7132de3924"><span><div id="92f54e378d7b4a0686a78a7132de3924" class="notion-header-anchor"></div><a class="notion-hash-link" href="#92f54e378d7b4a0686a78a7132de3924" title="📊 数据与格式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📊 数据与格式</span></span></h4><ul class="notion-list notion-list-disc notion-block-aceb4385ec644d1b94118247fa7ed288"><li><b>JSON</b> - JSON文件格式化和验证</li></ul><ul class="notion-list notion-list-disc notion-block-2ff3f0af88d241309c32df7918b7a39f"><li><b>YAML</b> - YAML语言支持</li></ul><ul class="notion-list notion-list-disc notion-block-3b4ae49eed954e4697dc893d43325b1a"><li><b>Markdown All in One</b> - Markdown编辑增强</li></ul><ul class="notion-list notion-list-disc notion-block-d5bcbcea16504ee4aa956e3b2e7641ba"><li><b>Markdown Preview Enhanced</b> - Markdown预览增强</li></ul><ul class="notion-list notion-list-disc notion-block-1ecb621d136e4a73ab99189f95672979"><li><b>Excel Viewer</b> - 在VSCode中查看CSV和Excel文件</li></ul><h4 class="notion-h notion-h3 notion-blue notion-h-indent-1 notion-block-2533ca605bca4ce2a2e5c487a7abc798" data-id="2533ca605bca4ce2a2e5c487a7abc798"><span><div id="2533ca605bca4ce2a2e5c487a7abc798" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2533ca605bca4ce2a2e5c487a7abc798" title="🐛 调试与测试"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🐛 调试与测试</span></span></h4><ul class="notion-list notion-list-disc notion-block-6162c87eb78542468cd750f63eec2b79"><li><b>Debugger for Chrome</b> - Chrome调试工具</li></ul><ul class="notion-list notion-list-disc notion-block-e7e6061564294cc6b8d8d69850e53cb0"><li><b>REST Client</b> - 在VSCode中测试HTTP请求</li></ul><ul class="notion-list notion-list-disc notion-block-454821da53414d4fabce1d103af51485"><li><b>Thunder Client</b> - 轻量级API测试工具</li></ul><h4 class="notion-h notion-h3 notion-teal notion-h-indent-1 notion-block-2c9ddc341dd2434488e3054f6cc7b544" data-id="2c9ddc341dd2434488e3054f6cc7b544"><span><div id="2c9ddc341dd2434488e3054f6cc7b544" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2c9ddc341dd2434488e3054f6cc7b544" title="🌐 远程开发"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🌐 远程开发</span></span></h4><ul class="notion-list notion-list-disc notion-block-8231b9600e154fda8d83fdb9606f53c4"><li><b>Remote - SSH</b> - 通过SSH连接远程服务器开发</li></ul><ul class="notion-list notion-list-disc notion-block-b1642115cccc49d7a0abcfb3f5c94869"><li><b>Remote - WSL</b> - 在WSL中开发</li></ul><ul class="notion-list notion-list-disc notion-block-b98ae65e0d5a4d59a8a1e10f4a1b751e"><li><b>Remote Development</b> - 远程开发扩展包</li></ul><h4 class="notion-h notion-h3 notion-purple notion-h-indent-1 notion-block-c84af14281754f3caad1c7e38e442523" data-id="c84af14281754f3caad1c7e38e442523"><span><div id="c84af14281754f3caad1c7e38e442523" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c84af14281754f3caad1c7e38e442523" title="📝 其他实用插件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 其他实用插件</span></span></h4><ul class="notion-list notion-list-disc notion-block-df51d1b798ba419bae3c28d73db25b9c"><li><b>Code Spell Checker</b> - 代码拼写检查</li></ul><ul class="notion-list notion-list-disc notion-block-a92ac4c5a921448b929f2b785724853c"><li><b>Project Manager</b> - 项目管理，快速切换项目</li></ul><ul class="notion-list notion-list-disc notion-block-0d29b128bf29470ca659efd78fee792e"><li><b>Settings Sync</b> - 同步VSCode设置和插件</li></ul><ul class="notion-list notion-list-disc notion-block-05cc9de857254faf95cb923eb4e11833"><li><b>Error Lens</b> - 行内显示错误和警告信息</li></ul><ul class="notion-list notion-list-disc notion-block-bc6e03cd0cf84c05bec4ddd9dc2cd2c0"><li><b>Code Runner</b> - 快速运行代码片段</li></ul><hr class="notion-hr notion-block-8ff93de392d949d18a2e9c1263c2d823"/><div class="notion-callout notion-teal_background_co notion-block-c1d416b5f1da455bb6aec3ddbf8fbd6e"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="💡">💡</span></div><div class="notion-callout-text"><div class="notion-text notion-block-2db526f9dc2a47b899c731fa00206b5a"><b>使用建议</b>
不要安装过多插件，会影响VSCode性能。根据实际需求选择必要的插件，定期清理不用的扩展。</div></div></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cursor工具简单使用指南]]></title>
            <link>https://hllqk.cn/article/cursor-guide</link>
            <guid>https://hllqk.cn/article/cursor-guide</guid>
            <pubDate>Thu, 29 Jan 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[推荐使用配置 （1）不推荐import vscode extensions有些插件会有问题，如remote ssh工具连不上远程。 图1 vscode extension配置导入 （2）推荐插件 Chinese：汉化 Dev contain…]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-2f7cdaa272b6804b8b9acadf29123a2e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2f7cdaa272b68009ba39da8ca952a9eb" data-id="2f7cdaa272b68009ba39da8ca952a9eb"><span><div id="2f7cdaa272b68009ba39da8ca952a9eb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b68009ba39da8ca952a9eb" title="推荐使用配置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>推荐使用配置</b></span></span></h2><div class="notion-text notion-block-2f7cdaa272b6806881c7f63a7460aa8e">（1）不推荐<code class="notion-inline-code">import vscode extensions</code>有些插件会有问题，如<code class="notion-inline-code">remote ssh</code>工具连不上远程。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b680a5b5e1ea0b4ba05533"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:614px;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-80a5-b5e1-ea0b4ba05533?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d5328e233017d5fabe2c68820d3fb60f70f33e21d4a1c51c2d00b1799ca6cd4e2c176f378591759450%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2f7cdaa272b680a282fdca88b0df54c6">图1 vscode extension配置导入</div><div class="notion-text notion-block-2f7cdaa272b680dca394dc18191cd365">（2）推荐插件</div><ul class="notion-list notion-list-disc notion-block-2f7cdaa272b680658e9bd01b8db6ecac"><li><span class="notion-yellow_background">Chinese：汉化</span></li></ul><ul class="notion-list notion-list-disc notion-block-2f7cdaa272b680f7b614e944aa6b8d0d"><li><span class="notion-yellow_background">Dev containers</span></li></ul><ul class="notion-list notion-list-disc notion-block-2f7cdaa272b68034be6bd91e3d04ad41"><li><span class="notion-yellow_background">ESLint：括号修饰</span></li></ul><ul class="notion-list notion-list-disc notion-block-2f7cdaa272b680a2886afbbf27950d4f"><li><span class="notion-yellow_background">Prettier：代码高亮</span></li></ul><ul class="notion-list notion-list-disc notion-block-2f7cdaa272b680d9b94bf1204f82cb23"><li><span class="notion-yellow_background">Python：Python相关插件，对python识别，支持Python Interpreter</span></li></ul><ul class="notion-list notion-list-disc notion-block-2f7cdaa272b680b6abcee1d45e02dd49"><li><span class="notion-yellow_background">Remote-ssh：远程链接集群代码工具。</span></li></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b680abbf3dcf2736126152"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:700px;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-80ab-bf3d-cf2736126152?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d55c777a967fa0f1967584b15b068666e908daf0c940b9ba5b5898173bab1be339d6edab1cbc4bd005%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2f7cdaa272b6800eaa6ff497463e479e">（3）其他使用和Vscode配置一模一样，字体大小如Font，窗口字体大小如Zoom配置等。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b6802ea042f08585f49d6e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:700px;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-802e-a042-f08585f49d6e?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d52d3116685fef39ef36d47b8956cc96887cfbd642c2bc6c89f640553b9bacc39a8875d6192a93edf6%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2f7cdaa272b680ca8b67f06f6adea59e">图2 cursor页面</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2f7cdaa272b6806da226c1e97126a3ad" data-id="2f7cdaa272b6806da226c1e97126a3ad"><span><div id="2f7cdaa272b6806da226c1e97126a3ad" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b6806da226c1e97126a3ad" title="使用技巧"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>使用技巧</b></span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-2f7cdaa272b680f78b49f1c50084de2f" data-id="2f7cdaa272b680f78b49f1c50084de2f"><span><div id="2f7cdaa272b680f78b49f1c50084de2f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680f78b49f1c50084de2f" title="提示词"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>提示词</b></span></span></h4><div class="notion-text notion-block-2f7cdaa272b680799794f14850d3d59c">（1）规范化提示词清晰传达我们的需求。</div><div class="notion-text notion-block-2f7cdaa272b680dd89d2fe8f885129b6">（2）使用ASK模式，让Cursor优化提示词。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2f7cdaa272b680bdb63fcfe78f31012a" data-id="2f7cdaa272b680bdb63fcfe78f31012a"><span><div id="2f7cdaa272b680bdb63fcfe78f31012a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680bdb63fcfe78f31012a" title="使用经验"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>使用经验</b></span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2f7cdaa272b680aaad2ec2a05cc63ed4" data-id="2f7cdaa272b680aaad2ec2a05cc63ed4"><span><div id="2f7cdaa272b680aaad2ec2a05cc63ed4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680aaad2ec2a05cc63ed4" title="2.1 经验分享"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>2.1 经验分享</b></span></span></h3><div class="notion-text notion-block-2f7cdaa272b6808f96b5c2aa430509c0"><a class="notion-link" href="https://x.com/ryolu_/status/1914384195138511142" target="_blank" rel="noopener noreferrer">https://x.com/ryolu_/status/1914384195138511142</a></div><div class="notion-text notion-block-2f7cdaa272b68038a2b6da26f2e3bd44">引用Cursor设计总监的经验话语</div><ol start="1" class="notion-list notion-list-numbered notion-block-2f7cdaa272b6800db959fab51db987b2" style="list-style-type:decimal"><li>Set 5-10 clear project rules upfront so Cursor knows your structure and constraints. Try /generate rules for existing codebases. # 设置5-10规则，减少大模型的幻觉，让AI过度聪明</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680cab6c9ea58892af7f6" style="list-style-type:decimal"><li>Be specific in prompts. Spell out tech stack, behavior, and constraints like a mini spec. # 清晰的提示词，说明你的技术栈，行为，包括最终需要达到的一个目的，限制条件，可以合理使用ASK模式</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-2f7cdaa272b68038b014d3f2b97abf11" style="list-style-type:decimal"><li>Work file by file; generate, test, and review in small, focused chunks. # 小颗粒度修改如文件夹或者文件级别去修改，用测试驱动开发的形式，让Cursor针对自行改动的内容进行测试</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-2f7cdaa272b6803f970fdaf244df65ee" style="list-style-type:decimal"><li>Write tests first, lock them, and generate code until all tests pass. # 先写测试用例，测试驱动开发，非常推荐的功能</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-2f7cdaa272b68037a52cf297c5212c4b" style="list-style-type:decimal"><li>Always review AI output and hard‑fix anything that breaks, then tell Cursor to use them as examples. # 审查AI的输出，这一段对于我们来说是强项</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680658d41cae648bcc08d" style="list-style-type:decimal"><li>Use @ file, @ folders, @ git to scope Cursor’s attention to the right parts of your codebase. # 使用@来限用上下文，高频使用功能</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680e6bcc4f986e1d016a9" style="list-style-type:decimal"><li>Keep design docs and checklists in .cursor/ so the agent has full context on what to do next. # 在.cursor/下给出清晰的清单，不要一次性做完，而是一个一个的做，一个一个做阶段性测试。</li></ol><ol start="8" class="notion-list notion-list-numbered notion-block-2f7cdaa272b6803fb7c6cc020669f56c" style="list-style-type:decimal"><li>If code is wrong, just write it yourself. Cursor learns faster from edits than explanations.# 代码如果百分之百写错了，就自己写，Cursor会汲取经验</li></ol><ol start="9" class="notion-list notion-list-numbered notion-block-2f7cdaa272b68086b216d2a921c36c26" style="list-style-type:decimal"><li>Use chat history to iterate on old prompts without starting over. # 利用聊天记录复用旧的提示词，项目级别保留历史对话</li></ol><ol start="10" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680359741eba4012c7da0" style="list-style-type:decimal"><li>Choose models intentionally. Gemini for precision, Claude for breadth. # 根据需要选择模型</li></ol><ol start="11" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680eaa049fb6605195d03" style="list-style-type:decimal"><li>In new or unfamiliar stacks, paste in link to documentation. Make Cursor explain all errors and fixes line by line.# 文档首页粘贴</li></ol><ol start="12" class="notion-list notion-list-numbered notion-block-2f7cdaa272b6805c867bffaad426db6d" style="list-style-type:decimal"><li>Let big projects index overnight and limit context scope to keep performance snappy. # 大工程索引完后再动工</li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2f7cdaa272b680e8b01cccae8ba772a3" data-id="2f7cdaa272b680e8b01cccae8ba772a3"><span><div id="2f7cdaa272b680e8b01cccae8ba772a3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680e8b01cccae8ba772a3" title="1.2 Cursor Rules"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>1.2 Cursor Rules</b></span></span></h3><div class="notion-text notion-block-2f7cdaa272b680898952dd0c4d155551"><a class="notion-link" href="https://github.com/PatrickJS/awesome-cursorrules" target="_blank" rel="noopener noreferrer">https://github.com/PatrickJS/awesome-cursorrules</a></div><ol start="1" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680099119eadf6a1656ce" style="list-style-type:decimal"><li>ASK模式-&gt;Agent模式：适用于所有的IDE模式。</li><ol class="notion-list notion-list-numbered notion-block-2f7cdaa272b680099119eadf6a1656ce" style="list-style-type:lower-alpha"><div class="notion-text notion-block-2f7cdaa272b6804fa6faede06a018f59">Step1: 利用ASK模式将自然语言转换成结构化的提示词</div><div class="notion-text notion-block-2f7cdaa272b680f88aeacfe8ce152407">我现在需要做一个个人作品集的展示网站，它是一个单页网站，然后作品都是以图片的展示形式，请你帮我生成提示词</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b6809aa280c552032e8398" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">我来帮您生成一个个人作品集展示网站的提示词。首先让我了解一下您的项目结构，然后为您提供详细的提示词。

Ran tool
基于您的需求，我为您生成一个详细的提示词来创建个人作品集展示网站：

## 个人作品集展示网站开发提示词

**项目概述：**
创建一个现代化的单页个人作品集展示网站，以图片为主要展示形式，具有响应式设计和优秀的用户体验。

**技术要求：**
- 使用 HTML5、CSS3 和 JavaScript (ES6+)
- 响应式设计，支持移动端、平板和桌面端
- 现代化的 UI/UX 设计
- 图片懒加载和优化
- 平滑的动画效果和过渡

**页面结构：**
1. **导航栏**
   - 固定在页面顶部
   - 包含 Logo/姓名
   - 导航菜单（首页、作品、关于、联系）
   - 汉堡菜单（移动端）

2. **首页横幅区域**
   - 全屏高度的欢迎区域
   - 个人介绍和标语
   - 背景图片或渐变效果
   - 向下滚动指示器

3. **作品展示区域**
   - 网格布局展示作品图片
   - 图片悬停效果
   - 点击放大查看详情
   - 分类筛选功能
   - 图片懒加载

4. **关于我区域**
   - 个人简介
   - 技能展示
   - 经验时间线
   - 个人照片

5. **联系区域**
   - 联系表单
   - 社交媒体链接
   - 联系信息

**设计风格：**
- 简约现代的设计风格
- 使用优雅的字体
- 柔和的色彩搭配
- 适当的留白
- 微妙的阴影和圆角

**功能特性：**
- 图片画廊（支持点击放大）
- 平滑滚动导航
- 作品分类筛选
- 响应式图片网格
- 加载动画
- 返回顶部按钮

**性能优化：**
- 图片压缩和优化
- 懒加载实现
- 最小化 CSS 和 JS
- 浏览器缓存策略

**文件结构建议：**
```
portfolio/
├── index.html
├── css/
│   ├── style.css
│   └── responsive.css
├── js/
│   ├── main.js
│   └── gallery.js
├── images/
│   ├── works/
│   ├── profile/
│   └── icons/
└── assets/
    └── fonts/
```

**额外建议：**
- 添加作品详情模态框
- 实现作品搜索功能
- 添加作品标签系统
- 集成社交媒体分享
- 添加作品下载功能（如适用）
- 实现深色/浅色主题切换

这个提示词涵盖了创建一个专业个人作品集网站的所有关键要素。您可以根据具体需求调整或补充任何部分。</code></pre><div class="notion-text notion-block-2f7cdaa272b6803b87cefc853e4ad027">Step2: 然后再切换为Agent模式</div></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680c1a96fdbaaef3f53e5" style="list-style-type:decimal"><li>测试驱动开发：需要实现一个特定的功能，先让AI想一些需要测试的功能，直到所有的测试用例全部跑通后</li><ol class="notion-list notion-list-numbered notion-block-2f7cdaa272b680c1a96fdbaaef3f53e5" style="list-style-type:lower-alpha"><div class="notion-text notion-block-2f7cdaa272b680baa0f4fd1b9dcb0f77">Step1:</div></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680d9b980c2ca27aa6141" style="list-style-type:decimal"><li>Project Rules-&gt;User Rule</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-2f7cdaa272b6806da1deea48a6c731b5" style="list-style-type:decimal"><li>@限用上下文</li><ol class="notion-list notion-list-numbered notion-block-2f7cdaa272b6806da1deea48a6c731b5" style="list-style-type:lower-alpha"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b680008c34d1f19428dac5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-8000-8c34-d1f19428dac5?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d5f2335a476e9de28f250f816deae959d59be92f57458e58290b5fc0e739da0b3854ed902fa83dcca5%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure></ol></ol><ol start="5" class="notion-list notion-list-numbered notion-block-2f7cdaa272b680038a53eb18ad2b7049" style="list-style-type:decimal"><li>学会复用历史会话</li></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b680c4a400e5ce9d28c10f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:700px;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-80c4-a400-e5ce9d28c10f?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d56fa42808a4bf91c5bc9042517c93df595c4882b0ea75234cf33dedcd5505998bc83035c022b7b4a8%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2f7cdaa272b6809895a4cdafc6f3325a" data-id="2f7cdaa272b6809895a4cdafc6f3325a"><span><div id="2f7cdaa272b6809895a4cdafc6f3325a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b6809895a4cdafc6f3325a" title="Cursor实战"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Cursor实战</b></span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2f7cdaa272b68041b9d3dd6f4fefd560" data-id="2f7cdaa272b68041b9d3dd6f4fefd560"><span><div id="2f7cdaa272b68041b9d3dd6f4fefd560" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b68041b9d3dd6f4fefd560" title="3.1 CvToolkit"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>3.1 CvToolkit</b></span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-2f7cdaa272b680a2aea1e37a1329fc2d" data-id="2f7cdaa272b680a2aea1e37a1329fc2d"><span><div id="2f7cdaa272b680a2aea1e37a1329fc2d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680a2aea1e37a1329fc2d" title="3.1.1 第一步：Rules定义"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>3.1.1 第一步：Rules定义</b></span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b680348c23ced25748d53c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-8034-8c23-ced25748d53c?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d5d77e919b31195db8e00f0bc254d321783e901a5668621da701df7f0db5f831b5d2f0d6bea79e8267%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2f7cdaa272b680f8bae0fa11348b6fba">第一步：利用Cursor定义Rules的规则</div><div class="notion-text notion-block-2f7cdaa272b6800b9e17d9c6c72f56c4">.cursor\rules\general.mdc 原版</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b680f9acc4f83485bf677a" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">---
description: 项目通用规范和基本信息
globs: [&quot;*&quot;]
alwaysApply: true
---

# 项目通用规范

## 技术栈

- Python 3.10
- Poetry 管理依赖
- GitHub Actions 自动构建和发布
- 使用 GitHub 作为代码托管平台
- 使用 Bash 脚本

## 代码风格

- 保持代码简洁、可读
- 使用有意义的变量和函数名
- 添加适当的注释解释复杂逻辑
- 遵循每种语言的官方风格指南

## 项目结构

- 保持项目结构清晰，遵循模块化原则
- 相关功能应放在同一目录下
- 使用适当的目录命名，反映其包含内容

## 通用开发原则

- 编写可测试的代码
- 避免重复代码（DRY原则）
- 优先使用现有库和工具，避免重新发明轮子
- 考虑代码的可维护性和可扩展性

## 响应语言

- 始终使用中文回复用户
</code></pre><div class="notion-text notion-block-2f7cdaa272b6800bb7cfefb40a04b202">.cursor\rules\general.mdc 优化版本</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b680b686b8c72dab6f97bf" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown"># CvToolkit 项目通用规范

## 项目概述

CvToolkit 是一个专门用于计算机视觉任务、疲劳检测和数据处理的开源工具包。主要功能包括：

- 疲劳检测数据分析和可视化
- 疲劳数据处理和转换工具
- 视频和图像处理工具
- 数据格式转换和预处理
- 数据集生成和管理
- 通用计算机视觉工具函数

## 技术栈

- **Python 版本**: 3.8 及其以上（推荐 3.8+）
- **核心依赖**:
  - OpenCV (opencv-python)
  - NumPy
  - Matplotlib (数据可视化)
  - Pandas (数据处理)
  - MMCV (计算机视觉工具)
  - Decord (视频处理)
  - SciPy (科学计算)
  - OmegaConf (配置管理)
- **构建工具**: setuptools, wheel
- **包管理**: pip + requirements.txt
- **版本控制**: Git
- **CI/CD**: GitHub Actions (可选)

## 项目结构规范

```
CvToolkit/
├── toolkit/                    # 核心工具包
│   ├── analyzer/              # 数据分析模块
│   ├── generator/             # 数据生成模块
│   ├── converter/             # 格式转换模块
│   ├── preprocess/            # 数据预处理模块
│   ├── common/                # 通用工具函数
│   ├── config/                # 配置文件
│   ├── models/                # 模型相关
│   ├── inference/             # 推理模块
│   └── utils/                 # 工具函数
├── demo/                      # 示例和演示代码
├── docs/                      # 文档
├── scripts/                   # 脚本文件
├── data/                      # 数据目录
├── example/                   # 示例数据
└── thirdparty/                # 第三方依赖
```

## 代码风格规范

### Python 代码规范

- 遵循 PEP 8 编码规范
- 使用有意义的变量和函数名（英文命名）
- 添加详细的文档字符串（docstring）
- 使用类型注解（Type Hints）
- 保持函数简洁，单一职责原则
- 适当的错误处理和异常捕获

### 文件命名规范

- 模块文件使用小写字母和下划线：`analyzer_fatigue.py`
- 类名使用驼峰命名：`AnalyzerFromAitxt`
- 函数和变量使用小写字母和下划线：`plot_3df_fatigue`
- 常量使用大写字母和下划线：`EYE_STATUS_ENUM`

### 注释规范

- 复杂逻辑必须添加中文注释
- 函数和类必须有详细的文档字符串
- 关键算法步骤需要行内注释
- 配置参数需要说明用途和取值范围

## 功能模块开发规范

### 分析器模块 (analyzer/)

- 支持多种数据格式（AITXT、JSON）
- 提供数据可视化功能
- 实现统计分析功能
- 支持批量处理

### 生成器模块 (generator/)

- 支持疲劳检测数据生成
- 实现数据增强功能
- 提供数据格式转换
- 支持自定义配置

### 通用工具模块 (common/)

- 提供跨模块使用的工具函数
- 实现文件 I/O 操作
- 提供计算机视觉基础功能
- 实现日志记录功能

### 配置管理

- 使用 OmegaConf 进行配置管理
- 配置文件使用 YAML 格式
- 支持环境变量覆盖
- 提供默认配置和用户配置

## 数据处理规范

### 输入数据格式

- 支持 AITXT 格式（疲劳检测结果）
- 支持 JSON 格式（标注数据）
- 支持常见视频格式（MP4、AVI）
- 支持常见图像格式（JPG、PNG）

### 输出数据格式

- 标准化 JSON 格式
- CSV 格式（统计分析结果）
- 图像格式（可视化结果）
- 视频格式（处理结果）

### 数据验证

- 输入数据完整性检查
- 格式验证和错误处理
- 数据质量评估
- 结果一致性验证

## 性能优化规范

### 内存管理

- 大文件处理使用流式读取
- 及时释放不需要的内存
- 使用生成器处理大数据集
- 避免内存泄漏

### 并行处理

- 使用多线程处理 I/O 密集型任务
- 使用多进程处理 CPU 密集型任务
- 合理设置线程/进程数量
- 避免资源竞争

### 缓存策略

- 合理使用缓存减少重复计算
- 缓存文件使用临时目录
- 定期清理缓存文件
- 缓存大小限制

## 测试规范

### 单元测试

- 核心功能必须有单元测试
- 测试覆盖率不低于 80%
- 使用 pytest 框架
- 测试数据使用示例数据

### 集成测试

- 模块间接口测试
- 端到端功能测试
- 性能基准测试
- 兼容性测试

## 文档规范

### 代码文档

- 所有公共 API 必须有文档字符串
- 使用 Google 或 NumPy 文档字符串格式
- 包含参数说明、返回值说明、示例代码
- 复杂算法需要详细说明

### 用户文档

- README.md 包含项目概述和使用说明
- 提供详细的安装指南
- 包含示例代码和演示
- 提供常见问题解答

### API 文档

- 自动生成 API 文档
- 包含所有公共接口说明
- 提供在线文档访问
- 定期更新文档

## 版本管理规范

### 版本号规范

- 使用语义化版本号（Semantic Versioning）
- 格式：主版本号.次版本号.修订号
- 主版本号：不兼容的 API 修改
- 次版本号：向下兼容的功能性新增
- 修订号：向下兼容的问题修正

### 发布流程

- 开发分支：develop
- 主分支：main
- 功能分支：feature/功能名
- 修复分支：hotfix/问题描述
- 发布标签：v 版本号

## 响应语言

- 始终使用中文回复用户
- 代码注释使用中文
- 文档使用中文编写
- 错误信息使用中文

## 开发环境设置

### 环境变量

```bash
# 设置 PYTHONPATH
export PYTHONPATH=$PWD:$PYTHONPATH

# 设置 CUDA 环境（如需要）
export CUDA_VISIBLE_DEVICES=0
```

### 依赖安装

```bash
# 安装基础依赖
pip install -r requirements.txt

# 开发环境额外依赖
pip install pytest pytest-cov black flake8
```

## 贡献指南

### 代码提交

- 提交前运行代码格式化：`black .`
- 提交前运行代码检查：`flake8`
- 提交前运行测试：`pytest`
- 提交信息使用中文描述

### 代码审查

- 所有代码变更需要代码审查
- 审查重点：功能正确性、代码质量、性能影响
- 审查通过后才能合并到主分支
- 记录审查意见和修改历史

## 响应语言

- 始终使用中文回复用户
</code></pre><div class="notion-text notion-block-2f7cdaa272b680bca140d98a2c7fced8">.cursor\rules\python.mdc 原版</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b680649daffca050b3261a" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown"># 角色
你是一名精通 Python 的高级工程师，拥有 20 年的软件开发经验。

# 目标
你的目标是以用户容易理解的方式帮助他们完成 Python 项目的设计和开发工作。你应该主动完成所有工作，而不是等待用户发出指示。

你应始终遵循以下原则：

### 编写代码时：
- 遵循 PEP 8 Python 代码风格指南。
- 使用 Python 3.10 及以上的语法特性和最佳实践。
- 合理使用面向对象编程（OOP）和函数式编程范式。
- 利用 Python 的标准库和生态系统中的优质第三方库。
- 实现模块化设计，确保代码的可重用性和可维护性。
- 使用类型提示（Type Hints）进行类型检查，提高代码质量。
- 编写详细的文档字符串（docstring）和注释。
- 记录当前的错误处理和日志记录。
- 持续编写单元测试确保代码质量。

### 解决问题时：
- 全面阅读相关代码文件，理解所有已有的功能和逻辑。
- 确保所有新增功能都能与现有系统兼容。
- 与用户沟通并充分交互，根据反馈调整解决方案。

在整个过程中，始终参考 Python 官方文档，确保使用最新的 Python 开发最佳实践。
</code></pre><div class="notion-text notion-block-2f7cdaa272b6803e83e0cad2594c624a">.cursor\rules\python.mdc 优化后版本</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b680bab56cc2c6bbaac8e5" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown"># CvToolkit Python 开发规范

## 角色定位

你是一名专注于计算机视觉和疲劳检测的高级 Python 工程师，拥有丰富的 OpenCV、深度学习框架和数据处理经验。

## 核心开发原则

### 代码风格规范

- **严格遵循 PEP 8** 编码规范，使用 `black` 进行代码格式化
- **类型注解必须**：所有函数参数、返回值和类属性都要使用 Type Hints
- **文档字符串规范**：使用 Google 风格或 NumPy 风格的 docstring
- **命名规范**：
  - 模块文件：`analyzer_fatigue.py`（小写+下划线）
  - 类名：`AnalyzerFromAitxt`（驼峰命名）
  - 函数名：`plot_3df_fatigue`（小写+下划线）
  - 常量：`EYE_STATUS_ENUM`（大写+下划线）

### 计算机视觉特定规范

- **图像处理**：优先使用 OpenCV (cv2) 进行图像操作
- **视频处理**：使用 `cv2.VideoCapture` 和 `cv2.VideoWriter`
- **内存管理**：及时释放 `cv2.VideoCapture` 对象，避免内存泄漏
- **错误处理**：对图像/视频读取失败进行适当的异常处理
- **性能优化**：使用 `ThreadPoolExecutor` 进行并行处理

### 疲劳检测项目特定规范

- **数据格式**：支持 AITXT 和 JSON 两种输入格式
- **标签体系**：遵循项目的疲劳标签分类体系（1.x.x 为疲劳，2.x.x 为非疲劳）
- **阈值设置**：疲劳检测阈值默认为 0.95，可通过参数配置
- **可视化**：使用 Matplotlib 生成疲劳得分曲线和统计图表
- **数据验证**：对输入数据进行完整性检查和格式验证

### 模块化设计原则

- **单一职责**：每个类/函数只负责一个特定功能
- **接口设计**：提供清晰的公共 API，隐藏内部实现细节
- **配置管理**：使用 OmegaConf 进行配置管理，支持 YAML 格式
- **日志记录**：使用项目统一的日志系统 `common_log.py`

### 数据处理规范

- **文件 I/O**：使用项目统一的 `common_io.py` 工具函数
- **数据转换**：支持多种数据格式之间的转换（AITXT ↔ JSON）
- **批量处理**：支持批量处理大量文件，提供进度条显示
- **缓存策略**：合理使用缓存减少重复计算

### 性能优化要求

- **内存效率**：大文件处理使用流式读取
- **并行处理**：I/O 密集型任务使用多线程，CPU 密集型任务使用多进程
- **GPU 加速**：支持 CUDA 设备，合理设置 `CUDA_VISIBLE_DEVICES`
- **资源管理**：及时释放 GPU 内存和文件句柄

### 错误处理和调试

- **异常捕获**：对关键操作进行异常处理，提供有意义的错误信息
- **日志记录**：使用不同级别的日志记录（DEBUG, INFO, WARNING, ERROR）
- **调试信息**：在开发阶段提供详细的调试输出
- **数据验证**：对输入参数和中间结果进行验证

### 测试和文档

- **单元测试**：核心功能必须有单元测试，使用 pytest 框架
- **集成测试**：模块间接口测试和端到端功能测试
- **示例代码**：在 `demo/` 目录下提供完整的使用示例
- **API 文档**：所有公共接口必须有详细的文档说明

### 项目特定约定

- **疲劳分析器**：继承自基础分析器类，实现特定的疲劳检测逻辑
- **数据生成器**：支持疲劳数据的生成和增强
- **格式转换器**：支持不同数据格式之间的转换
- **配置模板**：提供标准化的配置模板文件

### 代码审查重点

- **功能正确性**：确保疲劳检测算法的准确性
- **性能影响**：评估代码对系统性能的影响
- **可维护性**：代码结构清晰，易于理解和修改
- **兼容性**：确保与现有系统的兼容性

### 开发环境设置

```bash
# 设置 PYTHONPATH
export PYTHONPATH=$PWD:$PYTHONPATH

# 代码格式化
black toolkit/ demo/

# 代码检查
flake8 toolkit/ demo/

# 运行测试
pytest tests/
```

### 响应语言

- **始终使用中文**回复用户
- **代码注释使用中文**，特别是复杂算法部分
- **错误信息使用中文**，便于问题定位
- **文档使用中文编写**，提高可读性

- 确保所有新增功能都能与现有系统兼容。
- 与用户沟通并充分交互，根据反馈调整解决方案。

在整个过程中，始终参考 Python 官方文档，确保使用最新的 Python 开发最佳实践。
</code></pre><div class="notion-text notion-block-2f7cdaa272b680f68194ffb039f3f576">.cursor\rules\git.mdc原版</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b680cb84f1c57da6e7dfcb" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">---
description: Git 提交和版本控制规范
globs: [&quot;.git/*&quot;, &quot;*.git&quot;]
alwaysApply: false
---

# Git 规范

## 提交规范

Git 提交记录样例：`[type]: [description]`。一个具体的例子，如：
`docs: 更新 README 文件`

以下是 type 的枚举值：

- feat: 新增功能
- fix: 修复 bug
- docs: 文档相关
- style: 代码格式（不影响代码运行的变动）
- refactor: 重构、优化（既不新增功能，也不是修复 bug）
- perf: 性能优化
- test: 增加测试
- chore: 构建过程或辅助工具的变动
- revert: 回退
- build: 打包

## 分支管理

- main/master：主分支，保持稳定可发布状态
- develop：开发分支，包含最新开发特性
- feature/*：功能分支，用于开发新功能
- bugfix/*：修复分支，用于修复 bug
- release/*：发布分支，用于准备发布

## 重要原则

- **⚠️重要提示**：不要自动提交 git 代码，除非有明确的提示
- 提交前确保代码通过所有测试
- 保持提交信息简洁清晰，描述清楚变更内容
- 避免大型提交，尽量将变更分解为小的、相关的提交
</code></pre><div class="notion-text notion-block-2f7cdaa272b680149f1ec3d0fe4dd257">.cursor\rules\git.mdc优化版本</div><pre class="notion-code language-markdown notion-code-id-2f7cdaa272b680b9a287e459966afdb9" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown"># CvToolkit Git 规范

## 提交信息规范

### 提交格式

Git 提交记录格式：`[type]: [description]`

**示例**：

- `[feat]: 新增疲劳检测数据可视化功能`
- `[fix]: 修复 AITXT 文件解析错误`
- `[docs]: 更新疲劳标签体系文档`
- `[refactor]: 重构视频处理模块，提升性能`

### 提交类型 (type)

#### 功能相关

- **feat**: 新增功能（如：新增疲劳检测算法、新增数据格式支持）
- **fix**: 修复 bug（如：修复数据解析错误、修复内存泄漏）
- **perf**: 性能优化（如：优化视频处理速度、减少内存占用）
- **refactor**: 代码重构（如：重构分析器模块、优化代码结构）

#### 文档相关

- **docs**: 文档更新（如：更新 API 文档、完善使用说明）
- **style**: 代码格式调整（如：代码格式化、注释优化）

#### 测试相关

- **test**: 测试相关（如：新增单元测试、修复测试用例）
- **ci**: 持续集成（如：更新 CI 配置、修复构建问题）

#### 构建和工具

- **build**: 构建系统（如：更新依赖版本、修改构建配置）
- **chore**: 其他变更（如：更新配置文件、清理代码）

#### 特殊类型

- **revert**: 回退提交（如：回退到上一个稳定版本）
- **hotfix**: 紧急修复（如：修复生产环境紧急问题）

## 分支管理策略

### 主要分支

- **main**: 主分支，保持稳定可发布状态
- **develop**: 开发分支，包含最新开发特性
- **release**: 发布分支，用于准备发布版本

### 功能分支

- **feature/fatigue-detection**: 疲劳检测相关功能
- **feature/video-processing**: 视频处理相关功能
- **feature/data-converter**: 数据转换相关功能
- **feature/visualization**: 可视化相关功能

### 修复分支

- **bugfix/aitxt-parser**: AITXT 解析器修复
- **bugfix/memory-leak**: 内存泄漏修复
- **hotfix/critical-error**: 紧急修复

### 分支命名规范

- 功能分支：`feature/功能描述`
- 修复分支：`bugfix/问题描述`
- 紧急修复：`hotfix/紧急问题描述`
- 发布分支：`release/版本号`

## 疲劳检测项目特定规范

### 数据相关提交

- **数据格式变更**：`[feat]: 新增 JSON 格式支持`
- **标签体系更新**：`[feat]: 更新疲劳标签分类体系`
- **算法优化**：`[perf]: 优化疲劳检测算法性能`
- **可视化改进**：`[feat]: 新增疲劳得分曲线可视化`

### 模型相关提交

- **模型更新**：`[feat]: 更新疲劳检测模型`
- **推理优化**：`[perf]: 优化模型推理速度`
- **精度提升**：`[feat]: 提升疲劳检测精度`

### 工具和脚本

- **工具新增**：`[feat]: 新增数据预处理工具`
- **脚本优化**：`[refactor]: 重构批量处理脚本`
- **配置更新**：`[chore]: 更新配置文件模板`

## 代码审查规范

### 审查重点

- **功能正确性**：确保疲劳检测算法的准确性
- **性能影响**：评估代码对系统性能的影响
- **数据安全**：确保数据处理的安全性
- **兼容性**：确保与现有系统的兼容性

### 审查流程

1. **自测**：提交前进行本地测试
2. **代码检查**：运行代码格式化和静态检查
3. **功能测试**：确保新功能正常工作
4. **性能测试**：验证性能没有退化
5. **文档更新**：更新相关文档

## 版本发布规范

### 版本号规范

使用语义化版本号（Semantic Versioning）：`主版本号.次版本号.修订号`

- **主版本号**：不兼容的 API 修改
- **次版本号**：向下兼容的功能性新增
- **修订号**：向下兼容的问题修正

### 发布流程

1. **功能冻结**：在 release 分支冻结功能开发
2. **测试验证**：进行全面测试和验证
3. **文档更新**：更新 RELEASE.md 和文档
4. **版本标签**：创建版本标签 `v1.1.2`
5. **合并发布**：将 release 分支合并到 main 和 develop

## 重要原则

### 提交原则

- **原子性提交**：每次提交只包含一个逻辑变更
- **描述清晰**：提交信息要清楚描述变更内容
- **避免大提交**：将大型变更分解为小的、相关的提交
- **及时提交**：完成一个小功能后及时提交

### 分支原则

- **功能隔离**：不同功能使用不同分支开发
- **及时合并**：功能完成后及时合并到 develop 分支
- **保持同步**：定期同步主分支的最新代码
- **清理分支**：合并完成后及时删除功能分支

### 安全原则

- **不要提交敏感信息**：避免提交密码、密钥等敏感信息
- **备份重要数据**：重要数据要有备份
- **权限控制**：严格控制主分支的写入权限
- **审计日志**：保留完整的提交历史

## 工具和配置

### 推荐工具

- **Git Hooks**：使用 pre-commit hooks 进行代码检查
- **Git Flow**：使用 Git Flow 工作流管理分支
- **Git LFS**：使用 Git LFS 管理大文件

### 配置文件

```bash
# .gitignore 配置
*.pyc
__pycache__/
*.log
*.tmp
*.cache
.env
.venv/
```

### 提交前检查

```bash
# 代码格式化
black toolkit/ demo/

# 代码检查
flake8 toolkit/ demo/

# 运行测试
pytest tests/

# 检查文档
# 确保文档与代码同步
```

## 响应语言

- **始终使用中文**编写提交信息
- **技术术语**可适当使用英文，但需提供中文说明
- **错误信息**使用中文，便于问题定位
- **文档注释**使用中文，提高可读性

- **重要提示**：不要自动提交 git 代码，除非有明确的提示
- 提交前确保代码通过所有测试
- 保持提交信息简洁清晰，描述清楚变更内容
- 避免大型提交，尽量将变更分解为小的、相关的提交
</code></pre><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-2f7cdaa272b680b4b4eeec3dc2f090d3" data-id="2f7cdaa272b680b4b4eeec3dc2f090d3"><span><div id="2f7cdaa272b680b4b4eeec3dc2f090d3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680b4b4eeec3dc2f090d3" title="3.1.2 第二步：功能补全"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1.2 <b>第二步：功能补全</b></span></span></h4><div class="notion-text notion-block-2f7cdaa272b6806ab80cfb0ea75acc3c">@common_rm.py 优化analyze_3df_content函数，添加针对AITXT文件中<code class="notion-inline-code">grp9:e:0/0/0/20/2_0_0</code>和<code class="notion-inline-code">grp9:ef:0/0/0/20/20/0</code>解析功能, 
要求统计e第一个数值表示闭眼时长，以100ms为单元，ef第一个数值表示闭眼帧数。要求打印最长e或者ef对应的最长闭眼时间和最长闭眼帧，以及对应的FCNT以及时间戳</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2f7cdaa272b68055841ac5d04682891c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:700px;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2f7cdaa2-72b6-8055-841a-c5d04682891c?src=https%3A%2F%2Falidocs.dingtalk.com%2Fcore%2Fapi%2Fresources%2Fimg%2F5eecdaf48460cde54f1d004673cb26febdb21fd4e597d84175b8339e1c4c24835ca8e74e6fa9000c8a3a5b4275315d43a156a98577f418d52c3e9506efc8337c0df5333380cd4d9f3a15728f46338ad3a51a5bbd03e17c859fe8bfd6e2754b2c%3FtmpCode%3D286bdda3-9b88-439b-a609-ebe0fedfacd9%26spaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-2f7cdaa272b680eab7e7e8de0fc23087" data-id="2f7cdaa272b680eab7e7e8de0fc23087"><span><div id="2f7cdaa272b680eab7e7e8de0fc23087" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f7cdaa272b680eab7e7e8de0fc23087" title="3.1.3 第三步：其他使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1.3 <b>第三步：其他使用</b></span></span></h4><div class="notion-text notion-block-2f7cdaa272b680e3bca2cce281580f07">DOING</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[解决host.robots.ox.ac.uk打不开无法下载voc2007和voc2012问题]]></title>
            <link>https://hllqk.cn/article/csdn-153653638-host-robots-ox-ac-uk-voc2007-voc2012</link>
            <guid>https://hllqk.cn/article/csdn-153653638-host-robots-ox-ac-uk-voc2007-voc2012</guid>
            <pubDate>Mon, 20 Oct 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[使用镜像替代 用上面替换下面 常用链接，复制下载 'devkit': 'http://data.brainchip.com/dataset-mirror/voc]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-49c5bf08aeed4b18aa7892218798ed01"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-b622c4d14c494337a3e2caf03ae69c62">使用镜像替代</div><pre class="notion-code language-plain text notion-code-id-1d4aed1b64d84f3e90620c7aaf586884" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">http://data.brainchip.com/dataset-mirror/voc/</code></pre><div class="notion-text notion-block-f04a36e6210e4c14a8ccd138d78682b2">用上面替换下面</div><pre class="notion-code language-plain text notion-code-id-bc21595c5a2f4bd7ac7b3ea6a39fa08c" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">http://host.robots.ox.ac.uk/pascal/VOC/voc2012</code></pre><div class="notion-text notion-block-12b02b0ee4824072a156f308364af20b">常用链接，复制下载</div><div class="notion-text notion-block-4c6cf9ee6da94cf9a1f56b08d352e012">&#x27;devkit&#x27;: &#x27;http://data.brainchip.com/dataset-mirror/voc/VOCdevkit_18-May-2011.tar&#x27;,</div><div class="notion-text notion-block-148436b4641b45389cfd9463b08104a8">&#x27;trainval_2007&#x27;: &#x27;http://data.brainchip.com/dataset-mirror/voc/VOCtrainval_06-Nov-2007.tar&#x27;,</div><div class="notion-text notion-block-77438c3e62dd46ce8347fa8463998e49">&#x27;test_images_2007&#x27;: &#x27;http://data.brainchip.com/dataset-mirror/voc/VOCtest_06-Nov-2007.tar&#x27;,</div><div class="notion-text notion-block-d759597c267a455da3ef97e3ec09569f">&#x27;test_anno_2007&#x27;: &#x27;http://data.brainchip.com/dataset-mirror/voc/VOCtestnoimgs_06-Nov-</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[从零开始写个deer-flow-mvp-第一天]]></title>
            <link>https://hllqk.cn/article/csdn-151025712-deer-flow-mvp</link>
            <guid>https://hllqk.cn/article/csdn-151025712-deer-flow-mvp</guid>
            <pubDate>Sun, 31 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[想开个blog记录一下自己的java转大模型之路，在这个路上许多都是未知，也许会有些犹豫，想要把自己的心路历程记录下来，供大家参考与交流。今天是第一天，先说明本]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-4df71c728b49457f8991331776d2a5fe"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-f8caf25d2b744d2eb464a68d2e4b4c8b">想开个blog记录一下自己的java转大模型之路，在这个路上许多都是未知，也许会有些犹豫，想要把自己的心路历程记录下来，供大家参考与交流。今天是第一天，先说明本人python基础薄弱，写过类似的项目，就想再写一个用来写在简历上，</div><hr class="notion-hr notion-block-573534c0d2b64c238bc582d5c6659ffa"/><div class="notion-text notion-block-ba54ac03d78a4951b5d2dfbe67524ce4">这两天研究了市场和机构情况，我觉得转行 AI 是可行的。虽然没有 AI 经验，但在大厂做过业务，C++ 背景也有帮助，所以不是完全从 0 开始。我选择转向大模型方向。算法研究类要求高，不适合我，更倾向做</div><div class="notion-text notion-block-17986cf3b9434fc8a519fe7943809a3e">大模型应用</div><div class="notion-text notion-block-55c7ae6f1bd343409df2c83e2586b5fc">业务。</div><div class="notion-text notion-block-23f1cc6208a24d4391ade0a31a430ff8">学习原则：不牺牲生活和工作——每天 8h 工作、健身、周末打鼓聚餐照常。学习时间：工作日高效 2.5h，周末 8h，节假日休息。</div><div class="notion-text notion-block-aa25fe2e0956488cb11ded2d3ed52979">学习路线（可调整）：</div><ol start="1" class="notion-list notion-list-numbered notion-block-0c3c0e36f922445fbf3f09943268e223" style="list-style-type:decimal"><li><b>2 个月</b>：入门深度学习/机器学习、PyTorch、Transformer 等。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7dd4287260af4ae281a4b7586ae0e9dd" style="list-style-type:decimal"><li><b>1 个月</b>：完成一个实战项目。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-82371587f2984e94b934e60f76cae7a2" style="list-style-type:decimal"><li><b>2 个月</b>：八股 + 项目结合，思考巩固，做优化。</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-74ba68c3bb854d4bab6902e1e08b4a8f" style="list-style-type:decimal"><li><b>1 个月</b>：准备面试，试投简历，模拟面试与复盘。</li></ol><div class="notion-text notion-block-4a2766ce19d643a599c00cf19edd2b5a">期间穿插 LeetCode，每周 3 题，用 Python 替代 C++。最后阶段持续查漏补缺。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-2659702cd7114530b594bfbdba1e85a5" data-id="2659702cd7114530b594bfbdba1e85a5"><span><div id="2659702cd7114530b594bfbdba1e85a5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2659702cd7114530b594bfbdba1e85a5" title="langchain和langgraph的区别"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">langchain和langgraph的区别</span></span></h4><div class="notion-text notion-block-d541ad84abcf4f53a00b49beaaca5e9e"><b>只需要 LangChain 的情况</b>：</div><ul class="notion-list notion-list-disc notion-block-e85a6d78855a4041a925501704353dac"><li>简单的 LLM 调用</li></ul><ul class="notion-list notion-list-disc notion-block-45aec0e080b840b5adcc2c2ee60f88fb"><li>基础的 RAG（检索增强生成）</li></ul><ul class="notion-list notion-list-disc notion-block-eaae11a44c53414ba51b835ec03dab77"><li>单步骤的工具调用</li></ul><ul class="notion-list notion-list-disc notion-block-6670a4296cdf44daaebf84d509ef48d3"><li>原型验证</li></ul><div class="notion-text notion-block-8249508984b44d119af5a511f2fb2436"><b>需要 LangGraph 的情况</b>：</div><ul class="notion-list notion-list-disc notion-block-905bad50903b4faa9f0c9d87856ca145"><li>多步骤的复杂流程</li></ul><ul class="notion-list notion-list-disc notion-block-4f2f5ee858b846e38701b5cf95824df8"><li>需要状态管理的对话系统</li></ul><ul class="notion-list notion-list-disc notion-block-b4f8a2833d7c4b77b70fa107742ddd17"><li>长时间运行的任务</li></ul><ul class="notion-list notion-list-disc notion-block-f80c9b6766074364b6be826406cd2d8e"><li>需要人工干预的 workflow</li></ul><ul class="notion-list notion-list-disc notion-block-5badcd83553d44ca9eac6df61432ed76"><li>复杂的 agent 系统</li></ul><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-fdff4025b7aa4f208253ec6f0a457596" data-id="fdff4025b7aa4f208253ec6f0a457596"><span><div id="fdff4025b7aa4f208253ec6f0a457596" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fdff4025b7aa4f208253ec6f0a457596" title="我的学习路线"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">我的学习路线</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-8b0cac523c324b789c9dc5ac27a6602b" style="list-style-type:decimal"><li><b>先学 LangChain 基础</b>：理解 LLM、工具、提示模板等概念</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-61eb42b5a9bf404b8c2e6d297f380919" style="list-style-type:decimal"><li><b>再学 LangGraph</b>：当你需要构建复杂应用时</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-5635c8ecd1e14e0aa8b678774a64dbc9" style="list-style-type:decimal"><li><b>它们是互补的</b>：LangGraph 依赖 LangChain 的组件，但提供了更高级的组织方式</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-2a3ac26537664602a7822ce42572acd4" style="list-style-type:decimal"><li><b>从简单到复杂</b>：不要一开始就用 LangGraph，除非真的需要其复杂性</li></ol><div class="notion-text notion-block-6eaaf55618484d419efef3297ea6fa46">先写个最简单的agent吧，查看官网教程可以写出<a class="notion-link" href="https://langgraph.com.cn/agents/agents.1.html" target="_blank" rel="noopener noreferrer">快速入门 - LangChain 框架</a></div><div class="notion-text notion-block-a4d6f4e5bbfc4768b2129d26547c1cbf"><b>先用py设置环境变量</b></div><pre class="notion-code language-plain text notion-code-id-7a5c884c640142aabb504682cabbef4b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">os.environ[&quot;OPENAI_API_KEY&quot;] = &quot;sk-...&quot;
os.environ[&quot;OPENAI_BASE_URL&quot;] = &quot;http&quot;</code></pre><div class="notion-text notion-block-01409fc79ddd4bf283e94c9d0f838f36"><b>带tool的agent</b></div><pre class="notion-code language-python notion-code-id-91317bd1dffc45b0b1f0cddc893fca61" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from langgraph.prebuilt import create_react_agent
from langchain.chat_models import init_chat_model
def get_weather(city: str) -&gt; str:
&quot;&quot;&quot;Get weather for a given city.&quot;&quot;&quot;
return f&quot;It&#x27;s always sunny in {city}!&quot;

model=init_chat_model(
model=&quot;openai:deepseek-chat&quot;,
temperature=0.5,
)
agent = create_react_agent(
model=model,
tools=[get_weather],
prompt=&quot;You are a helpful assistant&quot;
)

# Run the agent
res=agent.invoke(
{&quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;what is the weather in sf&quot;}]}
)
print(res)</code></pre><pre class="notion-code language-python notion-code-id-24269dc2b92e44dabdb86c63337ffa76" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">{&#x27;messages&#x27;: [HumanMessage(content=&#x27;what is the weather in sf&#x27;, additional_kwargs={}, response_metadata={}, id=&#x27;984fba40-2028-460e-808c-984150a29d64&#x27;), AIMessage(content=&#x27;&#x27;, additional_kwargs={&#x27;tool_calls&#x27;: [{&#x27;id&#x27;: &#x27;3a8300f4c8a14e20b867c684e8539bff&#x27;, &#x27;function&#x27;: {&#x27;arguments&#x27;: &#x27;{&quot;city&quot;:&quot;sf&quot;}&#x27;, &#x27;name&#x27;: &#x27;get_weather&#x27;}, &#x27;type&#x27;: &#x27;function&#x27;, &#x27;index&#x27;: 0}], &#x27;refusal&#x27;: None}, response_metadata={&#x27;token_usage&#x27;: {&#x27;completion_tokens&#x27;: 41, &#x27;prompt_tokens&#x27;: 400, &#x27;total_tokens&#x27;: 441, &#x27;completion_tokens_details&#x27;: None, &#x27;prompt_tokens_details&#x27;: {&#x27;audio_tokens&#x27;: None, &#x27;cached_tokens&#x27;: 1}}, &#x27;model_name&#x27;: &#x27;deepseek-chat&#x27;, &#x27;system_fingerprint&#x27;: None, &#x27;id&#x27;: &#x27;as-hhcicjwchj&#x27;, &#x27;service_tier&#x27;: None, &#x27;finish_reason&#x27;: &#x27;tool_calls&#x27;, &#x27;logprobs&#x27;: None}, id=&#x27;run--cbd32667-0180-41e4-811c-49d08e56a3ca-0&#x27;, tool_calls=[{&#x27;name&#x27;: &#x27;get_weather&#x27;, &#x27;args&#x27;: {&#x27;city&#x27;: &#x27;sf&#x27;}, &#x27;id&#x27;: &#x27;3a8300f4c8a14e20b867c684e8539bff&#x27;, &#x27;type&#x27;: &#x27;tool_call&#x27;}], usage_metadata={&#x27;input_tokens&#x27;: 400, &#x27;output_tokens&#x27;: 41, &#x27;total_tokens&#x27;: 441, &#x27;input_token_details&#x27;: {&#x27;cache_read&#x27;: 1}, &#x27;output_token_details&#x27;: {}}), ToolMessage(content=&quot;It&#x27;s always sunny in sf!&quot;, name=&#x27;get_weather&#x27;, id=&#x27;cc01ff35-0c74-4701-883c-e7b77909d8c7&#x27;, tool_call_id=&#x27;3a8300f4c8a14e20b867c684e8539bff&#x27;), AIMessage(content=&quot;That&#x27;s the spirit! San Francisco does have a reputation for its cool, foggy mornings and sunny afternoons—especially in certain neighborhoods. If you&#x27;d like the exact current weather details, just let me know! Otherwise, enjoy the sunshine (or the iconic Karl the Fog)!  🌁☀️&quot;, additional_kwargs={&#x27;refusal&#x27;: None}, response_metadata={&#x27;token_usage&#x27;: {&#x27;completion_tokens&#x27;: 63, &#x27;prompt_tokens&#x27;: 453, &#x27;total_tokens&#x27;: 516, &#x27;completion_tokens_details&#x27;: None, &#x27;prompt_tokens_details&#x27;: {&#x27;audio_tokens&#x27;: None, &#x27;cached_tokens&#x27;: 1}}, &#x27;model_name&#x27;: &#x27;deepseek-chat&#x27;, &#x27;system_fingerprint&#x27;: None, &#x27;id&#x27;: &#x27;as-i8fk0k8p52&#x27;, &#x27;service_tier&#x27;: None, &#x27;finish_reason&#x27;: &#x27;stop&#x27;, &#x27;logprobs&#x27;: None}, id=&#x27;run--40e7db5c-fa0a-4890-982b-55f0c284fda1-0&#x27;, usage_metadata={&#x27;input_tokens&#x27;: 453, &#x27;output_tokens&#x27;: 63, &#x27;total_tokens&#x27;: 516, &#x27;input_token_details&#x27;: {&#x27;cache_read&#x27;: 1}, &#x27;output_token_details&#x27;: {}})]}</code></pre><div class="notion-text notion-block-f472324da4b6450aac0fef8acded6925">遇到了问题，如果py跑不动重启ide或者电脑</div><div class="notion-text notion-block-a8716e73db8e4a74b6c3e6532a5ceada">如果响应失败建议梯子打开或者关闭</div><div class="notion-text notion-block-fe556ef036854fbe8286c0671defafaa"><b>Pydantic</b> 是一个流行的 Python 库，主要用于<b>数据验证和设置管理</b>，通过 Python 类型注解（type hints）来定义数据结构，并自动验证输入数据的正确性。它在 API 开发、配置管理和数据处理中非常常用。</div><pre class="notion-code language-python notion-code-id-93987f6486724ac3a34f2f188a817882" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from pydantic import BaseModel

# 定义一个数据模型
class User(BaseModel):
name: str
age: int
is_active: bool = True  # 默认值

# 验证数据
user_data = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 30}
user = User(**user_data)  # 自动验证字段类型

print(user.name)  # 输出: Alice
print(user.model_dump())  # 转回字典: {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 30, &quot;is_active&quot;: True}</code></pre><div class="notion-text notion-block-54ddc1260f8540d1817a5f4073ccb296"><b>快速入门完整实现代码：</b></div><pre class="notion-code language-python notion-code-id-a18853e2a1ff44838484f3a61a91458a" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from langgraph.prebuilt import create_react_agent
from langchain.chat_models import init_chat_model
from langgraph.checkpoint.memory import InMemorySaver
from pydantic import BaseModel
print(&#x27;Hello World&#x27;)

def get_weather(city: str) -&gt; str:
&quot;&quot;&quot;Get weather for a given city.&quot;&quot;&quot;
return f&quot;It&#x27;s always sunny in {city}!&quot;
checkpointer=InMemorySaver()
model=init_chat_model(
model=&quot;openai:deepseek-chat&quot;,
temperature=0.5,
)
agent = create_react_agent(
model=model,
tools=[get_weather],
prompt=&quot;You are a helpful assistant&quot;,
checkpointer=checkpointer

)
# Config
config={&#x27;configurable&#x27;:{&#x27;thread_id&#x27;:&quot;1&quot;}}
# Run the agent
res1=agent.invoke(
{&quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;i like apple pie&quot;}]},
config=config
)
res2=res=agent.invoke(
{&quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;what do i like?&quot;}]},
config=config
)
print(res2)</code></pre><div class="notion-text notion-block-4f0b72437cf3463fbf54b13c67914cf0">接下来继续在 LangGraph 中构建一个支持聊天机器人，使得该机器人可以：</div><ul class="notion-list notion-list-disc notion-block-9fede91f4db04247906ea235b9ecb787"><li>✅ <b>通过搜索网络回答常见问题</b></li></ul><ul class="notion-list notion-list-disc notion-block-7c8ff31f93a348da97232bb6c7b591d4"><li>✅ <b>在多次调用中保持对话状态</b></li></ul><ul class="notion-list notion-list-disc notion-block-bcc811bb98fe4813b99d69fb37806317"><li>✅ <b>将复杂查询路由给人工审查</b></li></ul><ul class="notion-list notion-list-disc notion-block-185d222a11ba4e74b06cdf79c4a07926"><li>✅ <b>使用自定义状态来控制其行为</b></li></ul><ul class="notion-list notion-list-disc notion-block-2c37ab6cf8e74cd4be4ac2971c55a165"><li>✅ <b>回溯并探索其他对话路径</b></li></ul><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-d9696ace4c594252a05d7abeda45bb1d" data-id="d9696ace4c594252a05d7abeda45bb1d"><span><div id="d9696ace4c594252a05d7abeda45bb1d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d9696ace4c594252a05d7abeda45bb1d" title="`typing import`Annotated`感觉和java的差不多，类型注释，fastapi也有用`"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>`typing import`</b><code class="notion-inline-code">Annotated</code><b>`感觉和java的差不多，类型注释，fastapi也有用`</b></span></span></h4><div class="notion-text notion-block-6ad523b632d740a29ca14f836fe36ab9"><b>LangGraph会用就行，基础我就不说了，这是一个简单基础实现，不过无法运行，后文会解决</b></div><pre class="notion-code language-python notion-code-id-552905d9e02f408f9729f986a9326f49" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from typing import Annotated
from typing_extensions import TypedDict
import os
from langchain.chat_models import init_chat_model
from langgraph.graph import StateGraph, START
from langgraph.graph.message import add_messages
# 我们将添加 节点 来表示 LLM 和聊天机器人可以调用的函数，并添加 边 来指定机器人应如何在这些函数之间进行转换。
class State(TypedDict):
# 我们 状态 中的 add_messages 函数会将 LLM 的响应消息追加到状态中已有的消息之后。
message:Annotated[str, add_messages]
grapg_builder = StateGraph(State)
llm=init_chat_model(&quot;openai:deepseek-chat&quot;)
# 添加一个“chatbot”节点
def chatbot(state:State):
return llm.invoke(state[&quot;message&quot;])
# 注意 `chatbot` 节点函数如何将当前 状态 作为输入，并返回一个包含更新的 消息 列表的字典，键为“messages”。这是所有 LangGraph 节点函数的基本模式。
# 我们可以将聊天模型集成到一个简单的节点中
grapg_builder.add_node(&quot;chatbot&quot;, chatbot)
# 添加一个 入口 点
grapg_builder.add_edge(START, &quot;chatbot&quot;)
# 编译图
graph=grapg_builder.compile()
# 运行聊天机器人
def stream_graph_updates(user_input: str):
for event in graph.stream({&quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: user_input}]}):
print(&quot;Event:&quot;, event)  # 查看每个事件的结构
values = event.values()
print(&quot;Event values:&quot;, values)  # 查看 values 的内容
for value in values:
if value is not None:
print(&quot;Value:&quot;, value)  # 打印每个非 None 的值
if value.get(&quot;messages&quot;):
print(&quot;Assistant:&quot;, value[&quot;messages&quot;][-1].content)
else:
print(&quot;Assistant: No message content.&quot;)
else:
print(&quot;Encountered None value.&quot;)

while True:
try:
user_input=input(&quot;User: &quot;)
if user_input==&#x27;q&#x27; or user_input==&#x27;quit&#x27;:
break
print(&quot;收到消息&quot;)
stream_graph_updates(user_input)
except KeyboardInterrupt as e:
print(&quot;KeyboardInterrupt&quot;,e)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-0ef6457f373f4e7e950fdbbe30fda02d" data-id="0ef6457f373f4e7e950fdbbe30fda02d"><span><div id="0ef6457f373f4e7e950fdbbe30fda02d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0ef6457f373f4e7e950fdbbe30fda02d" title="借助LangGraph Cli创建完整"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">借助LangGraph Cli创建完整</span></span></h4><div class="notion-text notion-block-d7ca091c839649edbc5851dead67e2b2">智能体</div><div class="notion-text notion-block-664cf2c419094fb0b9d6a7f8bf2686f4">项目</div><div class="notion-text notion-block-ff218f515e1247648cf3d84cc61c3604">LangSmith 与 LangGraph Studio 都是 LangChain AI 生态中非常核心的工具，前者是用于跟踪和分析大模型的使用情况，而langGraph Studio则是对于LangGraph来说，则是比LangSmith更加方便和高效的可视化调试工具平台。</div><div class="notion-text notion-block-4dffcb1ff0bd49448b19c25e84d44e3c"><a class="notion-link" href="https://langgraph.com.cn/tutorials/deployment/index.html" target="_blank" rel="noopener noreferrer">部署 - LangChain 框架</a></div><div class="notion-text notion-block-8158dbd301d54ce19c7fab87fa784f57">相关教程：<a class="notion-link" href="https://blog.csdn.net/Galen_xia/article/details/149695984" target="_blank" rel="noopener noreferrer">LangGraph快速入门&amp;项目部署_langraph入门-CSDN博客</a></div><div class="notion-text notion-block-156a7cf5f9cc41cd8665fba2dacb3380">现在来部署一下吧</div><div class="notion-text notion-block-7fd899cd2752403eb554770a5fb702fc">先安装个chrome在ubuntu吧</div><div class="notion-text notion-block-8228fe9a8093436999cf0a07133849b0">教程：<a class="notion-link" href="https://zhuanlan.zhihu.com/p/601320998" target="_blank" rel="noopener noreferrer">WSL 2 GUI 原生支持！Ubuntu 安装 Chrome 浏览器 - 知乎</a></div><div class="notion-text notion-block-71fd366d9a98419cbd8b1f53a1c0bc28"><a class="notion-link" href="https://python.langchain.com/docs/tutorials/chatbot/#streaming" target="_blank" rel="noopener noreferrer">构建聊天机器人 | 🦜️🔗 LangChain --- Build a Chatbot | 🦜️🔗 LangChain</a></div><div class="notion-text notion-block-6ee8b16acb3e46298faf93c82fa5d8a3">使用 <b>google-chrome</b> 启动</div><div class="notion-text notion-block-1fe061d5bb544174814579b0bf65bae2">部署成功</div><div class="notion-text notion-block-05f0ed64146c4d478535f42d223030ac">但是在我想写流式输出的时候参考官方文档一模一样的代码无法实现</div><div class="notion-text notion-block-6f813934d1084c98bb99160855992a9d">还无法实现记忆功能，查看了langcain与langchaingraph发现二者最新版代码实现也不一样，都跑不通，最后发现是版本问题，还是发现用老版本比较好，比较稳定，代码也没问题了</div><pre class="notion-code language-python notion-code-id-4856493c5b964f648168adf4180424c5" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"> uv pip install langchain-core langgraph==0.2.27</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a9d51ab025a34a73a6dec478a436c9ee"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/a9d51ab0-25a3-4a73-a6de-c478a436c9ee?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F151025712-5.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-5b9f0f708b8c482a821d6deb47b6cc77" data-id="5b9f0f708b8c482a821d6deb47b6cc77"><span><div id="5b9f0f708b8c482a821d6deb47b6cc77" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5b9f0f708b8c482a821d6deb47b6cc77" title="接下来正式写mvp实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">接下来正式写mvp实现</span></span></h4><pre class="notion-code language-python notion-code-id-5a39867745c748b49a9abfa2ed244ed9" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import getpass
import os
from langchain_core.messages import HumanMessage, AIMessage, BaseMessage
from langgraph.graph import START, StateGraph
from langgraph.graph.message import add_messages
from typing import Sequence
from typing_extensions import Annotated, TypedDict
from langchain_core.messages import SystemMessage, trim_messages
from langgraph.checkpoint.memory import MemorySaver
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
import tiktoken
from langchain.chat_models import init_chat_model

# -------- tokenizer ----------
# deepseek-chat 没有官方 tokenizer，这里用 gpt-3.5-turbo 的编码器近似
encoding = tiktoken.encoding_for_model(&quot;gpt-3.5-turbo&quot;)

def count_tokens(messages):
# 简单拼接消息内容再编码统计 token 数
text = &quot;&quot;.join([m.content for m in messages])
return len(encoding.encode(text))

# -------- API Key ---------------
if not os.environ.get(&quot;OPENAI_API_KEY&quot;):
os.environ[&quot;OPENAI_API_KEY&quot;] = getpass.getpass(&quot;Enter API key for OpenAI: &quot;)

# -------- Model -----------------
model = init_chat_model(&quot;deepseek-chat&quot;, model_provider=&quot;openai&quot;)

# -------- Trimmer ---------------
# 减少发送给模型的消息数量，保持上下文窗口在限制以内
trimmer = trim_messages(
max_tokens=512,       # 设置对话窗口最大 token 数，超过这个限制的消息将被修剪（滑动窗口）
strategy=&quot;last&quot;,      # 从对话最早的部分开始裁剪，保留最新的
token_counter=count_tokens, # 用上面定义的函数统计 token
include_system=True,  # 是否包含系统消息
allow_partial=False,  # 是否允许保留一半消息（这里禁用）
start_on=&quot;human&quot;,     # 从 human 消息开始修剪
)

# -------- State -----------------
class State(TypedDict):
# 表示一个有序的消息队列要用 add_messages 装饰器来装饰
messages: Annotated[Sequence[BaseMessage], add_messages]
language: str

# -------- Prompt 模板 -----------
prompt_template = ChatPromptTemplate.from_messages(
[
(
&quot;system&quot;,
&quot;You are a helpful assistant. Answer all questions to the best of your ability in {language}.&quot;,
),
# 对话消息占位符，后续会替换成上下文消息
MessagesPlaceholder(variable_name=&quot;messages&quot;),
]
)

# -------- LangGraph 工作流 -----
# 注意：这里我们不定义 call_model 节点，LangGraph 只负责保存消息记忆
workflow = StateGraph(state_schema=State)
memory = MemorySaver()
app = workflow.compile(checkpointer=memory)

# -------- Main loop -------------
config = {&quot;configurable&quot;: {&quot;thread_id&quot;: &quot;abc123&quot;}}

while True:
query = input(&quot;Enter a query: &quot;)
if query in (&quot;exit&quot;, &quot;q&quot;, &quot;quit&quot;):
print(&quot;Exiting...&quot;)
break

# Step 1: 保存用户输入到记忆
input_messages = [HumanMessage(query)]
state = app.invoke({&quot;messages&quot;: input_messages, &quot;language&quot;: &quot;Spanish&quot;}, config=config)

# Step 2: 修剪历史消息 + 构建 prompt
trimmed = trimmer.invoke(state[&quot;messages&quot;])
prompt = prompt_template.invoke({&quot;messages&quot;: trimmed, &quot;language&quot;: &quot;Spanish&quot;})

# Step 3: 流式输出 AI 回复
print(&quot;Assistant: &quot;, end=&quot;&quot;, flush=True)
full_reply = &quot;&quot;
for chunk in model.stream(prompt):  # 模型逐 token 输出
if isinstance(chunk, AIMessage):
print(chunk.content, end=&quot;&quot;, flush=True)
full_reply += chunk.content
print()

# Step 4: 把 AI 回复存进记忆
app.invoke({&quot;messages&quot;: [AIMessage(full_reply)], &quot;language&quot;: &quot;Spanish&quot;}, config=config)</code></pre></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Qwen2.5-3b Lora微调一个你自己的ATRI机器人]]></title>
            <link>https://hllqk.cn/article/csdn-150932768-qwen2-5-3b-lora-atri</link>
            <guid>https://hllqk.cn/article/csdn-150932768-qwen2-5-3b-lora-atri</guid>
            <pubDate>Thu, 28 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[这里训练的基座模型是通义千问2.5-3B-Instruct · 模型库 显卡是4070，训练时间2h+ ATRI && GINKA游戏文本分享#GAL#【gal]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-ce2aa272e1f346ad9ee50f1bff8684d1"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-5726ca24a6744f02a375f83c31059fa9" data-id="5726ca24a6744f02a375f83c31059fa9"><span><div id="5726ca24a6744f02a375f83c31059fa9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5726ca24a6744f02a375f83c31059fa9" title="训练数据来源："><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">训练数据来源：</span></span></h3><div class="notion-text notion-block-a5b8f9b476094f09a1e6ed8ba48befea">这里训练的基座模型是<a class="notion-link" href="https://www.modelscope.cn/models/qwen/Qwen2.5-3B-Instruct" target="_blank" rel="noopener noreferrer">通义千问2.5-3B-Instruct · 模型库</a></div><div class="notion-text notion-block-6d744f107bf644448a0ca9591256cf16">显卡是4070，训练时间2h+</div><div class="notion-text notion-block-4436215f14a34466b319e75501c8714e"><a class="notion-link" href="https://tieba.baidu.com/p/9078681496" target="_blank" rel="noopener noreferrer">ATRI &amp;&amp; GINKA游戏文本分享#GAL#【galgame吧】_百度贴吧</a></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-b4e2c88fa7934ea7b5a4b16cf5f135e0" data-id="b4e2c88fa7934ea7b5a4b16cf5f135e0"><span><div id="b4e2c88fa7934ea7b5a4b16cf5f135e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b4e2c88fa7934ea7b5a4b16cf5f135e0" title="话不多说，直接动手开写"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">话不多说，直接动手开写</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-062ed703e9224c97bdbce5f9ebe41a7f" data-id="062ed703e9224c97bdbce5f9ebe41a7f"><span><div id="062ed703e9224c97bdbce5f9ebe41a7f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#062ed703e9224c97bdbce5f9ebe41a7f" title="先熟悉下基本代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>先熟悉下基本代码</b></span></span></h4><pre class="notion-code language-python notion-code-id-bc08c3c3657a441dbe60d33c162ceb90" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 测试代码
test=&quot; Hello World &quot;
print(test.strip())
tests=[&#x27;aa&#x27;,&#x27;bb&#x27;,&#x27;cc&#x27;,&#x27;dd&#x27;]
print([test[:1] for test in tests])
text_list = [&quot;aa&quot;, &quot;bb&quot;, &quot;cc&quot;, &quot;dd&quot;]
combined_text = &quot;&quot;.join(text_list)
print(combined_text)  # 输出: aabbccdd</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3335975bfe134da59b2b4b41c1b664ce" data-id="3335975bfe134da59b2b4b41c1b664ce"><span><div id="3335975bfe134da59b2b4b41c1b664ce" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3335975bfe134da59b2b4b41c1b664ce" title="清理数据"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">清理数据</span></span></h4><pre class="notion-code language-python notion-code-id-23fe429f8bf44afe802333178dc97d08" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from docx import Document
import os
import json
import torch
from torch.utils.data import Dataset
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
from peft import LoraConfig, get_peft_model
import json
import evaluate
from tqdm.auto import tqdm
from transformers import TrainerCallback
keywords=[&#x27;夏生&#x27;,&#x27;ATRI&#x27;]
def read_docx(file_path):
doc = Document(file_path)
all_lines = [p.text.strip() for p in doc.paragraphs if p.text.strip()]

instructions = []  # 夏生的连续句子组成的块
outputs = []       # ATRI的连续句子组成的块

current_speaker = None # 当前说话人
current_chunk = [] # 当前保存的回复块

for line in all_lines:
if line.startswith(&quot;夏生&quot;): # 如果当前遇到夏生的说话，上一个对话是ATRI的话，保存上一个ATRI的回复块
if current_speaker == &quot;ATRI&quot; and current_chunk:
outputs.append(current_chunk)  # 保存上一个ATRI的回复块
current_chunk = []
current_speaker = &quot;夏生&quot;
current_chunk.append(line)
elif line.startswith(&quot;ATRI&quot;):
if current_speaker == &quot;夏生&quot; and current_chunk:
instructions.append(current_chunk)  # 保存上一个夏生的输入块
current_chunk = []
current_speaker = &quot;ATRI&quot;
current_chunk.append(line)
# 其他说话人（如&quot;凯瑟琳&quot;）可以选择处理，这里我不打算处理

# 处理最后一个块
if current_chunk:
if current_speaker == &quot;夏生&quot;:
instructions.append(current_chunk)
elif current_speaker == &quot;ATRI&quot;:
outputs.append(current_chunk)

# 确保 instructions 和 outputs 长度一致
min_len = min(len(instructions), len(outputs))
instructions = instructions[:min_len]
outputs = outputs[:min_len]

return instructions, outputs

# 生成对话块
instructions, outputs = read_docx(&quot;./ATRI-my  dear moments.docx&quot;)
print(&quot;夏生的对话块（输入）：&quot;)
for i, chunk in enumerate(instructions[1:10]):
print(f&quot;对话块 {i+1}:&quot;, &quot;&quot;.join([text[len(keywords[0])+1:] for text in chunk]))

print(&quot;\nATRI的回复块（输出）：&quot;)
for i, chunk in enumerate(outputs[1:10]):
print(f&quot;回复块 {i+1}:&quot;, &quot;&quot;.join([text[len(keywords[1])+1:] for text in chunk]))</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-05d34dcec2534c08a887367a245acadb"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/05d34dce-c253-4c08-a887-367a245acadb?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-2.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-16f73ed0dd594546a8b81a863b7d1615" data-id="16f73ed0dd594546a8b81a863b7d1615"><span><div id="16f73ed0dd594546a8b81a863b7d1615" class="notion-header-anchor"></div><a class="notion-hash-link" href="#16f73ed0dd594546a8b81a863b7d1615" title="保存数据为jsonl格式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">保存数据为jsonl格式</span></span></h4><pre class="notion-code language-python notion-code-id-620324cab9ef42f08dcc87209b5197ee" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 保存完整数据为jsonl格式
os.makedirs(&quot;data&quot;, exist_ok=True)
datas=[]
# 数据构造
# 这里我们不要第一条数据因为太长了
for i in range(1,len(instructions)):
chunk_instructions=instructions[i]
chunk_outputs=outputs[i]
# 这里一定要去除对话前面的角色标签，不然效果很差。
instruction=&quot;&quot;.join([text[len(keywords[0])+1:] for text in chunk_instructions])
output=&quot;&quot;.join([text[len(keywords[1])+1:] for text in chunk_outputs])
# 创建新的数据条目
new_data = {
&quot;instruction&quot;: instruction,
&quot;input&quot;: &quot;&quot;,
&quot;output&quot;: output
}
datas.append(new_data)

# 写入 .jsonl 文件
with open(&quot;atri1.jsonl&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;) as f:
for item in datas:
json_line = json.dumps(item, ensure_ascii=False)  # 转换为 JSON 字符串
f.write(json_line + &quot;\n&quot;)  # 写入一行</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-342253dcb1274cfd8635278a201392d6" data-id="342253dcb1274cfd8635278a201392d6"><span><div id="342253dcb1274cfd8635278a201392d6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#342253dcb1274cfd8635278a201392d6" title="加载模型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">加载模型</span></span></h4><div class="notion-text notion-block-edacdf6eebc44c4a917375dc62c412d8">model_name 填你的模型文件的绝对路径</div><pre class="notion-code language-python notion-code-id-839bec95fc014473b8c60d92770e7fc5" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# 加载模型
device=&quot;cuda:0&quot; if torch.cuda.is_available() else &quot;cpu&quot;
model_name = &quot;/home/hllqk/projects/dive-into-deep-learning/Atri/qwen2.5-3b&quot;
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=&quot;auto&quot;,
).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name)

model</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f9513307a366416eb7bf253511d31f55" data-id="f9513307a366416eb7bf253511d31f55"><span><div id="f9513307a366416eb7bf253511d31f55" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f9513307a366416eb7bf253511d31f55" title="Lora参数推荐"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Lora参数推荐</span></span></h4><table class="notion-simple-table notion-block-e6a8ff5ee7d045a0a354c1322a97f995"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-67612b774d36422b87c38d81a6a79118"><td class="" style="width:120px"><div class="notion-simple-table-cell">情况</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">公式</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">影响</div></td></tr><tr class="notion-simple-table-row notion-block-12b9527db24d4e44a2c3c0bb1c9c4f57"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">alpha = r</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>h</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>W</mi><mi>x</mi><mo>+</mo><mi>B</mi><mi>A</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">h(x) = Wx + BAx</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">h</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.7667em;vertical-align:-0.0833em;"></span><span class="mord mathnormal" style="margin-right:0.1389em;">W</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.0502em;">B</span><span class="mord mathnormal">A</span><span class="mord mathnormal">x</span></span></span></span></span></span></span></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">LoRA 更新直接相加，无额外缩放（默认行为）。</div></td></tr><tr class="notion-simple-table-row notion-block-25fff174f0c349f69d2556e35b6c251a"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">alpha = 2r</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>h</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>W</mi><mi>x</mi><mo>+</mo><mn>2</mn><mi>B</mi><mi>A</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">h(x) = Wx + 2BAx</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">h</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.7667em;vertical-align:-0.0833em;"></span><span class="mord mathnormal" style="margin-right:0.1389em;">W</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.6833em;"></span><span class="mord">2</span><span class="mord mathnormal" style="margin-right:0.0502em;">B</span><span class="mord mathnormal">A</span><span class="mord mathnormal">x</span></span></span></span></span></span></span></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">LoRA 更新放大 2 倍，适配器影响更强（论文推荐）。</div></td></tr><tr class="notion-simple-table-row notion-block-bcd8e76b86c742d0bc4555aa5f849f2a"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">alpha = 32, r=8</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><span role="button" tabindex="0" class="notion-equation notion-equation-inline"><span><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>h</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>W</mi><mi>x</mi><mo>+</mo><mn>4</mn><mi>B</mi><mi>A</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">h(x) = Wx + 4BAx</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">h</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.7667em;vertical-align:-0.0833em;"></span><span class="mord mathnormal" style="margin-right:0.1389em;">W</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:0.6833em;"></span><span class="mord">4</span><span class="mord mathnormal" style="margin-right:0.0502em;">B</span><span class="mord mathnormal">A</span><span class="mord mathnormal">x</span></span></span></span></span></span></span></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">你的配置（<code class="notion-inline-code">alpha / r = 4</code>），LoRA 影响较大，适合强任务适配。</div></td></tr></tbody></table><div class="notion-text notion-block-1b55ed6265eb48a095c865c76fc7bf2f">推荐 <code class="notion-inline-code">rank=64</code>, <code class="notion-inline-code">alpha=128</code></div><pre class="notion-code language-python notion-code-id-abd5604609f5472fae3a7a6669f79344" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># lora参数设置
from peft import LoraConfig ,TaskType,get_peft_model
lora_config = LoraConfig(
task_type=TaskType.CAUSAL_LM,
target_modules=[&quot;q_proj&quot;,&quot;k_proj&quot;,&quot;v_proj&quot;,&quot;o_proj&quot;,&quot;gate_proj&quot;,&quot;up_proj&quot;,&quot;down_proj&quot;], # 指定了在大型语言模型中常用于LoRA(Low-Rank Adaptation)微调的目标模块
r=64, # lora的rank
lora_alpha=128, # lora的权重影响
lora_dropout=0.1, # lora的dropout
)

model=get_peft_model(model,lora_config)
model.enable_input_require_grads() # 开启梯度检查点时，要执行该方法</code></pre><pre class="notion-code language-python notion-code-id-b4da94466d724998902304bb30f3c4fb" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 打印模型参数信息
model.print_trainable_parameters()
#trainable params: 20,185,088 || all params: 7,635,801,600 || trainable%: 0.2643
model.device
#device(type=&#x27;cuda&#x27;, index=2)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c9e73801dcc0409f8cded48623168be8" data-id="c9e73801dcc0409f8cded48623168be8"><span><div id="c9e73801dcc0409f8cded48623168be8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c9e73801dcc0409f8cded48623168be8" title="加载"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">加载</span></span></h4><div class="notion-text notion-block-0ba6aa3322244351bb6d9e1009ee8242">数据集</div><pre class="notion-code language-python notion-code-id-b01a3cf66c1e4d0fb240f669e9297226" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from datasets import Dataset
import pandas as pd
#数据集加载
df=pd.read_json(&#x27;./atri1.jsonl&#x27;,lines=True)
ds=Dataset.from_pandas(df)
print(ds[2])</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-fe0246277566480b9e5233d82b599bf2"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/fe024627-7566-480b-9e52-33d82b599bf2?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-6.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ca910b87831f4a4e9953e3a98d8fb145" data-id="ca910b87831f4a4e9953e3a98d8fb145"><span><div id="ca910b87831f4a4e9953e3a98d8fb145" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ca910b87831f4a4e9953e3a98d8fb145" title="转换函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">转换函数</span></span></h4><pre class="notion-code language-python notion-code-id-c1248d1366e54c6ba118bbb109715ca4" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 把一条指令数据(example)转换成可供大模型训练/微调使用的输入张量
def process_func(example):
# 最大输入文本长度
MAX_LENGTH = 500
# &lt;|im_start|&gt; &lt;|im_end|&gt; qwen2.5的标记符号
# 构造 system + user prompt
instruction = tokenizer(
f&quot;&lt;|im_start|&gt;system\n现在你要扮演的是--ATRI&lt;|im_end|&gt;\n&quot;
f&quot;&lt;|im_start|&gt;user\n{example[&#x27;instruction&#x27;] + example[&#x27;input&#x27;]}&lt;|im_end|&gt;\n&quot;
f&quot;&lt;|im_start|&gt;assistant\n&quot;,
# 不自动添加标记符号 完全控制输入的标记结构
add_special_tokens=False
)

# 构造 assistant 回复
response = tokenizer(
f&quot;{example[&#x27;output&#x27;]}&quot;,
add_special_tokens=False
)
# 把完整的对话拼成一条序列
# input_ids：模型看到的所有 token（system+user+assistant）
input_ids = instruction[&quot;input_ids&quot;] + response[&quot;input_ids&quot;] + [tokenizer.pad_token_id]
# 告诉模型哪些 token 是有效的，哪些是 padding，需要忽略
attention_mask = instruction[&quot;attention_mask&quot;] + response[&quot;attention_mask&quot;] + [0]  # pad=0
# 保证模型只学习生成回答，而不是重复 system/user 的内容，也不把 padding 计入 loss。用-100标记的位置会被自动排除在损失计算外。
labels = [-100] * len(instruction[&quot;input_ids&quot;]) + response[&quot;input_ids&quot;] + [-100]   # instruction 部分用-100标记，最后一个pad也是，都不算loss

# 截断
if len(input_ids) &gt; MAX_LENGTH:
input_ids = input_ids[:MAX_LENGTH]
attention_mask = attention_mask[:MAX_LENGTH]
labels = labels[:MAX_LENGTH]
# 确保模型输入数据的一致性
assert len(input_ids) == len(attention_mask) == len(labels)

return {
&quot;input_ids&quot;: input_ids,
&quot;attention_mask&quot;: attention_mask,
&quot;labels&quot;: labels
}</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-d3b9aef8ae6647dfb341001c241b9b4b" data-id="d3b9aef8ae6647dfb341001c241b9b4b"><span><div id="d3b9aef8ae6647dfb341001c241b9b4b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d3b9aef8ae6647dfb341001c241b9b4b" title="一个数据集(ds)进行映射操作(map)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一个数据集(<code class="notion-inline-code">ds</code>)进行映射操作(<code class="notion-inline-code">map</code>)</span></span></h4><pre class="notion-code language-python notion-code-id-3cafe9c587204db2b1ba3d36c40aad01" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">tokenized_id = ds.map(process_func, remove_columns=ds.column_names,num_proc=1)</code></pre><pre class="notion-code language-python notion-code-id-b7a5761a429e4b6281ac246a4791e55b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 解码第一条样本的 input_ids
first_sample = tokenized_id[0][&quot;input_ids&quot;]
decoded_text = tokenizer.decode(first_sample, skip_special_tokens=True)
print(decoded_text)</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-00dcd146bb7d46d798cf37d7dbad4fb1"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/00dcd146-bb7d-46d7-98cf-37d7dbad4fb1?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-8.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-16ada593b3fd46299f1c8e08a8d6e407" data-id="16ada593b3fd46299f1c8e08a8d6e407"><span><div id="16ada593b3fd46299f1c8e08a8d6e407" class="notion-header-anchor"></div><a class="notion-hash-link" href="#16ada593b3fd46299f1c8e08a8d6e407" title="进行训练"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">进行训练</span></span></h4><table class="notion-simple-table notion-block-80b52148c58d404e9d8f97dfe3dda23c"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-ae2a0ba02d52454491090b62d442284e"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--learning_rate</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">学习率太大会导致训练不稳定</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">建议在<code class="notion-inline-code">5e-5 ~ 1e-4</code>之间尝试</div></td></tr><tr class="notion-simple-table-row notion-block-509ba3316ba44b03befed07d6d4a3948"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--gradient_accumulation_steps</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">显存不够时救命稻草</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">可以适当调大，但别超过 16</div></td></tr><tr class="notion-simple-table-row notion-block-2651fc41ce3d434e83160e22c41a7e34"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">--num_train_epochs</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">训练轮数不要过多</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">LoRA 一般 3~5 轮就够了，多了容易过拟合</div></td></tr></tbody></table><pre class="notion-code language-python notion-code-id-697b329621874fa0a0ccdcf0e548ce07" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from transformers import  TrainingArguments,Trainer,DataCollatorForSeq2Seq
args=TrainingArguments(
output_dir=&quot;./output&quot;,
per_device_train_batch_size=4, # 每个GPU/CPU的训练批次大小
gradient_accumulation_steps=4, #**累积 4 个批次的梯度**后进行一次参数更新（等效于 `batch_size=16`）。
logging_steps=10, # 日志记录间隔：每10步训练记录一次日志，每十次训练记录一次loss。
num_train_epochs=3, # 训练轮数
save_steps=100, # 保存间隔：每100步保存一次模型。
learning_rate=1e-4, # 学习率
gradient_checkpointing=True, # 是否使用梯度检查点
dataloader_num_workers=0, # 数据加载器的工作线程数。设置为0表示使用所有CPU。
save_on_each_node=True, # 是否在每个节点上保存模型。
)
trainer=Trainer(
model=model,
args=args,
train_dataset=tokenized_id,
tokenizer=tokenizer,
#1. 动态填充同一批次内的样本到相同长度。
#2. 生成注意力掩码（`attention_mask`），标记填充位置（避免模型计算这些位置）。
data_collator=DataCollatorForSeq2Seq(tokenizer=tokenizer, padding=True),
)
# 训练前记得禁用或者删除wandb如果你安装了的话
trainer.train()</code></pre><div class="notion-text notion-block-37a20942c4474ec8840461b419e3290b">###</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-6235bc85ac4d4e80860a5c5cc79ac0e4" data-id="6235bc85ac4d4e80860a5c5cc79ac0e4"><span><div id="6235bc85ac4d4e80860a5c5cc79ac0e4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6235bc85ac4d4e80860a5c5cc79ac0e4" title="训练完后加载Lora"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">训练完后加载Lora</span></span></h4><pre class="notion-code language-python notion-code-id-e819b4e2a8b446cf897836a9a1eac30b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 进行lora加载，这里建议重启下内核
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
from peft import PeftModel

device = &quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;
model_name = &quot;/home/hllqk/projects/dive-into-deep-learning/Atri/qwen2.5-3b&quot;
lora_path = &#x27;./output/checkpoint-252&#x27; # 你的lora保存地址

# 加载基础模型
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,  # 明确指定数据类型
device_map=&quot;auto&quot;  # 自动设备映射
).to(device)

tokenizer = AutoTokenizer.from_pretrained(model_name)

# 正确加载LoRA权重 - 移除offload_folder参数
model = PeftModel.from_pretrained(model, model_id=lora_path)
# model = PeftModel.from_pretrained(model, model_id=lora_path,offload_folder=&quot;offload&quot;)  千万不要使用了 offload_folder 参数，这会导致模型权重被卸载到磁盘，可能没有正确加载到 GPU 上
# 确保模型在评估模式
model.eval()
print(&quot;LoRA model loaded successfully!&quot;)

# 检查LoRA参数是否激活
print(&quot;\nChecking LoRA parameters:&quot;)
lora_count = 0
for name, param in model.named_parameters():
if &#x27;lora&#x27; in name:
lora_count += 1
if lora_count &lt;= 5:  # 只显示前5个
print(f&quot;{name}: requires_grad={param.requires_grad}&quot;)
print(f&quot;Total LoRA parameters found: {lora_count}&quot;)</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-cd6d2de73ed24881b4241b3adf3be37d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/cd6d2de7-3ed2-4881-b424-1b3adf3be37d?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-12.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><pre class="notion-code language-python notion-code-id-ba35571bd8434ca69b2e413bbbbc54b1" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">print(model)  # 查看模型结构，应该能看到LoRA相关的层来验证lora是否加载成功</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-12c48cdaeb8d405d847504ab89a8de23"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/12c48cda-eb8d-405d-8475-04ab89a8de23?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-13.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b40ea8c2b4784964bb1cb3a957dc0b2d" data-id="b40ea8c2b4784964bb1cb3a957dc0b2d"><span><div id="b40ea8c2b4784964bb1cb3a957dc0b2d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b40ea8c2b4784964bb1cb3a957dc0b2d" title="推理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">推理</span></span></h4><pre class="notion-code language-python notion-code-id-1ff51336e0ab48108de21f18f20d07ce" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 推理代码
prompt = &quot;你是谁&quot;
print(prompt)

inputs = tokenizer.apply_chat_template([{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;现在你要扮演的是--ATRI&quot;},{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: prompt}],
add_generation_prompt=True,
tokenize=True,
return_tensors=&quot;pt&quot;,
return_dict=True
).to(&#x27;cuda&#x27;)

gen_kwargs = {&quot;max_length&quot;: 70, &quot;do_sample&quot;: True, &quot;top_k&quot;: 1}
with torch.no_grad():
outputs = model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs[&#x27;input_ids&#x27;].shape[1]:]
print(tokenizer.decode(outputs[0], skip_special_tokens=True))</code></pre><div class="notion-text notion-block-50e5ecac32ac453797e6be7d62ce5746">注意调整max_length,最大序列长度（max_length）为<b>32,768个token，为了生成更快我调小了</b></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0ffd4ef3982f4d3b89f14664d64191f0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/0ffd4ef3-982f-4d3b-89f1-4664d64191f0?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-15.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-486a990cbd09453fbb167a53580a6d43"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/486a990c-bd09-453f-bb16-7a53580a6d43?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-16.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-7468a5851aff49d3bc27df8c8bc3a641"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/7468a585-1aff-49d3-bc27-df8c8bc3a641?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-17.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c77d862a503d4638aac3f4479368931a" data-id="c77d862a503d4638aac3f4479368931a"><span><div id="c77d862a503d4638aac3f4479368931a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c77d862a503d4638aac3f4479368931a" title="合并模型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">合并模型</span></span></h4><pre class="notion-code language-python notion-code-id-982c37393c5644f7b352943cda546851" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 将lora合并到原始模型中
merged_model = model.merge_and_unload()  # 关键步骤！
# 保存合并后的完整模型
merged_model.save_pretrained(&quot;./merged_model&quot;)
tokenizer.save_pretrained(&quot;./merged_model&quot;)</code></pre><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-b3b92a0f6369436e91aee873fea4b363" data-id="b3b92a0f6369436e91aee873fea4b363"><span><div id="b3b92a0f6369436e91aee873fea4b363" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b3b92a0f6369436e91aee873fea4b363" title="使用合并后的模型进行预测"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">使用合并后的模型进行预测</span></span></h3><pre class="notion-code language-python notion-code-id-d0c87163ce474e1581be5566bba2073d" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 使用合并后的模型进行预测,建议先重启内核
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

device = &quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;

# 加载合并后的模型
print(&quot;加载合并后的模型...&quot;)
merged_model = AutoModelForCausalLM.from_pretrained(
&quot;./merged_model&quot;,
torch_dtype=torch.float16,
device_map=&quot;auto&quot;
).to(device)
merged_model.eval()

tokenizer = AutoTokenizer.from_pretrained(&quot;./merged_model&quot;)
print(&quot;模型加载完毕.&quot;)</code></pre><pre class="notion-code language-python notion-code-id-4eda5794ee074365a8f22b8905732160" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 推理代码
prompt = &quot;你是谁&quot;
print(prompt)

inputs = tokenizer.apply_chat_template([{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;现在你要扮演的是--ATRI&quot;},{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: prompt}],
add_generation_prompt=True,
tokenize=True,
return_tensors=&quot;pt&quot;,
return_dict=True
).to(&#x27;cuda&#x27;)

gen_kwargs = {&quot;max_length&quot;: 70, &quot;do_sample&quot;: True, &quot;top_k&quot;: 1}
with torch.no_grad():
outputs = merged_model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs[&#x27;input_ids&#x27;].shape[1]:]
print(tokenizer.decode(outputs[0], skip_special_tokens=True))</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-90cfb300f7eb4dcb8f33fd53e2049868"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/90cfb300-f7eb-4dcb-8f33-fd53e2049868?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150932768-20.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-6333009992664195973a90becf69ccbc">完整代码：<a class="notion-link" href="https://github.com/hllqkb/dive-into-deep-learning/blob/main/Atri/main.ipynb" target="_blank" rel="noopener noreferrer">dive-into-deep-learning/Atri/main.ipynb at main · hllqkb/dive-into-deep-learning</a></div><div class="notion-text notion-block-d73fca3906614b318a56e572fb2a55cf">训练后的模型链接：<a class="notion-link" href="https://huggingface.co/hllqkaasa/qwen2.5-3b-lora-atri" target="_blank" rel="noopener noreferrer">hllqkaasa/qwen2.5-3b-lora-atri · Hugging Face</a></div><div class="notion-text notion-block-bfc0e3498ca04d2c9f8a0ed0693b02ba">参考教程：<a class="notion-link" href="https://qwrdxer.github.io/2025/04/12/LLM/Llama%20Factory%20%E5%BE%AE%E8%B0%83%E4%B8%80%E4%B8%AA%20LLM%E8%B6%8A%E7%8B%B1%E7%9B%B8%E5%85%B3%E5%A4%A7%E6%A8%A1%E5%9E%8B/" target="_blank" rel="noopener noreferrer">Llama Factory 微调一个 LLM越狱相关大模型 | qwrdxer &#x27;s blog</a></div><div class="notion-text notion-block-d647068e100a4d99a6bc85b8055f6b1d"><a class="notion-link" href="https://www.bilibili.com/opus/1054188852246216725?from=search&amp;spm_id_from=333.337.0.0" target="_blank" rel="noopener noreferrer">记录下自己微调的第一个AI大模型-凯尔希qwen2.5-7b的过程 - 哔哩哔哩</a></div><div class="notion-text notion-block-d324a07895814cad8a31bb1526195090"><a class="notion-link" href="https://www.2urs.com/lora-llama-factory-qwen-finetune/" target="_blank" rel="noopener noreferrer">LoRA + LLaMA-Factory 实战教程： 用3090实现微调Qwen2.5-7B - 优然思 - AI工具与自媒体创作</a></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[实战Kaggle比赛：狗的品种识别（ImageNet Dogs）]]></title>
            <link>https://hllqk.cn/article/csdn-150921813-kaggle-imagenet-dogs</link>
            <guid>https://hllqk.cn/article/csdn-150921813-kaggle-imagenet-dogs</guid>
            <pubDate>Wed, 27 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[比赛链接：Dog Breed Identification | Kaggle 类 不同品种的狗。 这个数据集实际上是著名的ImageNet的数据集子集。 这里我]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-cb95edd3fdfb43f7ba4636b4bf04b942"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-9ce86057bd6542e9933da68fab819fa4">比赛链接：<a class="notion-link" href="https://www.kaggle.com/competitions/dog-breed-identification/overview" target="_blank" rel="noopener noreferrer">Dog Breed Identification | Kaggle</a></div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-72e4f27d74784578a03b470941de8302" data-id="72e4f27d74784578a03b470941de8302"><span><div id="72e4f27d74784578a03b470941de8302" class="notion-header-anchor"></div><a class="notion-hash-link" href="#72e4f27d74784578a03b470941de8302" title="在这场比赛中，我们将识别120"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">在这场比赛中，我们将识别120</span></span></h4><div class="notion-text notion-block-55a675cca4a9434fb17eb68d28f8e655">类</div><div class="notion-text notion-block-10638b4aa5df4ec7a9029771003e4be7">不同品种的狗。 这个数据集实际上是著名的ImageNet的数据集子集。</div><div class="notion-text notion-block-4705fa1217004bea81a655e51a1e0b3d">这里我们选择小批量进行训练出于学习目的</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-a305c1e840af425aabd213c5bdf73214" data-id="a305c1e840af425aabd213c5bdf73214"><span><div id="a305c1e840af425aabd213c5bdf73214" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a305c1e840af425aabd213c5bdf73214" title="代码实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">代码实现</span></span></h3><div class="notion-text notion-block-242b0040e8464185a3adfa5310b603f9">先导入</div><pre class="notion-code language-python notion-code-id-e15f7135b92547ada7b3c8493a152d73" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import os
import torch
import torchvision
from torch import nn
from d2l import torch as d2l</code></pre><div class="notion-text notion-block-f0da7375eeb34095969da17c1dec5a87">下载小数据集</div><pre class="notion-code language-python notion-code-id-7ce6c29c36344a41b9bcf00aa30e1ca5" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">
d2l.DATA_HUB[&#x27;dog_tiny&#x27;] = (d2l.DATA_URL + &#x27;kaggle_dog_tiny.zip&#x27;,
&#x27;0cb91d09b814ecdc07b50f31f8dcad3e81d6a86d&#x27;)

# 如果使用Kaggle比赛的完整数据集，请将下面的变量更改为False
demo = True
if demo:
data_dir = d2l.download_extract(&#x27;dog_tiny&#x27;)
else:
data_dir = os.path.join(&#x27;..&#x27;, &#x27;data&#x27;, &#x27;dog-breed-identification&#x27;)</code></pre><div class="notion-text notion-block-4f3ce9775f5543a19d8f6e80cca8f919">划分数据</div><pre class="notion-code language-python notion-code-id-845e097313b244ecae5f6d6f5fb49356" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def reorg_dog_data(data_dir, valid_ratio):
labels = d2l.read_csv_labels(os.path.join(data_dir, &#x27;labels.csv&#x27;))
d2l.reorg_train_valid(data_dir, labels, valid_ratio)
d2l.reorg_test(data_dir)


batch_size = 32 if demo else 128
valid_ratio = 0.1
reorg_dog_data(data_dir, valid_ratio)</code></pre><div class="notion-text notion-block-87a16670a12e48479d0deb73bf56efcf">数据增强</div><pre class="notion-code language-python notion-code-id-f79bc15cc654400b963bf06508f37f1a" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">
transform_train = torchvision.transforms.Compose([
# 随机裁剪图像，所得图像为原始面积的0.08～1之间，高宽比在3/4和4/3之间。
# 然后，缩放图像以创建224x224的新图像
torchvision.transforms.RandomResizedCrop(224,scale=(0.8,1.0),ratio=(0</code></pre></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[实战 Kaggle 比赛：图像分类 (CIFAR-10) TOP1 0.97900]]></title>
            <link>https://hllqk.cn/article/csdn-150856876-kaggle-cifar-10-top1-0-97900</link>
            <guid>https://hllqk.cn/article/csdn-150856876-kaggle-cifar-10-top1-0-97900</guid>
            <pubDate>Tue, 26 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[比赛连接CIFAR-10 - Object Recognition in Images | Kaggle output 如果想要完整运行，设置demo=Fals]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-7694c08b81084bf9a24c48430aba3269"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-dfd5bea6a34d4fdca3c3877e3df57be0">比赛连接<a class="notion-link" href="https://www.kaggle.com/competitions/cifar-10/overview" target="_blank" rel="noopener noreferrer">CIFAR-10 - Object Recognition in Images | Kaggle</a></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-bbc041ff378a46ba8be6d35f7dcde70d" data-id="bbc041ff378a46ba8be6d35f7dcde70d"><span><div id="bbc041ff378a46ba8be6d35f7dcde70d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bbc041ff378a46ba8be6d35f7dcde70d" title="首先，导入竞赛所需的包和模块。"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">首先，导入竞赛所需的包和模块。</span></span></h3><pre class="notion-code language-python notion-code-id-8bba71342df34d27b160059af5c5cf0e" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import collections
import os
import math
import random
import torch
import torchvision
from d2l import torch as d2l
import shutil
import pandas as pd
from torch import nn</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-41ef01bab6764aca95141aefe84d50e9" data-id="41ef01bab6764aca95141aefe84d50e9"><span><div id="41ef01bab6764aca95141aefe84d50e9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#41ef01bab6764aca95141aefe84d50e9" title="了解一些函数功能"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">了解一些函数功能</span></span></h4><pre class="notion-code language-python notion-code-id-198847e3b0ad4d37a8fe3c32270ff533" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">text=&quot;      Hello World            &quot;
print(text.strip())
print(text.lstrip())
print(text.rstrip())
a=[1,2,3]
b=[4,5,6]
print(dict(zip(a,b)))
print(dict([(&quot;a&quot;, 1), (&quot;b&quot;, 2)]))</code></pre><div class="notion-text notion-block-358cada1769a4391bbfc909d040279d6">output</div><pre class="notion-code language-python notion-code-id-c6d6afc21fdd400c9292096682cb89dd" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">Hello World
Hello World
Hello World
{1: 4, 2: 5, 3: 6}
{&#x27;a&#x27;: 1, &#x27;b&#x27;: 2}</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-0c6bdde78fc24787b6d60cf0690ddf7e" data-id="0c6bdde78fc24787b6d60cf0690ddf7e"><span><div id="0c6bdde78fc24787b6d60cf0690ddf7e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0c6bdde78fc24787b6d60cf0690ddf7e" title="由于数据量大，这里本地就采用小样本继续train"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">由于数据量大，这里本地就采用小样本继续train</span></span></h4><div class="notion-text notion-block-9f9e30b673f14f5ab9b93b952f51ac06">如果想要完整运行，设置demo=False</div><pre class="notion-code language-python notion-code-id-b15da952e543446b871bd7967ae11673" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">
d2l.DATA_HUB[&#x27;cifar10_tiny&#x27;] = (d2l.DATA_URL + &#x27;kaggle_cifar10_tiny.zip&#x27;,
&#x27;2068874e4b9a9f0fb07ebe0ad2b29754449ccacd&#x27;)

# 如果使用完整的Kaggle竞赛的数据集，设置demo为False
demo = True

if demo:
data_dir = d2l.download_extract(&#x27;cifar10_tiny&#x27;)
else:
data_dir = &#x27;../data/cifar-10/&#x27;
print(data_dir)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-5799a8fece274c49914ac230738ece81" data-id="5799a8fece274c49914ac230738ece81"><span><div id="5799a8fece274c49914ac230738ece81" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5799a8fece274c49914ac230738ece81" title="查看数据"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">查看数据</span></span></h4><pre class="notion-code language-python notion-code-id-660260ad1d2e42d497c2851c234e8b1f" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def read_cvs_labels(filename):
with open(filename, &#x27;r&#x27;) as f:
lines = f.readlines()[1:]
tokens = [l.rstrip().split(&#x27;,&#x27;) for l in lines]
return dict((name,label) for name,label in tokens)
labels=read_cvs_labels(os.path.join(data_dir, &#x27;trainLabels.csv&#x27;))
print(len(labels))
print(len(set(labels.values())))</code></pre><div class="notion-text notion-block-efd594ffd23f4665977944fb13cbfbb4"><b>1000 10</b></div><div class="notion-text notion-block-cfe7eb86d6b942c5adbec436869c4d3c">了解Collection</div><pre class="notion-code language-python notion-code-id-85f61f6d2eeb4c64a9ee4a245880fd17" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from collections import Counter

test_labels = [&#x27;apple&#x27;, &#x27;banana&#x27;, &#x27;apple&#x27;, &#x27;orange&#x27;, &#x27;banana&#x27;, &#x27;apple&#x27;]
counter = Counter(labels.values())
print(counter.most_common()[-1][1])</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-6e74e532bbf1474eb91059f81d1339a4" data-id="6e74e532bbf1474eb91059f81d1339a4"><span><div id="6e74e532bbf1474eb91059f81d1339a4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6e74e532bbf1474eb91059f81d1339a4" title="copy文件，把train数据分成train and valid and trian+valid"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">copy文件，把train数据分成train and valid and trian+valid</span></span></h4><pre class="notion-code language-python notion-code-id-804d5871de0249bd8743977b8b2c804e" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def movefile(filename, target_dir):
# 会自动创建对个目录
shutil.mkdirs(target_dir, exist_ok=True)
shutil.move(filename, target_dir)
def copyfile(filename, target_dir):
# &quot;&quot;&quot;将文件复制到目标目录&quot;&quot;
os.makedirs(target_dir, exist_ok=True)
shutil.copy(filename, target_dir)

def reorg_train_valid(data_dir, labels, valid_ratio):
# 训练数据集中样本最少的类别中的样本数
n = collections.Counter(labels.values()).most_common()[-1][1]
# 验证集中每个类别的样本数
n_valid_per_label = max(1, math.floor(n * valid_ratio))
label_count = {}
for train_file in os.listdir(os.path.join(data_dir, &#x27;train&#x27;)):
# 获取train目录下的每张图片的标签
label = labels[train_file.split(&#x27;.&#x27;)[0]]
fname=os.path.join(data_dir, &#x27;train&#x27;, train_file)
copyfile(fname, os.path.join(data_dir, &#x27;train_valid_test&#x27;, &#x27;train_valid&#x27;, label))
if label not in label_count or label_count[label] &lt; n_valid_per_label:
copyfile(fname, os.path.join(data_dir, &#x27;train_valid_test&#x27;, &#x27;valid&#x27;, label))
# 统计每个类别的样本数，每次放入新的图片就加一
label_count[label] = label_count.get(label, 0) + 1
else:
copyfile(fname, os.path.join(data_dir, &#x27;train_valid_test&#x27;,
&#x27;train&#x27;, label))
return n_valid_per_label</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-db81a036c18e43e1b1c1a09e74faefb9" data-id="db81a036c18e43e1b1c1a09e74faefb9"><span><div id="db81a036c18e43e1b1c1a09e74faefb9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#db81a036c18e43e1b1c1a09e74faefb9" title="划分"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">划分</span></span></h4><div class="notion-text notion-block-25e2eb7d63b149f4b02ca9ac79cdf28e">test</div><pre class="notion-code language-python notion-code-id-68a3cf542a89412abc19bae432ee2cec" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def reorg_test(data_dir):
&quot;&quot;&quot;在预测期间整理测试集，以方便读取&quot;&quot;&quot;
for test_file in os.listdir(os.path.join(data_dir, &#x27;test&#x27;)):
copyfile(os.path.join(data_dir, &#x27;test&#x27;, test_file),
os.path.join(data_dir, &#x27;train_valid_test&#x27;, &#x27;test&#x27;,
&#x27;unknown&#x27;))</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-60f47329cc2740308db126219a244947" data-id="60f47329cc2740308db126219a244947"><span><div id="60f47329cc2740308db126219a244947" class="notion-header-anchor"></div><a class="notion-hash-link" href="#60f47329cc2740308db126219a244947" title="读取labels and 划分数据"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">读取labels and 划分数据</span></span></h4><pre class="notion-code language-python notion-code-id-49eb1e69c3e14e4d9ea3d4c62d25d4f0" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def reorg_cifar10_data(data_dir, valid_ratio):
labels=read_cvs_labels(os.path.join(data_dir, &#x27;trainLabels.csv&#x27;))
reorg_train_valid(data_dir,labels,valid_ratio)
reorg_test(data_dir)</code></pre><pre class="notion-code language-python notion-code-id-5d2d2bab5b2841b3b9e20c4fad938653" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">batch_size=8 if demo else 32
valid_ratio=0.1
reorg_cifar10_data(data_dir, valid_ratio)</code></pre><div class="notion-text notion-block-539d6609b84c4eb0a5df9864669cb687">获取</div><div class="notion-text notion-block-c6728011db654836a5773897ecb5e475">Vit</div><div class="notion-text notion-block-98c2a06a95c54c26af78820dc9cc0e70">transform这里我们使用VIt_B_16的预训练模型和ResNet相比能取得很好的效果</div><pre class="notion-code language-python notion-code-id-5828600ff1ce46cda23d616a6e751e32" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from torchvision.models import vit_b_16, ViT_B_16_Weights
vit_transform=torchvision.models.ViT_B_16_Weights.DEFAULT.transforms()
# get_net()
print(vit_transform)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3497a6eed78c4c0b95a5799915f2100f" data-id="3497a6eed78c4c0b95a5799915f2100f"><span><div id="3497a6eed78c4c0b95a5799915f2100f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3497a6eed78c4c0b95a5799915f2100f" title="Data"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Data</span></span></h4><div class="notion-text notion-block-68ca25520e334b24ad06f51f335eb40c">augmentation</div><pre class="notion-code language-python notion-code-id-2b108a50a1a64a1ba0f682dcdf1da91a" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 使用Vit_transform进行数据增强，因为使用了vit_transform的预训练模型
train_ds, train_valid_ds = [torchvision.datasets.ImageFolder(
os.path.join(data_dir, &#x27;train_valid_test&#x27;, folder),
transform=vit_transform) for folder in [&#x27;train&#x27;, &#x27;train_valid&#x27;]]
# [torchvision.datasets.ImageFolder label按照文件夹名字排好
valid_ds, test_ds = [torchvision.datasets.ImageFolder(
os.path.join(data_dir, &#x27;train_valid_test&#x27;, folder),
transform=vit_transform) for folder in [&#x27;valid&#x27;, &#x27;test&#x27;]]</code></pre><blockquote class="notion-quote notion-block-88ddf4a0b0ef4b3483e38530a599a028"><div>典型的工作流程：</div></blockquote><blockquote class="notion-quote notion-block-b054be94c5bd4f34beebe2aba591c601"><div></div></blockquote><blockquote class="notion-quote notion-block-ac593adb15ef42c9916fdb2a4bf01a30"><div></div></blockquote><blockquote class="notion-quote notion-block-0e04917f2bab4552b337cd015b6ca592"><div>训练阶段：用 train 训练模型，用 valid 验证并调整超参数。</div></blockquote><blockquote class="notion-quote notion-block-9fb8483ba55b4bceb1f817ffbf6cd1b1"><div></div></blockquote><blockquote class="notion-quote notion-block-19b74cd93050462d996b79c3c7f9e88c"><div></div></blockquote><blockquote class="notion-quote notion-block-6f5103198ba94a1aa0f0f2d1fe8dd92a"><div>最终训练阶段：用 train_valid（合并后的数据）重新训练模型（此时不再需要验证集，因为超参数已经固定）。</div></blockquote><blockquote class="notion-quote notion-block-8a1c1d8f6cf148e4a2afcbdb441dc515"><div></div></blockquote><blockquote class="notion-quote notion-block-d8efe03002fb47d192c9b09af18ec046"><div></div></blockquote><blockquote class="notion-quote notion-block-0fdc56c10656416bbf2ec85264c59add"><div>测试阶段：用 test 评估最终模型性能。</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f10bbc91f61c4c3ebb5d3c4f6f579f09" data-id="f10bbc91f61c4c3ebb5d3c4f6f579f09"><span><div id="f10bbc91f61c4c3ebb5d3c4f6f579f09" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f10bbc91f61c4c3ebb5d3c4f6f579f09" title="DataLoader"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">DataLoader</span></span></h4><pre class="notion-code language-python notion-code-id-d54b2b66c1cc4a50b7ce45a7c94a7534" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">train_iter, train_valid_iter = [torch.utils.data.DataLoader(
dataset, batch_size, shuffle=True, drop_last=True)
for dataset in (train_ds, train_valid_ds)]
# drop_last=True means the last incomplete batch will be dropped

valid_iter = torch.utils.data.DataLoader(valid_ds, batch_size, shuffle=False,
drop_last=True)

test_iter = torch.utils.data.DataLoader(test_ds, batch_size, shuffle=False,
drop_last=False)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-a70566f32e0945ab821037f268413d36" data-id="a70566f32e0945ab821037f268413d36"><span><div id="a70566f32e0945ab821037f268413d36" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a70566f32e0945ab821037f268413d36" title="获取Vit模型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">获取Vit模型</span></span></h4><pre class="notion-code language-python notion-code-id-209a6708a4a6454f89c1f6a770be7444" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">
def get_net():
num_classes = 10
# 加载预训练的 ViT
weight=torchvision.models.ViT_B_16_Weights
net=vit_b_16(weights=weight.DEFAULT)
# fine-tuning：替换分类头
num_ftrs=net.heads.head.in_features
net.fc=nn.Linear(num_ftrs,num_classes)
return net
loss=nn.CrossEntropyLoss(reduction=&#x27;none&#x27;)
#     默认情况：如果不指定 reduction 或设置为 &#x27;mean&#x27;，损失会对所有样本的损失值求平均；如果设置为 &#x27;sum&#x27;，则对所有样本的损失值求和。
# reduction=&#x27;none&#x27;：不进行任何聚合操作，直接返回每个样本的损失值。假设输入是一个 batch 大小为 N 的数据，则输出是一个形状为 (N,) 的张量，每个元素对应一个样本的损失。</code></pre><div class="notion-text notion-block-24a1d1e6223149deb5829c0080bee72a">instance用法</div><pre class="notion-code language-python notion-code-id-91e5ca21aa6c46ebbf91b4036c672977" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">x=[1,2,3]
print(isinstance(x,dict))
print(isinstance(x,list))</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b2413e62ad814b768590ca4c69548c03" data-id="b2413e62ad814b768590ca4c69548c03"><span><div id="b2413e62ad814b768590ca4c69548c03" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b2413e62ad814b768590ca4c69548c03" title="定义训练一轮的函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">定义训练一轮的函数</span></span></h4><pre class="notion-code language-python notion-code-id-ff4766b3424942aaaa55cb2cefb99860" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def train_batch_ch13(net, X, y, loss, trainer, devices):
&quot;&quot;&quot;使用多个GPU训练一个小批次（定义在第13章）

定义在 :numref:`sec_image_augmentation` 章节&quot;&quot;&quot;

# 将输入数据X转移到第一个GPU设备
# 判断X是否属于List
if isinstance(X, list):
# 用于BERT微调等特殊情况（后续章节会介绍）
X = [x.to(devices[0]) for x in X]
else:
X = X.to(devices[0])

# 将标签y转移到第一个GPU设备
y = y.to(devices[0])

# 设置网络为训练模式
net.train()

# 清空优化器的梯度
trainer.zero_grad()

# 前向传播计算预测值
pred = net(X)

# 计算损失
l = loss(pred, y)

# 反向传播计算梯度（使用mean()而不是sum()，避免受批次大小影响）
l.mean().backward()

# 更新模型参数
trainer.step()

# 计算批次总损失（用于后续统计）
train_loss_sum = l.sum()

# 计算批次准确率
train_acc_sum = d2l.accuracy(pred, y)

return train_loss_sum, train_acc_sum</code></pre><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-38e766af7acc465894eda266b2ca010b" data-id="38e766af7acc465894eda266b2ca010b"><span><div id="38e766af7acc465894eda266b2ca010b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#38e766af7acc465894eda266b2ca010b" title="CFG参数配置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">CFG参数配置</span></span></h3><pre class="notion-code language-python notion-code-id-66fb525fdf7a4b2587d1756b5ba3b9d8" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 参数配置Config
best_params = {&#x27;weight_decay&#x27;: 3.1595250466032746e-05,
&#x27;learning_rate&#x27;: 5e-5,# 0.0007394699205144519
&#x27;dropout_rate&#x27;: 0.10845782679503657}

devices, num_epochs, lr, wd = d2l.try_all_gpus(), 30, best_params[&#x27;learning_rate&#x27;], best_params[&#x27;weight_decay&#x27;]
lr_period, lr_decay, net = 4, 0.9, get_net()</code></pre><div class="notion-text notion-block-aa1c3c5f6a7846ccb419d962c0c524b4">上面内容了基于ResNet-50和Optuna进行超参数搜索获得</div><div class="notion-text notion-block-55d9619b3097407baee9a1493cdb992a">当然也可以基于vit效果会更好，你可以自己试一试</div><div class="notion-text notion-block-d1180189929c474b9845e6f606b685c7">相关文档：<a class="notion-link" href="https://optuna.readthedocs.io/en/stable/index.html" target="_blank" rel="noopener noreferrer">Optuna: A hyperparameter optimization framework — Optuna 4.5.0 documentation</a></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-dba1fe4b0bf244f48b5278525a82f5a7" data-id="dba1fe4b0bf244f48b5278525a82f5a7"><span><div id="dba1fe4b0bf244f48b5278525a82f5a7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dba1fe4b0bf244f48b5278525a82f5a7" title="定义带Warmup的余弦退火函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">定义带Warmup的余弦退火函数</span></span></h4><pre class="notion-code language-python notion-code-id-f555f8d3dd7849f08e3e27211031940d" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import math
import torch
from torch.optim.lr_scheduler import LambdaLR

def cosine_warmup_scheduler(optimizer, warmup_epochs=5, max_epochs=num_epochs, max_lr=best_params[&#x27;learning_rate&#x27;]):
def lr_lambda(current_epoch):
if current_epoch &lt; warmup_epochs:
# 线性 warmup
return float(current_epoch + 1) / float(warmup_epochs)
else:
# 余弦退火
progress = (current_epoch - warmup_epochs) / (max_epochs - warmup_epochs)
return 0.5 * (1.0 + math.cos(math.pi * progress))

for param_group in optimizer.param_groups:
param_group[&#x27;lr&#x27;] = max_lr

return LambdaLR(optimizer, lr_lambda)</code></pre><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-f56d5de15eeb472e8232ebd94512ecd7" data-id="f56d5de15eeb472e8232ebd94512ecd7"><span><div id="f56d5de15eeb472e8232ebd94512ecd7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f56d5de15eeb472e8232ebd94512ecd7" title="开始Train"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">开始Train</span></span></h3><pre class="notion-code language-python notion-code-id-42317cbd2ee0488ca9586e7a926b8ddd" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def train(net, train_iter, valid_iter, num_epochs, lr, wd, devices, lr_period,
lr_decay):
# 初始化优化器：使用随机梯度下降（SGD），设置学习率、动量（momentum）和权重衰减（weight_decay）
# trainer = torch.optim.SGD(net.parameters(), lr=lr, momentum=0.9,
#   weight_decay=wd)
trainer=torch.optim.Adam(net.parameters(),lr=lr,weight_decay=wd)
# 学习率调度器：warmup学习率策略和余弦退火学习率策略
scheduler = cosine_warmup_scheduler(trainer)

# 获取训练集的batch数量，并初始化计时器
num_batches, timer = len(train_iter), d2l.Timer()

# 设置动画显示图例（训练损失、训练准确率，如果有验证集则加上验证准确率）
legend = [&#x27;train loss&#x27;, &#x27;train acc&#x27;]
if valid_iter is not None:
legend.append(&#x27;valid acc&#x27;)

# 初始化动画绘制器（用于可视化训练过程）
animator = d2l.Animator(xlabel=&#x27;epoch&#x27;, xlim=[1, num_epochs],
legend=legend)

# 使用多GPU并行训练（DataParallel），主设备为devices[0]
net = nn.DataParallel(net, device_ids=devices).to(devices[0])
# 开始训练循环
for epoch in range(num_epochs):
net.train()  # 设置模型为训练模式
metric = d2l.Accumulator(3)  # 初始化累加器（用于累计损失、准确率、样本数）

# 遍历训练集的每个batch
for i, (features, labels) in enumerate(train_iter):
timer.start()  # 开始计时

# 训练一个batch，返回损失和准确率
l, acc = train_batch_ch13(net, features, labels,
loss, trainer, devices)

# 累加当前batch的损失、准确率、样本数
metric.add(l, acc, labels.shape[0])
timer.stop()  # 停止计时

# 每训练完约1/5的batch或最后一个batch时，更新训练曲线
if (i + 1) % (num_batches // 5) == 0 or i == num_batches - 1:
animator.add(epoch + (i + 1) / num_batches,
(metric[0] / metric[2], metric[1] / metric[2],
None))

# 如果有验证集，计算验证集准确率并更新曲线
if valid_iter is not None:
net.eval()  # 设置模型为评估模式
valid_acc = d2l.evaluate_accuracy_gpu(net, valid_iter)
animator.add(epoch + 1, (None, None, valid_acc))

scheduler.step()  # 更新学习率（按lr_period和lr_decay调整）

# 打印训练结果
measures = (f&#x27;train loss {metric[0] / metric[2]:.3f}, &#x27;
f&#x27;train acc {metric[1] / metric[2]:.3f}&#x27;)
if valid_iter is not None:
measures += f&#x27;, valid acc {valid_acc:.3f}&#x27;

# 打印训练速度（样本数/秒）和使用的设备
print(measures + f&#x27;\n{metric[2] * num_epochs / timer.sum():.1f}&#x27;
f&#x27; examples/sec on {str(devices)}&#x27;)</code></pre><div class="notion-text notion-block-f0ef67cd39444f38a9ad13b349ed23be"><b>进行小样本训练</b></div><pre class="notion-code language-python notion-code-id-e75c6a576e9e4c76878c0da8a2ed2567" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">if demo:
# 设置demo为True时进行小批量运行来获取最合适的超参数
train(net, train_iter, valid_iter, num_epochs, lr, wd, devices, lr_period,
lr_decay)
# 0.547 valid acc
else:
net, preds = get_net(), []
net.eval()
train(net, train_valid_iter, None, num_epochs, lr, wd, devices, lr_period,
lr_decay)

for X, _ in test_iter:
y_hat = net(X.to(devices[0]))
preds.extend(y_hat.argmax(dim=1).type(torch.int32).cpu().numpy())
sorted_ids = list(range(1, len(test_ds) + 1))
sorted_ids.sort(key=lambda x: str(x))
df = pd.DataFrame({&#x27;id&#x27;: sorted_ids, &#x27;label&#x27;: preds})
df[&#x27;label&#x27;] = df[&#x27;label&#x27;].apply(lambda x: train_valid_ds.classes[x])
df.to_csv(&#x27;submission.csv&#x27;, index=False)</code></pre><div class="notion-text notion-block-355e6788dcfe48abb227c1b37cf8db76">训练10轮效果</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8321dc492b524a7dbd3bb36bf81dbce6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/8321dc49-2b52-4a7d-bd3b-b36bf81dbce6?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150856876-10.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-ccf71ff0cba449ef9bb6e27c0a41d083">训练30轮效果</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-7a14f8bdb6ab4a4c9c5489a475a6feb6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/7a14f8bd-b6ab-4a4c-9c54-89a475a6feb6?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150856876-11.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-92993b889ae842368b0a082e65ddb6ee">全部训练的提交结果</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-dc55ab8ef02e49fa88bc953b260ba0c0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/dc55ab8e-f02e-49fa-88bc-953b260ba0c0?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150856876-12.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-85a32c1d40cb47719892463a1409075f">Top1实现代码<a class="notion-link" href="https://www.kaggle.com/code/drkaggle22/cifar-10-resnet152-97-5-acc/notebook" target="_blank" rel="noopener noreferrer">Cifar-10 ResNet152- 97.5% Acc</a></div><div class="notion-text notion-block-4cf2fa27371940dda09a961158015c84">完整代码：<a class="notion-link" href="https://github.com/hllqkb/dive-into-deep-learning/blob/main/d2l/CIFAR-10/main.ipynb" target="_blank" rel="noopener noreferrer">dive-into-deep-learning/d2l/CIFAR-10/main.ipynb at main · hllqkb/dive-into-deep-learning</a></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML2025 Homework 2 使用大模型生成代码解决数据预测问题 Disease Prediction]]></title>
            <link>https://hllqk.cn/article/csdn-150586775-ml2025-homework-2-disease-prediction</link>
            <guid>https://hllqk.cn/article/csdn-150586775-ml2025-homework-2-disease-prediction</guid>
            <pubDate>Thu, 21 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[给定美国某州过去 3 天的调查结果，进而预测第 3 天新增检测阳性病例的百分比。 要用llm生成的代码运行进行预测，不要修改llm生成的代码 代码结构 我们将按]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-a42be0c370d847a092272b6d382c3ac5"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-f6b6f7076d184927b1e8c82e5033b3ee" data-id="f6b6f7076d184927b1e8c82e5033b3ee"><span><div id="f6b6f7076d184927b1e8c82e5033b3ee" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f6b6f7076d184927b1e8c82e5033b3ee" title="任务简介 - 作为数据科学家的 AI 助手"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">任务简介 - 作为数据科学家的 AI 助手</span></span></h3><ul class="notion-list notion-list-disc notion-block-4c4149486aa84a5486ee308c0d1dbb3d"><li>使用 LLMs 自动编写代码</li></ul><ul class="notion-list notion-list-disc notion-block-7434d2e6c772403698a1ceed48ac43f4"><li>只需了解数据集，LLMs 就能为每项任务生成定制化解决方案</li></ul><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-7e6c49ecae6440a2b93a96dde716cb63" data-id="7e6c49ecae6440a2b93a96dde716cb63"><span><div id="7e6c49ecae6440a2b93a96dde716cb63" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7e6c49ecae6440a2b93a96dde716cb63" title="任务 Disease Prediction"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">任务 Disease Prediction</span></span></h4><div class="notion-text notion-block-d45ff5e3714a4ee6a9d45236a24ea463">给定美国某州过去 3 天的调查结果，进而预测第 3 天新增检测阳性病例的百分比。</div><div class="notion-text notion-block-0569f7af8ef74300bc827eec59cb4c73">要用llm生成的代码运行进行预测，不要修改llm生成的代码</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-d36d8110bbe545b6b96ecdb28345c9ae" data-id="d36d8110bbe545b6b96ecdb28345c9ae"><span><div id="d36d8110bbe545b6b96ecdb28345c9ae" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d36d8110bbe545b6b96ecdb28345c9ae" title="数据集描述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">数据集描述</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-de42a42fc47d43f987c1c6114a8ae9bd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/de42a42f-c47d-43f9-87c1-c6114a8ae9bd?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150586775-1.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-84320ff046f0495794ade521b8dbac77">代码结构</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2b2594ce36664b678f8d4dc2cdca375a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2b2594ce-3666-4b67-8f8d-4dc2cdca375a?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150586775-2.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-ce7d0754760a474a8672ffd89beaebb0" data-id="ce7d0754760a474a8672ffd89beaebb0"><span><div id="ce7d0754760a474a8672ffd89beaebb0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ce7d0754760a474a8672ffd89beaebb0" title="计划"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">计划</span></span></h4><div class="notion-text notion-block-30ce3cf8a0284ab2b257a63eab1abe7d">我们将按照以下步骤进行操作：</div><div class="notion-text notion-block-598e4df65cb84886bf220d78d0ab0e1d">**1.加载必要的程序库和数据。</div><div class="notion-text notion-block-1b84b13c98bf40e7a00ec249a7ccc341">2.通过处理缺失值和特征缩放对数据进行预处理。</div><div class="notion-text notion-block-cd5f7ec30c554633ba5403609bc65488">3.将数据集划分为训川练集和测试集。</div><div class="notion-text notion-block-a4810c2416ff4534a2cb405974afac52">4.在训练数据上训川练回归模型。</div><div class="notion-text notion-block-fce289eba809479ab611314ada86b97a">5.对测试数据进行预测。</div><div class="notion-text notion-block-40096e84a10f4792a65785494aff6a29">6.将预测结果保存至提交文件。**</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-9906d6f70cca4a17bae3b72d4c276705" data-id="9906d6f70cca4a17bae3b72d4c276705"><span><div id="9906d6f70cca4a17bae3b72d4c276705" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9906d6f70cca4a17bae3b72d4c276705" title="开源模型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">开源模型</span></span></h4><div class="notion-text notion-block-7a90f6086c8d49819ed2ac8b580c3948">排行榜</div><div class="notion-text notion-block-3dde19417d504e87910c13aa06330c24"><a class="notion-link" href="https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/" target="_blank" rel="noopener noreferrer">https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/</a></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-55609ca5b41b401f9027d509999a2340" data-id="55609ca5b41b401f9027d509999a2340"><span><div id="55609ca5b41b401f9027d509999a2340" class="notion-header-anchor"></div><a class="notion-hash-link" href="#55609ca5b41b401f9027d509999a2340" title="提示－不同LLMs"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">提示－不同LLMs</span></span></h4><div class="notion-text notion-block-1e97fca8ebd14eb29c485be0ea92d408">更强的LLM可能有用，但不总是如此…….</div><div class="notion-text notion-block-43a5df777b7b44d9aa4e398e760fb6f7">我们如何知道哪个LLM更好呢？</div><div class="notion-text notion-block-dbd60ff0e935453f8efae4a594554cb6">模型大小？</div><div class="notion-text notion-block-d7c30c88f84846bb94faac74e12b1eca">预训练</div><div class="notion-text notion-block-a3118b7c3248474bb70d397a4fff99be">语料库？开放LLM排行榜？</div><div class="notion-text notion-block-fa6d13709a224aeda22f996c73f6edf6">你可以从HuggingFace上选择模型。</div><div class="notion-text notion-block-85e304c10a44429c84e6fa1c6ae7db4b">禁止使用诸如</div><div class="notion-text notion-block-b6d641adc38f494cab6803d2d6d8cddc">GPT-4o</div><div class="notion-text notion-block-2eeb92326e9646308352ca20d78eed18">、Gemini等闭源LLMAPl。</div><blockquote class="notion-quote notion-block-fcfb0b0926fd42c3b3f49822c8738bdb"><div>当然还有so many ways,这里我说下我所采用的方法</div></blockquote><ol start="1" class="notion-list notion-list-numbered notion-block-568df6c039224ff9b25286974bb68bfb" style="list-style-type:decimal"><li>使用开源的大模型<a class="notion-link" href="https://developer.aliyun.com/article/1672926" target="_blank" rel="noopener noreferrer">qwen-coder-plus-latest</a></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-a696301c65b04cee8962e5f650be24ad" style="list-style-type:decimal"><li>优化各种提示词</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-bb51ff940186437e9e8c4fa5e25e9704" style="list-style-type:decimal"><li>增大steps数</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-6e398a6010ea4e05bf229f7aca124cc6" style="list-style-type:decimal"><li>增大num_drafts数</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-38165890981246c2a583395263e863d2" style="list-style-type:decimal"><li>温度0.3</li></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-79a29029f1d64f229c633b754b6f6a9a" data-id="79a29029f1d64f229c633b754b6f6a9a"><span><div id="79a29029f1d64f229c633b754b6f6a9a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#79a29029f1d64f229c633b754b6f6a9a" title="下面是核心代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">下面是核心代码</span></span></h4><pre class="notion-code language-python notion-code-id-c95d49769cb2478dbc6c0d9886557a2b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># openai模型api
import os
import openai
api_key=os.getenv(&#x27;OPENAI_API_KEY&#x27;) or &#x27;your_api_key&#x27;
base_url=os.getenv(&#x27;OPENAI_BASE_URL&#x27;) or &quot;your_base_url&quot;
# model=os.getenv(&#x27;OPENAI_MODEL&#x27;) or &quot;your_model&quot;
model=&#x27;qwen-coder-plus-latest&#x27;
# print(api_key,base_url,model)
client=openai.OpenAI(
    api_key=api_key,
    base_url=base_url,
)
def generate_response(prompt,system_prompt=&quot;&quot;,max_tokens=8192,temperature=0.1,stream=False):
    response=client.chat.completions.create(
        model=model,
        messages=[
            {
                &#x27;role&#x27;: &#x27;system&#x27;,
                &#x27;content&#x27;:system_prompt
            },
            {

                &#x27;role&#x27;:&#x27;user&#x27;,
                &#x27;content&#x27;:prompt
            }
        ]
        ,max_tokens=max_tokens,
        temperature=temperature,
        stream=stream
    )
    if stream:
        # 处理流式输出
        def generate():
            for chunk in response:
                if chunk.choices[0].delta.content is not None:
                    yield chunk.choices[0].delta.content
        return generate()
    else:
        # 处理非流式输出
        return response.choices[0].message.content
print(&quot;模型api调用成功！&quot;)
# # 非流式调用
# result = generate_response(&quot;你是谁&quot;)
# print(result)

# # 流式调用
# for chunk in generate_response(prompt=&quot;喜欢什么&quot;, stream=True):
#     print(chunk, end=&quot;&quot;, flush=True)</code></pre><pre class="notion-code language-python notion-code-id-6986127cdf33470db20b1d8248e97fb6" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import random
from typing import Any, Callable, cast

import re
import sys
import json
import humanize

from pydantic import BaseModel

ExecCallbackType = Callable[[str, bool], ExecutionResult]

class Agent:
    def __init__(
        self,
        cfg,
        journal: Journal,
    ):
        super().__init__()
        self.cfg = cfg
        self.journal = journal
        self.data_preview: str | None = None

    def search_policy(self) -&gt; Node | None:
        &quot;&quot;&quot;Select a node to work on (or None to draft a new node).&quot;&quot;&quot;
        search_cfg = self.cfg.agent.search

        # initial drafting
        if len(self.journal.draft_nodes) &lt; search_cfg.num_drafts:
            return None

        # debugging
        if random.random() &lt; search_cfg.debug_prob:
            # nodes that are buggy + leaf nodes + debug depth &lt; max debug depth
            debuggable_nodes = [
                n
                for n in self.journal.buggy_nodes
                if n.is_leaf
            ]
            if debuggable_nodes:
                return random.choice(debuggable_nodes)

        # back to drafting if no nodes to improve
        good_nodes = self.journal.good_nodes
        if not good_nodes:
            return None

        # greedy
        greedy_node = self.journal.get_best_node()

        return greedy_node

    def plan_and_code_query(self, system_message, user_message, retries=3) -&gt; tuple[str, str]:
        &quot;&quot;&quot;Generate a natural language plan + code in the same LLM call and split them apart.&quot;&quot;&quot;
        completion_text = None
        for _ in range(retries):

            response = generate_response(
                prompt=user_message,
                system_prompt=system_message,
            )
            completion_text = response
            code = extract_code(completion_text)
            nl_text = extract_text_up_to_code(completion_text)

            if code:
                return nl_text, code

            print(&quot;Plan + code extraction failed, retrying...&quot;)
        print(&quot;Final plan + code extraction attempt failed, giving up...&quot;)
        return &quot;&quot;, completion_text

    def _draft(self) -&gt; Node:

        # ================ TODO: ask LLM agents to come up with a solution and then implement ================

        # system_prompt = &quot;You are an AI agent.&quot;

        # user_prompt = [
        #     &quot;You have to come up with a solution for machine learning task and then implement this solution in Python.&quot;
        #     f&quot;The task is to {str(self.cfg.task_goal)} &quot;,
        #     f&#x27;All the provided input data is stored in &quot;{self.cfg.data_dir}&quot; directory.&#x27;,
        #     f&quot;{str(self.data_preview)}&quot;,
        #     &#x27;You have to save the predictions result on testing set in &quot;/content/submission.csv&quot;.&#x27;,
        #     &#x27;Note that the testing file DOES NOT have the target column.&#x27;
        # ]
        system_prompt = &quot;&quot;&quot;You are an expert AI agent specializing in time series prediction and data analysis.
You are running on Ubuntu 22.04.5 LTS with Python 3.11.
Your task is to develop a solution that predicts testing probabilities based on survey data.
You should:
1. Analyze the data structure and features
2. Design an appropriate model architecture
3. Implement the solution in Python
4. Ensure the code is well-documented and follows best practices
5. Save predictions to the specified output file

Focus on creating a robust solution that minimizes Mean Squared Error (MSE).&quot;&quot;&quot;

        user_prompt = [
            &quot;Task: Develop a machine learning model to predict testing probabilities.&quot;,
            f&quot;Goal: {str(self.cfg.task_goal)}&quot;,
            f&quot;Data Location: {self.cfg.data_dir}&quot;,
            f&quot;Data Overview:\n{str(self.data_preview)}&quot;,
            &quot;Requirements:&quot;,
            &quot;1. Save predictions to &#x27;/content/submission.csv&#x27;&quot;,
            &quot;2. Note that the testing file DOES NOT have the target column&quot;,
            &quot;3. Implement proper data preprocessing&quot;,
            &quot;4. Use appropriate model selection and validation&quot;,
            &quot;\nNeed to provide:&quot;,
            &quot;1. A detailed plan explaining your approach&quot;,
            &quot;2. Full Python implementation&quot;,
            &quot;\nNote:&quot;,
            &quot;1. Token limit is 8192.&quot;,
        ]
        system_message = system_prompt
        user_message = &quot;\n&quot;.join(user_prompt)
        print(f&#x27;user_message: {user_message}&#x27;)

        plan, code = self.plan_and_code_query(system_message=system_message, user_message=user_message)
        return Node(plan=plan, code=code)

    def _improve(self, parent_node: Node) -&gt; Node:

        # ================  TODO: ask LLM agent to improve drafts ================

        # system_prompt = &quot;You are an AI assistant.&quot;

        # user_prompt = [
        #     f&quot;Task description: {str(self.cfg.task_goal)} &quot;
        #     f&quot;Memory: {str(self.journal.generate_summary())} &quot;
        #     f&quot;Previous solution: Code: {str(wrap_code(parent_node.code))} &quot;
        # ]
        system_prompt = &quot;&quot;&quot;You are an expert AI agent tasked with improving an existing prediction model.
You are running on Ubuntu 22.04.5 LTS with Python 3.11.
Your goal is to enhance the model&#x27;s performance by:
1. Analyzing the current implementation
2. Identifying potential improvements
3. Implementing optimizations
4. Maintaining or improving code quality

Focus on reducing the Mean Squared Error (MSE) while keeping the solution practical and efficient.&quot;&quot;&quot;

        user_prompt = [
            &quot;Task: Improve the existing prediction model&quot;,
            f&quot;Original Goal: {str(self.cfg.task_goal)}&quot;,
            &quot;Previous Solutions:&quot;,
            f&quot;{str(self.journal.generate_summary())}&quot;,
            &quot;Current Implementation:&quot;,
            f&quot;Code:\n{str(wrap_code(parent_node.code))}&quot;,
            &quot;\nNeed to provide:&quot;,
            &quot;1. Analysis of current implementation&quot;,
            &quot;2. Specific improvement plan&quot;,
            &quot;3. Enhanced implementation&quot;
        ]
        system_message = system_prompt
        user_message = &quot;\n&quot;.join(user_prompt)

        print(f&#x27;user_message: {user_message}&#x27;)

        plan, code = self.plan_and_code_query(system_message=system_message, user_message=user_message)
        return Node(plan=plan, code=code, parent=parent_node)

    def _debug(self, parent_node: Node) -&gt; Node:

        # ================  TODO: ask LLM agent to debug ================
        # system_prompt = &quot;You are an AI agent.&quot;

        # user_prompt = [
        #     f&quot;Task description: {str(self.cfg.task_goal)}\n\n&quot;,
        #     f&quot;Previous (buggy) implementation: {str(wrap_code(parent_node.code))}\n\n&quot;,
        #     f&quot;Execution output: {str(wrap_code(parent_node.term_out, lang=&#x27;&#x27;))}\n\n&quot;,
        #     str(self.data_preview)
        # ]
        system_prompt = &quot;&quot;&quot;You are an expert AI agent debugger specializing in machine learning code.
You are running on Ubuntu 22.04.5 LTS with Python 3.11.
Your task is to:
1. Analyze the error or issue in the current implementation
2. Identify the root cause
3. Propose and implement a fix
4. Ensure the solution maintains good performance

Focus on creating a robust fix that resolves the issue while maintaining or improving the model&#x27;s performance.&quot;&quot;&quot;

        user_prompt = [
            &quot;Task: Debug and fix the prediction model&quot;,
            f&quot;Original Goal: {str(self.cfg.task_goal)}&quot;,
            &quot;Current Implementation:&quot;,
            f&quot;Code:\n{str(wrap_code(parent_node.code))}&quot;,
            &quot;Execution Output:&quot;,
            f&quot;{str(wrap_code(parent_node.term_out, lang=&#x27;&#x27;))}&quot;,
            &quot;Data Context:&quot;,
            f&quot;{str(self.data_preview)}&quot;,
            &quot;\nNeed to provide:&quot;,
            &quot;1. Analysis of the error/issue&quot;,
            &quot;2. Root cause identification&quot;,
            &quot;3. Proposed fix&quot;,
            &quot;4. Corrected implementation&quot;
        ]

        system_message = system_prompt
        user_message = &quot;\n&quot;.join(user_prompt)
        print(f&#x27;user_message: {user_message}&#x27;)

        plan, code = self.plan_and_code_query(system_message=system_message, user_message=user_message)
        return Node(plan=plan, code=code, parent=parent_node)

    def update_data_preview(
        self,
    ):
        self.data_preview = data_preview_generate(cfg.data_dir)

    def step(self, exec_callback: ExecCallbackType):
        if not self.journal.nodes or self.data_preview is None:
            self.update_data_preview()

        parent_node = self.search_policy()
        if parent_node is None:
            result_node = self._draft()
        elif parent_node.is_buggy:
            result_node = self._debug(parent_node)
        else:
            result_node = self._improve(parent_node)

        self.parse_exec_result(
            node=result_node,
            exec_result=exec_callback(result_node.code, True),
        )
        self.journal.append(result_node)

    def parse_exec_result(self, node: Node, exec_result: ExecutionResult):
        node.absorb_exec_result(exec_result)

        system_prompt = &quot;You are an AI assistant. You are running on Ubuntu 22.04.5 LTS with Python 3.11.&quot;

        # ================  TODO: ask LLM agent to extract evaluation result from the execution output. ================
        # save log file
        # user_prompt = f&quot;&quot;&quot;
        #     The task is:
        #     {self.cfg.task_goal}

        #     The code implementation is:
        #     {wrap_code(node.code)}

        #     The execution output is:
        #     {wrap_code(node.term_out, lang=&quot;&quot;)}
        # &quot;&quot;&quot;
        user_prompt = f&quot;&quot;&quot;
Task: Evaluate the prediction model implementation

Original Goal:
{self.cfg.task_goal}

Implementation:
{wrap_code(node.code)}

Execution Output:
{wrap_code(node.term_out, lang=&quot;&quot;)}

Need to provide a structured analysis including:
1. Execution Status (Success/Error)
2. Performance Metrics (especially MSE)
3. Issues or Concerns (if any)
4. Overall Assessment&quot;&quot;&quot;

        system_message = system_prompt
        # user_message = &quot; &quot;.join(user_prompt)
        user_message = user_prompt

        print(f&#x27;user_message: {user_message}&#x27;)
        response = generate_response(
                prompt=user_message,
                system_prompt=system_message,
            )

        # ================  TODO: evaluation ================
        # you can force the LLM to structure the output to extract the metric
        # reference: https://python.useinstructor.com/integrations/llama-cpp-python/#llama-cpp-python
        # node.analysis = response.summary
        # node.is_buggy = (
        #     response.is_buggy
        #     or node.exc_type is not None
        #     or response.metric is None
        # )

        try:
            parsed_response = json.loads(response)
            node.analysis = parsed_response.get(&quot;assessment&quot;, &quot;&quot;)
            node.metric = parsed_response[&quot;mse&quot;] if parsed_response.get(&quot;mse&quot;) is not None else 0.0
            node.is_buggy = (
                parsed_response.get(&quot;execution_status&quot;, &quot;Error&quot;) == &quot;Error&quot;
                or node.exc_type is not None
                or node.metric is None
            )
        except Exception as e:
            print(&quot;Failed to parse evaluation response:&quot;, e)
            node.analysis = &quot;Failed to parse evaluation response.&quot;
            node.is_buggy = False
            node.metric = 0.0</code></pre><pre class="notion-code language-python notion-code-id-9f170af70a0d49d9bc0be3b5f7298f9b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># ================  TODO: config ================
config = {
    # experiment configurations
    &quot;exp_name&quot;: &quot;ML2025_HW2&quot;,
    &quot;data_dir&quot;:  Path(&quot;./ML2025Spring-hw2-public&quot;).resolve(),

    # the description of the task
    &quot;task_goal&quot;: &quot;Given the survey results from the past two days in a specific state in the U.S.,\
                  predict the probability of testing positive on day 3. \
                  The evaluation metric is Mean Squared Error (MSE).&quot;,

    &quot;agent&quot;: {
        # the number of iterations
        &quot;steps&quot;: 5,
        &quot;search&quot;: {
            # decide whether to debug or improve
            &quot;debug_prob&quot;: 0.5,
            # the number of draft generated before improving/debugging
            &quot;num_drafts&quot;: 5,
        },
    },
}

cfg = Config(config)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f0b7f96b3ff547b9978d04e95b1236c9" data-id="f0b7f96b3ff547b9978d04e95b1236c9"><span><div id="f0b7f96b3ff547b9978d04e95b1236c9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f0b7f96b3ff547b9978d04e95b1236c9" title="完整代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">完整代码</span></span></h4><div class="notion-text notion-block-6919bd9d42234546bbe772647a2f9a99"><a class="notion-link" href="https://github.com/hllqkb/ML2025Spring_HUNG_YI_LEE_Machine_Learning_Homework/blob/master/ML2025Spring-hw2/ML2025Spring_hw2_bossline.ipynb" target="_blank" rel="noopener noreferrer">https://github.com/hllqkb/ML2025Spring_HUNG_YI_LEE_Machine_Learning_Homework/blob/master/ML2025Spring-hw2/ML2025Spring_hw2_bossline.ipynb</a></div><div class="notion-text notion-block-0dd11d949aa947a6838e26ab72a09a2c">根据下面的Baseline表</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-6e12203e720d49e1b23eb9d8fe7387cd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/6e12203e-720d-49e1-b23e-b9d8fe7387cd?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150586775-6.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-46cef75f0d2d42189b42f63c9a0f1e93"><b>前往比赛提交并且查看我们的成绩</b></div><div class="notion-text notion-block-6b12fa3d4a4a49e58362d1526adfb64a">比赛链接</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-c316d341f9614398a8ef6455c655bf52"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/c316d341-f961-4398-a8ef-6455c655bf52?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150586775-7.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-59525b671f2a457faf2f5f4cb2250e93">输出结果<code class="notion-inline-code">0.947</code></div><div class="notion-text notion-block-e409479efe1545a4a40e6dea6d243320">‼️ 目前仍难以获得可复现且稳定的结果。 ‼️</div><div class="notion-text notion-block-c290fb53769f439e9fdef57634cccfc7">当然你想拿高分的话可以偷偷作弊一下，直接自己写一个，肯定比ai写的好</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-d1d98bc186c0413bb925767e3b4045f8" data-id="d1d98bc186c0413bb925767e3b4045f8"><span><div id="d1d98bc186c0413bb925767e3b4045f8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d1d98bc186c0413bb925767e3b4045f8" title="0.8300"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">0.8300</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-f6e2da583b5c4f6db056c4b490679bd3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/f6e2da58-3b5c-4f6d-b056-c4b490679bd3?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150586775-8.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-888e9fb360e744dfab5cab9b66409b7f"><b>best.py完整代码</b></div><pre class="notion-code language-python notion-code-id-a60597d6782d4de08b17bacf3702a593" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 引入必要模块
# 数据操作
import pandas as pd
import numpy as np
import math
import csv
import random
import os
from monai.utils import set_determinism
from torch.utils.data import Dataset, DataLoader
# 进度条
from tqdm import tqdm
# 特征选择
from sklearn.feature_selection import SelectKBest, f_regression
# pytorch
import torch
import torch.nn as nn
# 绘制图像
from torch.utils.tensorboard import SummaryWriter
# set random seed
def split_valid_set(data_set, valid_ratio, seed):
    np.random.seed(seed)
    indices = np.random.permutation(len(data_set))
    valid_size = int(len(data_set) * valid_ratio)
    valid_idx = indices[:valid_size]
    train_idx = indices[valid_size:]
    return data_set[train_idx], data_set[valid_idx]
def select_features(train_data,valid_data,test_data,select_all=True):
    # choose label
    y_train=train_data[:,-1]
    y_valid=valid_data[:,-1]
    # choose all features except label
    raw_x_train=train_data[:,:-1]
    raw_x_valid=valid_data[:,:-1]
    raw_x_test=test_data
    if select_all:
        feat_idx=list(range(raw_x_train.shape[1]))
        all_to_remove = {0}
        feat_idx = [x for x in feat_idx if x not in all_to_remove]

    else:
        # Feature selection
        feat_idx = [34, 35, 36, 43, 46, 47, 51, 52, 53,
                    54, 61, 64, 65, 69, 70, 71, 72, 79, 82, 83]
    return raw_x_train[:,feat_idx],raw_x_valid[:,feat_idx],raw_x_test[:,feat_idx],y_train,y_valid

class COVID19Dataset(Dataset):
    def __init__(self, features,target=None):
        if target is None:
            # predict
            self.target=target
        else:
            # train
            self.target = torch.FloatTensor(target)
        self.features = torch.FloatTensor(features)
    def __getitem__(self,idx):
        # idx means index of sample
        if self.target is None:
            return self.features[idx]
        else:
            return self.features[idx],self.target[idx]
    def __len__(self):
        return len(self.features)
# define model
class MyModel(nn.Module):
    def __init__(self, input_dim):
        super(MyModel, self).__init__()
        hidden_dims = config[&#x27;layer&#x27;]  # 如 [128, 64, 32]

        layers = []
        dims = [input_dim] + hidden_dims

        for in_dim, out_dim in zip(dims[:-1], dims[1:]):
            layers.append(nn.Linear(in_dim, out_dim))
            layers.append(nn.GELU())  # 更先进的激活函数

        # 可选：加入 Dropout 或 BatchNorm 以提升泛化能力
        # layers.append(nn.Dropout(0.2))

        layers.append(nn.Linear(dims[-1], 1))  # 输出层：无激活

        self.layers = nn.Sequential(*layers)

    def forward(self, x):
        x = self.layers(x)
        return x.squeeze(1)  # 输出 (B)
# Set CFG
device=torch.device(&#x27;cuda&#x27; if torch.cuda.is_available() else &#x27;cpu&#x27;)
config={
    &#x27;layer&#x27;: [128, 64, 32],
    &#x27;k&#x27;:20,
    &#x27;seed&#x27;: 3407,
    &#x27;select_all&#x27;: False,
    &#x27;normalize&#x27;: True,
    &#x27;batch_size&#x27;: 128,
    &#x27;lr&#x27;: 0.00035099698616997447,
    &#x27;n_epochs&#x27;: 20000,
    &#x27;valid_ratio&#x27;: 0.2,
    &#x27;early_stop&#x27;: 400,
    &#x27;save_path&#x27;: &#x27;./models/model.ckpt&#x27;,
    &#x27;beta1&#x27;: 0.95,  # β₁
    &#x27;eps&#x27;: 1e-7,  # ϵ
}

# train
def train(train_loader,valid_loader,model,config,device):
    criterion=nn.MSELoss()
    optimizer = torch.optim.Adam(
    model.parameters(),
    lr=config[&#x27;lr&#x27;],
    betas=(config[&#x27;beta1&#x27;], 0.999),  # 调整 β₁
    eps=config[&#x27;eps&#x27;],               # 调整 ϵ
    # weight_decay=0  # 可选：是否加入 L2 正则化
)
    writer=SummaryWriter()
    best_loss=math.inf
    early_stop_count=0
    step=0
    for epoch in range(config[&#x27;n_epochs&#x27;]):
        loss_record=[]
        model.train()
        train_bar=tqdm(train_loader)
        for x,y in train_bar:
            x,y=x.to(device),y.to(device)
            optimizer.zero_grad()
            outputs=model(x)
            loss=criterion(outputs,y)
            loss.backward()
            optimizer.step()
            loss_record.append(loss.detach().item())
            step+=1
        # validate
        model.eval()
        valid_loss_record=[]
        valid_bar=tqdm(valid_loader)
        for x,y in valid_bar:
            x,y=x.to(device),y.to(device)
            with torch.no_grad():
                outputs=model(x)
                loss=criterion(outputs,y)
                valid_loss_record.append(loss.detach().item())
        valid_loss=np.mean(valid_loss_record)
        writer.add_scalar(&#x27;valid_loss&#x27;,valid_loss,step)
        # save best model
        if valid_loss&lt;best_loss:
            best_loss=valid_loss
            torch.save(model.state_dict(),config[&#x27;save_path&#x27;])
            early_stop_count=0
            print(&#x27;Saving model with loss {:.3f}...&#x27;.format(best_loss))
        else:
            early_stop_count+=1
        if early_stop_count&gt;=config[&#x27;early_stop&#x27;]:
            return best_loss
    return best_loss
# set same seed
set_determinism(seed=config[&#x27;seed&#x27;])

# 读取数据（保留 DataFrame 或 NumPy）
train_data = pd.read_csv(&#x27;./ML2025Spring-hw2-public/train.csv&#x27;).values
test_data = pd.read_csv(&#x27;./ML2025Spring-hw2-public/test.csv&#x27;).values

# 切分数据（不转成 Subset）
train_data, valid_data = split_valid_set(train_data, config[&#x27;valid_ratio&#x27;], config[&#x27;seed&#x27;])

# 检查标签是否有 NaN
if np.isnan(train_data[:, -1]).sum() &gt; 0 or np.isnan(valid_data[:, -1]).sum() &gt; 0:
    raise ValueError(&quot;Labels contain NaN values. Please check your data.&quot;)
# Normalization with Min-Max scaling 可以加一个点
if config[&#x27;normalize&#x27;]:
    train_min = np.min(train_data[:, 35:-1], axis=0)  # 计算每列最小值
    train_max = np.max(train_data[:, 35:-1], axis=0)  # 计算每列最大值
    # 防止除以0的情况，可以加一个很小的数
    epsilon = 1e-8
    train_range = train_max - train_min + epsilon
    # 归一化训练集
    train_data[:, 35:-1] = (train_data[:, 35:-1] - train_min) / train_range
    # 用相同的min和range归一化验证集
    valid_data[:, 35:-1] = (valid_data[:, 35:-1] - train_min) / train_range
    # 用相同的min和range归一化测试集
    test_data[:, 35:] = (test_data[:, 35:] - train_min) / train_range
x_train,x_valid,x_test,y_train,y_valid=select_features(train_data,valid_data,test_data,config[&#x27;select_all&#x27;])
# convert to tensor
train_dataset=COVID19Dataset(x_train,y_train)
valid_dataset=COVID19Dataset(x_valid,y_valid)
test_dataset=COVID19Dataset(x_test)
# pin memory能保存数据到GPU的高速缓存中，能加快数据加载速度,shuffle=True表示每个epoch打乱数据
train_loader=DataLoader(train_dataset,batch_size=config[&#x27;batch_size&#x27;],shuffle=True,pin_memory=True)
valid_loader=DataLoader(valid_dataset,batch_size=config[&#x27;batch_size&#x27;],shuffle=True,pin_memory=True)
test_loader=DataLoader(test_dataset,batch_size=config[&#x27;batch_size&#x27;],shuffle=False,pin_memory=True)
# create model
model=MyModel(input_dim=x_train.shape[1]).to(device)

# train

print(&#x27;Training model...&#x27;)
best_loss=train(train_loader,valid_loader,model,config,device)
print(f&#x27;Best validation loss: {best_loss:.3f}&#x27;)
def predict(test_loader,model,device):
    model.eval()
    preds=[]
    with torch.no_grad():
        for x in tqdm(test_loader):
            x=x.to(device)
            outputs=model(x)
            # 把数据从GPU转移到CPU，才能转换为numpy数组
            preds.append(outputs.detach().cpu())
    preds = torch.cat(preds, dim=0).numpy()
    return preds
# predict
predictions=predict(test_loader,model,device)
# save predictions
def save_pred(preds, file):
    &#x27;&#x27;&#x27; Save predictions to specified file &#x27;&#x27;&#x27;
    with open(file, &#x27;w&#x27;) as fp:
        writer = csv.writer(fp)
        writer.writerow([&#x27;id&#x27;, &#x27;tested_positive&#x27;])
        for i, p in enumerate(preds):
            writer.writerow([i, p])
save_pred(predictions, &#x27;./predictions.csv&#x27;)
print(&#x27;Predictions saved in ./predictions.csv&#x27;)</code></pre><div class="notion-text notion-block-0ee8aedc3315407c9b4e10a0d796f20a">代码库：<a class="notion-link" href="https://github.com/hllqkb/ML2025Spring_HUNG_YI_LEE_Machine_Learning_Homework" target="_blank" rel="noopener noreferrer">https://github.com/hllqkb/ML2025Spring_HUNG_YI_LEE_Machine_Learning_Homework</a></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML2025 Homework 1 基于Agent系统的检索增强生成技术 Retrieval Augmented Generation with Agentic System]]></title>
            <link>https://hllqk.cn/article/csdn-150578548-ml2025-homework-1-agent-retrieval-augmen</link>
            <guid>https://hllqk.cn/article/csdn-150578548-ml2025-homework-1-agent-retrieval-augmen</guid>
            <pubDate>Thu, 21 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[代理系统是一个框架，其中LLM作为个体并合作完成复杂的任务 结果如图 RAG with Agentic System The goal of HW1 is bu]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-6f1289026883457689092eb79a51cfca"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-4f87f9f200f647a8a313286892ef63b3" data-id="4f87f9f200f647a8a313286892ef63b3"><span><div id="4f87f9f200f647a8a313286892ef63b3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4f87f9f200f647a8a313286892ef63b3" title="什么是RAG"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是RAG</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-88043ecf60974abba29a34a4fb3d775e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/88043ecf-6097-4abb-a29a-34a4fb3d775e?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150578548-1.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><blockquote class="notion-quote notion-block-27b6fa7114714bd2aa451090e2114b35"><div>Retrieval augmeted generation (RAG)是一种方法允许llm使用外部知识回答问题</div></blockquote><blockquote class="notion-quote notion-block-ec6cba22372049f39c32d5f10a2d244d"><div>关于<code class="notion-inline-code">RAG</code>的概念不多概述</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-acbb22112ec44a66bd8ec986de83dbdd" data-id="acbb22112ec44a66bd8ec986de83dbdd"><span><div id="acbb22112ec44a66bd8ec986de83dbdd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#acbb22112ec44a66bd8ec986de83dbdd" title="什么是代理系统"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是代理系统</span></span></h4><div class="notion-text notion-block-d1cf1f3d59364f90b0e1f255a998ef0c">代理系统是一个框架，其中LLM作为个体并合作完成复杂的任务</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-18c0ef10e16c489e8f56340cfcb6b376"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/18c0ef10-e16c-489e-8f56-340cfcb6b376?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150578548-2.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2aef44187bc5446ba8cd082f6dc9076a">结果如图</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-102b0b5a073c4cd99c4050d56573928b" data-id="102b0b5a073c4cd99c4050d56573928b"><span><div id="102b0b5a073c4cd99c4050d56573928b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#102b0b5a073c4cd99c4050d56573928b" title="Task Overview"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Task Overview</span></span></h4><div class="notion-text notion-block-7160400f0ce1408ba2d41a062f3f1178">RAG with</div><div class="notion-text notion-block-5231319668ea467fb048cae3dba10a62">Agentic</div><div class="notion-text notion-block-cfabd8ffe0a74dd191d7ec569c6b516e">System</div><div class="notion-text notion-block-a78b22ff52f14819bc8894a9a9beeb16">The goal of HW1 is building an RAG system with agents</div><div class="notion-text notion-block-dc000e59f2444c2fb1c24027b7389d66">要构建rag系统这个在baseline已经完成了</div><div class="notion-text notion-block-87430567499d47958384e40e9dc8f94b"><b>TODOs</b></div><ol start="1" class="notion-list notion-list-numbered notion-block-75b5f45d9cfc44e88515645e1919f084" style="list-style-type:decimal"><li>Learn how an RAG system operates.</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-964107134ae743acab0815d2bcf9b310" style="list-style-type:decimal"><li>Design the prompts for agents to solve some tasks.</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-bfd562610b92403fa283e16a478ab0b0" style="list-style-type:decimal"><li>Submit your code to NTU COOL and submit your results to JudgeBoi</li></ol><div class="notion-text notion-block-22e2f3efa17a41988624a04f69845c01">这是要做的TODOs</div><div class="notion-text notion-block-6a5703deb564413899e0a81b8f3541a6">不过无法提交到JudgeBoi了结果，但是可以直接自己用gpt4o验证正确性</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-fba9846f013448fe9d2d2a183f324cc4" data-id="fba9846f013448fe9d2d2a183f324cc4"><span><div id="fba9846f013448fe9d2d2a183f324cc4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fba9846f013448fe9d2d2a183f324cc4" title="Dataset"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Dataset</span></span></h4><div class="notion-text notion-block-67ce04458a324e78842b6066055b7434">There are 90 hand-crafted questions.</div><div class="notion-text notion-block-690b3999587348738c9ecae46e0cb469">The answers to these questions are a word or a phrase.</div><div class="notion-text notion-block-891ea27cd5fc478ca494d588a7d21825">The dataset contains two parts: public and private</div><div class="notion-text notion-block-d2bab672d26a4672b8ed5403193efd47">关于数据集的描述，有public.txt和private.txt，public有答案,private没有答案</div><div class="notion-text notion-block-20634c2572f342ef94ec8df44c50bc64">由于无法提交评分，我们这里直接实现hint就行了</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-96b93a5a98d04b8586a6d314984b7386" data-id="96b93a5a98d04b8586a6d314984b7386"><span><div id="96b93a5a98d04b8586a6d314984b7386" class="notion-header-anchor"></div><a class="notion-hash-link" href="#96b93a5a98d04b8586a6d314984b7386" title="Hints"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Hints</span></span></h4><div class="notion-text notion-block-05a1774d30b147dba962a9d6c2a4d723">Please note that the following hints are just for your reference. You are not required to follow</div><div class="notion-text notion-block-aa41fb24d76c4738a602874861918390">them. And you are not guaranteed to beat the baselines by simply following them.</div><div class="notion-text notion-block-c8a557e1ddaa44169f93a57c473dea27">For the simple baseline, you don’t need to do anything. Directly feed the questions to</div><div class="notion-text notion-block-4d351c339afb49c8a79dcd2d55e3beb9">the LLM. (Just run the sample code!)</div><div class="notion-text notion-block-40d86ba3000a4d79adf8b23fe1dab0bc">For the medium baseline, you will need to integrate the search tool into your system.</div><div class="notion-text notion-block-c6477397b2994ee1a16c55015495fb3e">The search tool has already been implemented in the sample code. You need to</div><div class="notion-text notion-block-3c4f8c9a29a445dbb544bec4e6c63ec4">integrate it into your pipeline</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-5b40ee5d85f146c3924708e05c17ee85"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/5b40ee5d-85f1-46c3-9247-08e05c17ee85?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150578548-3.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-2f60b3d8cbdd49daa0476ee9374639a5">让我们来实现这个架构并且实现web搜索和rag和使用能调用huggingface的模型</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-a94df913da29444ab52478e640a9d342" data-id="a94df913da29444ab52478e640a9d342"><span><div id="a94df913da29444ab52478e640a9d342" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a94df913da29444ab52478e640a9d342" title="关键改进"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">关键改进</span></span></h4><div class="notion-text notion-block-2eb71f7558114338a87419477e44e385"><b>移除Meta-Llama-3.1-8B-Instruct-Q8_0.gguf和相关依赖，因为这个模型使用rag实在是太过复杂了，选择了别的模型</b></div><pre class="notion-code language-bash notion-code-id-25b804efb2744613b5fb57f78d18d415" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">!python3 -m pip install googlesearch-python bs4 charset-normalizer requests-html lxml_html_clean

from pathlib import Path
if not Path(&#x27;./public.txt&#x27;).exists():
    !wget https://www.csie.ntu.edu.tw/~ulin/public.txt
if not Path(&#x27;./private.txt&#x27;).exists():
    !wget https://www.csie.ntu.edu.tw/~ulin/private.txt</code></pre><div class="notion-text notion-block-696ff434434942c4825666a4ce5ecdc9"><b>搜索代码改进，使用博查ai搜索，最后测试ai搜索没什么用对于一个问句，或者关键词搜索，更别提web爬虫搜索相关信息用google or bing,要实现一个完善的ai搜索比较复杂，调用api也没有好的效果，建议使用一些开源项目或者别的api可以取得更好效果</b></div><pre class="notion-code language-python notion-code-id-88d1d317f05c48c99e38e6376b33367e" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from typing import List
from googlesearch import search as _search
from bs4 import BeautifulSoup
from charset_normalizer import detect
import asyncio
from requests_html import AsyncHTMLSession
import urllib3
urllib3.disable_warnings()

async def worker(s:AsyncHTMLSession, url:str):
    try:
        header_response = await asyncio.wait_for(s.head(url, verify=False), timeout=10)
        if &#x27;text/html&#x27; not in header_response.headers.get(&#x27;Content-Type&#x27;, &#x27;&#x27;):
            return None
        r = await asyncio.wait_for(s.get(url, verify=False), timeout=10)
        return r.text
    except:
        return None
from typing import List
from requests_html import AsyncHTMLSession
from bs4 import BeautifulSoup
from charset_normalizer import detect
import asyncio
import requests
import json
import urllib.parse
import re
import urllib3
urllib3.disable_warnings()

async def fetch_html(s: AsyncHTMLSession, url: str) -&gt; str | None:
    try:
        r = await asyncio.wait_for(s.get(url, verify=False), timeout=10)
        if &#x27;text/html&#x27; not in r.headers.get(&#x27;Content-Type&#x27;, &#x27;&#x27;):
            return None
        return r.text
    except:
        return None

async def get_htmls(urls: List[str]) -&gt; List[str]:
    session = AsyncHTMLSession()
    tasks = [fetch_html(session, url) for url in urls]
    return await asyncio.gather(*tasks)

async def search(keyword: str, n_results: int = 3) -&gt; List[str]:

    url = &quot;https://api.bochaai.com/v1/ai-search&quot;
    headers = {
        &#x27;Authorization&#x27;: &#x27;Bearer 你的key&#x27;,
        &#x27;Content-Type&#x27;: &#x27;application/json&#x27;
    }
    payload = {
        &quot;query&quot;: keyword,
        &quot;freshness&quot;: &quot;oneYear&quot;,
        &quot;summary&quot;: True,
        &quot;count&quot;: n_results
    }
    response = requests.post(url, headers=headers, json=payload)
    response_json= response.json()
    result=[]
    for message in response_json[&#x27;messages&#x27;]:
        result.append(message[&#x27;content&#x27;])
    return result</code></pre><div class="notion-text notion-block-a5bfd7c439ae4468bda05edb5adbcde8"><b>定义agent字典，为啥要这样做，因为无法使用LLMAgent</b></div><pre class="notion-code language-python notion-code-id-1932cd820df340dd87e030cf13d7a6f7" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 定义agents字典
agents = {
    &quot;question_extraction_agent&quot;: {
        &quot;role_description&quot;: &quot;你是一個專門負責問題過濾的 AI 助手，能從輸入中識別出與問題相關的核心描述，去除掉無關或冗餘的內容。&quot;,
        &quot;task_description&quot;: &quot;請從以下輸入中篩選並保留與問題相關的部分，刪除與問題無關的句子或細節：&quot;
    },
    &quot;keyword_extraction_agent&quot;: {
        &quot;role_description&quot;: &quot;你是一個關鍵詞提取助手，能從問題中找出最重要的詞彙與短語，幫助搜尋工具更準確地找到答案。&quot;,
        &quot;task_description&quot;: &quot;請從以下問題中抽取最能代表問題核心的關鍵詞或短語，並以逗號分隔：&quot;
    }
}

# 调用示例
def call_agent(agent_name, input_text):
    agent = agents.get(agent_name)
    return agent[&#x27;role_description&#x27;]+agent[&#x27;task_description&#x27;]+input_text

# 使用question_extraction_agent处理问题
result1 = call_agent(&quot;question_extraction_agent&quot;, &quot;我想知道如何学习Python，顺便问一下今天天气怎么样？&quot;)
print(result1)

# 使用keyword_extraction_agent提取关键词
result2 = call_agent(&quot;keyword_extraction_agent&quot;, &quot;学习Python的最佳方法是什么？&quot;)
print(result2)</code></pre><div class="notion-text notion-block-8172266c7a974f3ca442ac08bdf1b534"><b>使用嵌入模型</b></div><pre class="notion-code language-python notion-code-id-f6cff76a80c3422d88869ed2c8fdf89d" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from langchain_huggingface import HuggingFaceEmbeddings

# 指定要加载的预训练模型的名称，参考排行榜：https://huggingface.co/spaces/mteb/leaderboard
model_name = &quot;chuxin-llm/Chuxin-Embedding&quot;

# 创建 Hugging Face 的嵌入模型实例，这个模型将用于将文本转换为向量表示（embedding）
embedding_model = HuggingFaceEmbeddings(model_name=model_name)

# # 打印嵌入模型的配置信息，显示模型结构和其他相关参数
# print(embedding_model)

# # embed_query() 方法会将文本转换为嵌入的向量
# query_embedding = embedding_model.embed_query(&quot;Hello&quot;)

# # 打印生成的嵌入向量的长度，向量长度应与模型的输出维度一致（这里是 1024），你也可以选择打印向量看看
# print(f&quot;嵌入向量的维度为: {len(query_embedding)}&quot;)</code></pre><pre class="notion-code language-python notion-code-id-136f870caa384f318d5990c8e3461210" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 直接保存搜索的结果的嵌入的相关函数
from langchain.vectorstores import FAISS
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.docstore.document import Document
import numpy as np
import os

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=100,  # 尝试调整它
    chunk_overlap=10,  # 尝试调整它
    #length_function=len,  # 可以省略
    # separators=[&quot;\n\n&quot;, &quot;\n&quot;, &quot; &quot;, &quot;。&quot;, &quot;&quot;]  # 可以省略
)

def build_faiss_index(texts):
    # 添加public.txt的内容到知识库里面
        # 读取并预处理public.txt
    with open(&quot;./public.txt&quot;, &#x27;r&#x27;, encoding=&#x27;utf-8&#x27;) as f:
        public_text = f.read()

    # 先将public_text分块
    public_docs = text_splitter.split_documents([Document(page_content=public_text)])
    # 保存和加载向量数据库
    # 把文本列表转化为文档列表
    document=[Document(page_content=text) for text in texts]
    # 使用预训练嵌入模型生成向量并创建向量数据库
    docs = text_splitter.split_documents(document)
        # 合并文档
    all_docs = docs + public_docs
    # 创建向量数据库
    vectorstore = FAISS.from_documents(all_docs, embedding_model)
    # 创建检索器
    retriever = vectorstore.as_retriever(search_kwargs={&quot;k&quot;: 3})

    return vectorstore,retriever</code></pre><div class="notion-text notion-block-2c6708071f2c4eb081d2e5b3cfa6b2dd">剩下代码不一一概述了</div><div class="notion-text notion-block-66079cc94ac9497a8e00c1c239b7f431">完整代码：<a class="notion-link" href="https://github.com/hllqkb/ML2025Spring_HUNG_YI_LEE_Machine_Learning_Homework/blob/master/ML2025Spring-hw1/mlhw1-bossline.ipynb" target="_blank" rel="noopener noreferrer">https://github.com/hllqkb/ML2025Spring_HUNG_YI_LEE_Machine_Learning_Homework/blob/master/ML2025Spring-hw1/mlhw1-bossline.ipynb</a></div><div class="notion-text notion-block-0564ebb81c4b435c84f56ad7a5743762">最后输出</div><pre class="notion-code language-python notion-code-id-9dd306ac4d81425ba865045be4386970" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">问题过滤结果: 你是一個專門負責問題過濾的 AI 助手，能從輸入中識別出與問題相關的核心描述，去除掉無關或冗餘的內容。請從以下輸入中篩選並保留與問題相關的部分，刪除與問題無關的句子或細節：校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？

虎山雄風飛揚是哪間學校的校歌歌詞？

(去除： 校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。)
提取的关键词: 你是一個關鍵詞提取助手，能從問題中找出最重要的詞彙與短語，幫助搜尋工具更準確地找到答案。請從以下問題中抽取最能代表問題核心的關鍵詞或短語，並以逗號分隔：校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？

虎山、雄風、飛揚、校歌、歌詞、學校、宣告、規定、治學、辦學、理念、理想、學校文化
检索到 3 篇相关文档
最终输入内容已拼接完成
生成式模型已完成回答
最终回答: 問題: 你是一個專門負責問題過濾的 AI 助手，能從輸入中識別出與問題相關的核心描述，去除掉無關或冗餘的內容。請從以下輸入中篩選並保留與問題相關的部分，刪除與問題無關的句子或細節：校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？

虎山雄風飛揚是哪間學校的校歌歌詞？

(去除： 校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。)
關鍵詞: 你是一個關鍵詞提取助手，能從問題中找出最重要的詞彙與短語，幫助搜尋工具更準確地找到答案。請從以下問題中抽取最能代表問題核心的關鍵詞或短語，並以逗號分隔：校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？

虎山、雄風、飛揚、校歌、歌詞、學校、宣告、規定、治學、辦學、理念、理想、學校文化

相關文檔:
校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？,光華國小
「如果你朋友唱歌沒有跑調，一定是他的伴侶跑掉了」是一句用來形容失戀之人唱歌模樣的網路笑話。「短暫交會的旅程就此分岔」是哪個歌唱團體歌曲中的歌詞？,動力火車
无

請基於以上內容回答問題： 虎山雄風飛揚是哪間學校的校歌歌詞？

虎山雄風飛揚是光華國小的校歌歌詞。
問題: 你是一個專門負責問題過濾的 AI 助手，能從輸入中識別出與問題相關的核心描述，去除掉無關或冗餘的內容。請從以下輸入中篩選並保留與問題相關的部分，刪除與問題無關的句子或細節：校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？

虎山雄風飛揚是哪間學校的校歌歌詞？

(去除： 校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。)
關鍵詞: 你是一個關鍵詞提取助手，能從問題中找出最重要的詞彙與短語，幫助搜尋工具更準確地找到答案。請從以下問題中抽取最能代表問題核心的關鍵詞或短語，並以逗號分隔：校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？

虎山、雄風、飛揚、校歌、歌詞、學校、宣告、規定、治學、辦學、理念、理想、學校文化

相關文檔:
校歌為學校（包括小學、中學、大學等）宣告或者規定的代表該校的歌曲。用於體現該校的治學理念、辦學理想等學校文化。「虎山雄風飛揚」是哪間學校的校歌歌詞？,光華國小
「如果你朋友唱歌沒有跑調，一定是他的伴侶跑掉了」是一句用來形容失戀之人唱歌模樣的網路笑話。「短暫交會的旅程就此分岔」是哪個歌唱團體歌曲中的歌詞？,動力火車
无

請基於以上內容回答問題： 虎山雄風飛揚是哪間學校的校歌歌詞？

虎山雄風飛揚是光華國小的校歌歌詞。</code></pre><pre class="notion-code language-bash notion-code-id-428528a950d44a1dbf8c70b11917013b" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">請基於以上內容回答問題：
NCC 規定每案加收審查費多少錢？

NCC 規定每案加收審查費 750 元。</code></pre></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[手写MNIST数字识别 底层实现]]></title>
            <link>https://hllqk.cn/article/csdn-150552932-mnist</link>
            <guid>https://hllqk.cn/article/csdn-150552932-mnist</guid>
            <pubDate>Wed, 20 Aug 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[mnist已经写了很多遍了，这次再全部从零底层实现一遍，顺便附上具体原理 数字识别就是个分类问题，神经网络可以用于回归任务和分类任务，回归问题用恒等函数，分类问]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-ca4e8c5ceb4944058e3d938a64e4bbd0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-1bfc005c309343fd806078dd4989cbba"><b>mnist已经写了很多遍了，这次再全部从零底层实现一遍，顺便附上具体原理</b></div><div class="notion-text notion-block-cf07be9f56004a7399094d1f4614e60c">数字识别就是个分类问题，神经网络可以用于回归任务和分类任务，回归问题用恒等函数，分类问题用softmax函数。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-7b10d571463a42adadb3269522b074fd" data-id="7b10d571463a42adadb3269522b074fd"><span><div id="7b10d571463a42adadb3269522b074fd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7b10d571463a42adadb3269522b074fd" title="什么是softmax函数："><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是softmax函数：</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-18e1236709754c25ab66ffbb42ad05cd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/18e12367-0975-4c25-ab66-ffbb42ad05cd?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-1.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-97f954f6c5344439a735c5a3124e0196">这个函数就是，我们代码实现</div><pre class="notion-code language-python notion-code-id-73756a07ac69453ba5024e98475714dd" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def softmax(x):
    &quot;&quot;&quot;
    计算softmax函数
    &quot;&quot;&quot;
    return np.exp(x) / np.sum(np.exp(x), axis=0)</code></pre><div class="notion-text notion-block-3e138a0ba6714cc2a6827d743c367b56">正常输出</div><pre class="notion-code language-bash notion-code-id-06f3742327d647a7b908a66a60571aba" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">print(softmax(np.array([1, 2, 3])))</code></pre><pre class="notion-code language-bash notion-code-id-25f71c86d9b6438fa17266e954813ad5" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">[0.09003057 0.24472847 0.66524096]</code></pre><pre class="notion-code language-python notion-code-id-8b9d723bf91045af8f17841d4b6ba1e9" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">print(softmax(np.array([1010, 2000, 3000])))</code></pre><div class="notion-text notion-block-487da36e8b7b42bd925af248a4fef27b">我们试一试大数运行函数输出</div><pre class="notion-code language-bash notion-code-id-169c23e247c8430986cc77843b9f87a3" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">[nan nan nan]</code></pre><div class="notion-text notion-block-1119349086b5472793d5ccddbe41c2a6">上面的softmax函数的实现虽然正确描述了式子，但在计算机的运算</div><div class="notion-text notion-block-42b7b980c4b447dfb3ada55d616c2cdd">上有一定的缺陷。这个缺陷就是溢出问题。softmax函数的实现中要进行指</div><div class="notion-text notion-block-f999de6dad7e4e00bf172224cedc2d1e">数函数的运算，但是此时指数函数的值很容易变得非常大。比如，e^10的值</div><div class="notion-text notion-block-d4e0952ce1fd4205a05b2971dea52c16">会超过20000，e^100会变成一个后面有40多个0的超大值，</div><div class="notion-text notion-block-3c1a412717fe484ba3dcc946683fb286">e^1000的结果会返回一个表示无穷大的inf。如果在这些超大值之间进行除法运算，结果会出现“不确定”的情况</div><div class="notion-text notion-block-0ad39883f58545bfb8bfadb45a707519">我们可以改进函数,通过减去输入信号中的最大值（上例中的c），我们发现原</div><div class="notion-text notion-block-b8a8aaf6d9aa4a36b1ce41ac4d5c0396">本为nan（not a number，不确定）的地方，现在被正确计算了。</div><pre class="notion-code language-python notion-code-id-1046046d5ac74d24af6e2d7f30a61a86" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def softmax(x):
    &quot;&quot;&quot;
    计算softmax函数，解决溢出问题
    &quot;&quot;&quot;
    x = x - np.max(x)
    exp_x = np.exp(x)
    return exp_x / np.sum(exp_x)
print(softmax(np.array([1010, 1000, 990])))</code></pre><div class="notion-text notion-block-b159962cd49b4724a9d74f7575e5dbf1">最终得到正常结果</div><pre class="notion-code language-bash notion-code-id-f07f94db685e461fa1762935d7439099" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">[9.99954600e-01 4.53978686e-05 2.06106005e-09]</code></pre><div class="notion-text notion-block-5453d90845c8446e93be94b2b668ff72">softmax函数的输出是0.0到1.0之间的实数。并且，softmax</div><div class="notion-text notion-block-6a21268d5024436586573bacb76c81dc">函数的输出值的总和是1。输出总和为1是softmax函数的一个重要性质。正</div><div class="notion-text notion-block-38b61cf09c3c41d4a605e0eeb8a12f55">因为有了这个性质，我们才可以把softmax函数的输出解释为‘概率’</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-94aa3065d6144e1da41c42f1cbd7446c" data-id="94aa3065d6144e1da41c42f1cbd7446c"><span><div id="94aa3065d6144e1da41c42f1cbd7446c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#94aa3065d6144e1da41c42f1cbd7446c" title="输出层的神经元数量"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">输出层的神经元数量</span></span></h4><blockquote class="notion-quote notion-block-ba9a26e1db584e37bbb86d2e3fcafac9"><div>输出层的神经元数量需要根据待解决的问题来决定。对于分类问题，输</div></blockquote><blockquote class="notion-quote notion-block-0b26baed6fa34ccebec7ec352f341301"><div></div></blockquote><blockquote class="notion-quote notion-block-b8ba18ced33f4272a37eb595c49c961b"><div>出层的神经元数量一般设定为类别的数量。比如，对于某个输入图像，预测</div></blockquote><blockquote class="notion-quote notion-block-f5c8132f9dcf44ce8a2f4dce57327385"><div></div></blockquote><blockquote class="notion-quote notion-block-8793054bc9854b9383a917b86eab932d"><div>是图中的数字0到9中的哪一个的问题（10类别分类问题），</div></blockquote><blockquote class="notion-quote notion-block-2ea7f601e3f548d7a116226cba6f0b51"><div></div></blockquote><blockquote class="notion-quote notion-block-8252e0ad62b94019875979b8807a8af0"><div>所以我们将输出层的神经元设定为10个</div></blockquote><div class="notion-text notion-block-0228367371ef41499e26df76d305ddb2">介绍完神经网络的结构之后，现在我们来试着解决实际问题。这里我们</div><div class="notion-text notion-block-de778fa1ea2142dfb7453dc3cb06f164">来进行手写数字图像的分类。假设学习已经全部结束，我们使用学习到的参</div><div class="notion-text notion-block-ff96d243b31d41a4935bc2ed549190e9">数，先实现神经网络的“</div><div class="notion-text notion-block-b67e3be89ca34f93be3faf4564db142a">推理</div><div class="notion-text notion-block-0961401abe74472689e681379c40838f">处理”。这个推理处理也称为神经网络的**前向</div><div class="notion-text notion-block-c03bfb2b8f234d1e8e37fa527d1aa31f">传播（forward propagation）**。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-6c5a41e57a2f4c7691d57bd615ff64ff" data-id="6c5a41e57a2f4c7691d57bd615ff64ff"><span><div id="6c5a41e57a2f4c7691d57bd615ff64ff" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6c5a41e57a2f4c7691d57bd615ff64ff" title="MNIST数据集"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">MNIST数据集</span></span></h4><div class="notion-text notion-block-38f30f8be07b45db85d81fd6fef95771">这里使用的数据集是MNIST手写数字图像集。MNIST是</div><div class="notion-text notion-block-e95dfd8d8fcb4012aadc2958d3aa84c8">机器学习</div><div class="notion-text notion-block-79754939b72d4d0cad2c197eebd5950e">领域</div><div class="notion-text notion-block-a87c2c5c84b44b73a094a8b7d7a35a18">最有名的数据集之一，被应用于从简单的实验到发表的论文研究等各种场合。</div><div class="notion-text notion-block-8cb126928a6b45c1a59971a792847e32">实际上，在阅读图像识别或机器学习的论文时，MNIST数据集经常作为实</div><div class="notion-text notion-block-bcee0da0a235414a844fa534e936f9f6">验用的数据出现。</div><div class="notion-text notion-block-1c01aa3a4afe434584ef02393e9e49dc">MNIST数据集是由0到9的数字图像构成的。训练图像有6万张，</div><div class="notion-text notion-block-368af4b3867b452faeb7f6e63189ca0e">测试图像有1万张，这些图像可以用于学习和推理。MNIST数据集的一般</div><div class="notion-text notion-block-82f51b051a884ede9a68cab7acb58392">使用方法是，先用训练图像进行学习，再用学习到的模型度量能在多大程度</div><div class="notion-text notion-block-6ddcc8a01ac5420190693e150704a4b5">上对测试图像进行正确的分类</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-c199508a0376445eba54067f67d68c16"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/c199508a-0376-445e-ba54-067f67d68c16?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-2.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><div class="notion-text notion-block-18e270b5e96346bfb588d3cdf7d24550">NIST的图像数据是28像素 × 28像素的灰度图像（1通道），各个像素</div><div class="notion-text notion-block-8f647dfc84fa47abbe00977890b52d2c">的取值在0到255之间。每个图像数据都相应地标有“7”“2”“1”等标签</div><blockquote class="notion-quote notion-block-29f7d96109ed47a795e863890ed63ab2"><div>了解上面的知识差不多可以直接手写实现了</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-4128c64ee654401389ca622a4faaacf7" data-id="4128c64ee654401389ca622a4faaacf7"><span><div id="4128c64ee654401389ca622a4faaacf7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4128c64ee654401389ca622a4faaacf7" title="代码实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">代码实现</span></span></h4><pre class="notion-code language-python notion-code-id-14333081bbee409e88e374794783aae8" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import torch
from torchvision import datasets, transforms
from torch.utils.data import DataLoader
# 数据预处理：归一化
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])

# 加载训练集和测试集
train_dataset = datasets.MNIST(root=&#x27;./data&#x27;, train=True, download=True, transform=transform)
test_dataset = datasets.MNIST(root=&#x27;./data&#x27;, train=False, download=True, transform=transform)
# 加载训练集和测试集的DataLoader,每次加载64个样本,train_loader的shuffle参数设为True表示每次迭代时都打乱数据
train_loader = DataLoader(train_dataset, batch_size=64, shuffle=True)
test_loader = DataLoader(test_dataset, batch_size=64, shuffle=False)</code></pre><div class="notion-text notion-block-ee3944bc20f642219e3c865d8d7f9784">展示MNIST数据集</div><pre class="notion-code language-python notion-code-id-19279f981ebc4562bbcd1d1b1ad6cfc6" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 查看shape和图片
from matplotlib import pyplot as plt
print(train_dataset.train_data.shape)
fig=plt.figure()
for i in range(12):
    # 创建一个 3×4 的网格，共 12 个子图
    plt.subplot(3,4,i+1)
    # 自动调整子图之间的间距和边距
    plt.tight_layout()
    # 显示图片 ，&#x27;gray&#x27; 表示灰度图
    plt.imshow(train_dataset.train_data[i], cmap=&#x27;gray&#x27;)
    # 不显示x,y刻度
    plt.xticks([])
    plt.yticks([])
    # 设置标题
    plt.title(f&#x27;Label: {train_dataset.train_labels[i]}&#x27;)
# 显示图片
plt.show()</code></pre><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-02bf316b70b441c0a7edbd6cf6fcfb06"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/02bf316b-70b4-41c0-a7ed-bd6cf6fcfb06?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-5.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-0f50dfe674aa4f07ab0c3a8e45d32ae4" data-id="0f50dfe674aa4f07ab0c3a8e45d32ae4"><span><div id="0f50dfe674aa4f07ab0c3a8e45d32ae4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0f50dfe674aa4f07ab0c3a8e45d32ae4" title="定义神经网络"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">定义神经网络</span></span></h4><blockquote class="notion-quote notion-block-643802b88e16424ea226510b2fa6a001"><div>了解这个神经网络的组成</div></blockquote><blockquote class="notion-quote notion-block-2562795cb3284e8ca650d572e08f2f4e"><div></div></blockquote><blockquote class="notion-quote notion-block-fa47acf7a7944c239882acd3e006c595"><div></div></blockquote><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b45520015a5b420b90be33600af7374e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/b4552001-5a5b-420b-90be-33600af7374e?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-6.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-d31ead3ede7b4e808c9fe27cc1d1fb9f" data-id="d31ead3ede7b4e808c9fe27cc1d1fb9f"><span><div id="d31ead3ede7b4e808c9fe27cc1d1fb9f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d31ead3ede7b4e808c9fe27cc1d1fb9f" title="1.首先用到了一个二维卷积层,卷积原理如图"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.首先用到了一个二维卷积层,卷积原理如图</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-55bce6a6e26b476c934f2df816057533"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/55bce6a6-e26b-476c-934f-2df816057533?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-7.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><blockquote class="notion-quote notion-block-ee269f096cd64b6782574e0d9b97a272"><div><code class="notion-inline-code">torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding)</code></div></blockquote><div class="notion-text notion-block-1bdc616f02874a289972dc62e90e2895">参数：</div><div class="notion-text notion-block-379bc04e49694211895d97cf9abe0fb4"><code class="notion-inline-code">in_channels</code>：输入通道</div><div class="notion-text notion-block-fde58cfc73e7432b8e0ddeccdb15396a"><code class="notion-inline-code">out_channels</code>：输出通道</div><div class="notion-text notion-block-fa182cb6afcd4668809d9d8411859b6f"><code class="notion-inline-code">kernel_size</code>：卷积核大小</div><div class="notion-text notion-block-972d234fdf334974b6159be7fbd475ef"><code class="notion-inline-code">stride</code>：步长</div><div class="notion-text notion-block-1af3a45587124b4794939d46ef9c62e2"><code class="notion-inline-code">padding</code>：填充</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-0a32322dfe574be9a594b25d464a37e9" data-id="0a32322dfe574be9a594b25d464a37e9"><span><div id="0a32322dfe574be9a594b25d464a37e9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0a32322dfe574be9a594b25d464a37e9" title="2.激活层使用ReLU激活函数。"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.激活层使用ReLU激活函数。</span></span></h4><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-2cd3f25a51cc4d3696d11829cbc79b22"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/2cd3f25a-51cc-4d36-96d1-1829cbc79b22?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-8.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><blockquote class="notion-quote notion-block-dc32c509532e49a982f7181053f5740c"><div><code class="notion-inline-code">torch.nn.ReLU()</code></div></blockquote><blockquote class="notion-quote notion-block-1593d6934dc64a7f8fb3b86fd877fa81"><div></div></blockquote><blockquote class="notion-quote notion-block-39c484b426164e8380a58c2cc7f03016"><div>要手动实现也是很简单</div></blockquote><pre class="notion-code language-python notion-code-id-61a2c83410f5496ea6d592451939af7c" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def ReLU(x):
    return np.maximum(0, x)</code></pre><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-c244ea2af3224babb2ed66a0dd5e2442" data-id="c244ea2af3224babb2ed66a0dd5e2442"><span><div id="c244ea2af3224babb2ed66a0dd5e2442" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c244ea2af3224babb2ed66a0dd5e2442" title="3 池化层请添加图片描述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3 池化层请添加图片描述</span></span></h4><div class="notion-text notion-block-5c5911a293d14600a34c2fbbfe31819c">池化原理</div><blockquote class="notion-quote notion-block-b86d45d5d4ee404eb8193f7d4b7a5a66"><div><code class="notion-inline-code">torch.nn.MaxPool2d(input, kernel_size, stride, padding)</code></div></blockquote><div class="notion-text notion-block-b1c730b62b4a4cf898ae6c3ce43aa80d">这些参数上文已经说明</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-a6d93b3625004b5eb6d3303772007c0f" data-id="a6d93b3625004b5eb6d3303772007c0f"><span><div id="a6d93b3625004b5eb6d3303772007c0f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a6d93b3625004b5eb6d3303772007c0f" title="4 全连接层"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4 全连接层</span></span></h4><blockquote class="notion-quote notion-block-5aa18c0539294de68eb97e2278e55489"><div><code class="notion-inline-code">self.fc1 = nn.Linear(64 * 7 * 7, 128)</code></div></blockquote><blockquote class="notion-quote notion-block-5f0b7088f98e496788304912c6328b2e"><div></div></blockquote><blockquote class="notion-quote notion-block-90da7ea9cde0415786fa89700b8ec8ae"><div><code class="notion-inline-code">self.fc2 = nn.Linear(128, 10)</code></div></blockquote><div class="notion-text notion-block-ad37646e7392465fb0cf848e8b59aa31"><b>作用</b></div><div class="notion-text notion-block-6f43bbc13a664a46b0a2990bc042111a">维度转换：从空间特征到分类决策</div><div class="notion-text notion-block-49ee327d799a480b830f902d7a40ae77">输入处理：</div><div class="notion-text notion-block-fdd86bdc5b604fc69dc977fdbe779404">卷积层输出的四维张量 (B, C, W, H)（批大小、通道数、宽、高）通过 view 或 flatten 操作被展平为二维张量 (B, C*W*H)，即将空间和通道信息合并为一维特征向量。</div><div class="notion-text notion-block-bcb3669327144a7e8b295113e22951d6">例如：若卷积层输出为 (64, 128, 7, 7)，展平后为 (64, 128 * 7 * 7=6272)。</div><div class="notion-text notion-block-5ed97704b90347afb833d4ffb9bcb929">输出映射：</div><div class="notion-text notion-block-96072e02d7de447b89c428735214472f">全连接层通过权重矩阵将高维特征映射到目标维度（如分类类别数）。例如，输入 6272 维特征可通过全连接层输出 (64, 10)（10分类任务）。</div><div class="notion-text notion-block-d0924b1d2b3643ba8b235a08f2425d76">好的，我们已经了解了大概的结构组成</div><div class="notion-text notion-block-90b00c67f47547ec9c7ada0e7b135533"><b>接下来我们根据结构图来实现代码</b></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-d77ab53f7abf4b068ed904325a379c34"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" alt="notion image" loading="lazy" decoding="async" src="https://hllqk.cn/img/block/d77ab53f-7abf-4b06-8ed9-04325a379c34?src=https%3A%2F%2Fhllqkb-blog.pages.dev%2Fimages%2Fcsdn%2F150552932-10.png%3FspaceId%3D3770ce44-c347-41ad-9bb8-35b98c17fd91"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-81463e0307c0458c80dfdee1baae7320" data-id="81463e0307c0458c80dfdee1baae7320"><span><div id="81463e0307c0458c80dfdee1baae7320" class="notion-header-anchor"></div><a class="notion-hash-link" href="#81463e0307c0458c80dfdee1baae7320" title="神经网络的代码实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">神经网络的代码实现</span></span></h4><pre class="notion-code language-python notion-code-id-256e525faae243e983243e5333d91152" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import torch.nn as nn
import torch.nn.functional as F

# 定义一个简单的卷积神经网络（CNN），用于图像分类
class CNN(nn.Module):
    def __init__(self):
        super(CNN, self).__init__()
        # 第一层卷积：输入通道 1（灰度图），输出通道 32，卷积核大小 5x5，padding=2 保持尺寸不变
        self.conv1 = nn.Conv2d(1, 32, kernel_size=5, padding=2)
        # 第二层卷积：输入通道 32，输出通道 64，卷积核大小 5x5，同样 padding=2
        self.conv2 = nn.Conv2d(32, 64, kernel_size=5, padding=2)
        # 最大池化层，窗口大小 2x2，相当于下采样一半
        self.pool = nn.MaxPool2d(2)
        # 全连接层 1：输入 64*7*7 个特征，输出 128 个神经元
        self.fc1 = nn.Linear(64 * 7 * 7, 128)
        # 全连接层 2：输入 128，输出 10（对应 10 个类别，比如 MNIST）
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x):
        # 第一次卷积 -&gt; ReLU 激活 -&gt; 池化
        x = F.relu(self.pool(self.conv1(x)))
        # 第二次卷积 -&gt; ReLU 激活 -&gt; 池化
        x = F.relu(self.pool(self.conv2(x)))
        # 将特征图展平成一维向量，方便送入全连接层
        x = x.view(-1, 64 * 7 * 7)  # -1 表示自动计算 batch size
        # 第一个全连接层 + ReLU
        x = F.relu(self.fc1(x))
        # 第二个全连接层，输出 10 类
        x = self.fc2(x)
        return x

# 实例化模型
model = CNN()</code></pre><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-e093ccf646f64c2da070e2107a3dc6e0" data-id="e093ccf646f64c2da070e2107a3dc6e0"><span><div id="e093ccf646f64c2da070e2107a3dc6e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e093ccf646f64c2da070e2107a3dc6e0" title="定义"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">定义</span></span></h4><div class="notion-text notion-block-d641b9d7479e4b089ca8f6d6415e5583">损失函数</div><div class="notion-text notion-block-274d397259a04575a3ec6164ffddcca5">和优化器</div><div class="notion-text notion-block-a3acd5116ea3418ca070abafca37af04">使用交叉熵损失函数和</div><div class="notion-text notion-block-4ef864b826b94565959ef99dd9463fe1">Adam优化器</div><div class="notion-text notion-block-9f23e36085814983aab78264ac5db28f">：</div><pre class="notion-code language-python notion-code-id-296a4b0829b2402588b11df8a21ae301" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import torch.optim as optim
# 交叉熵损失函数用于分类问题
criterion = nn.CrossEntropyLoss()
# Adam优化器
optimizer = optim.Adam(model.parameters(), lr=0.001)</code></pre><ol start="1" class="notion-list notion-list-numbered notion-block-2338e13dc48245d982ca052a4a539555" style="list-style-type:decimal"><li>模型训练</li></ol><div class="notion-text notion-block-8fc41e284a5b4812bcebc40373fe8eb6">定义训练过程：</div><pre class="notion-code language-python notion-code-id-b2f7977887674507809bf8c0364a0b82" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">from tqdm import tqdm  # 用于显示进度条

def train_model(model, train_loader, optimizer, criterion, epochs=10):
    &quot;&quot;&quot;
    训练模型函数
    参数:
        model: 神经网络模型
        train_loader: 训练数据 DataLoader
        optimizer: 优化器 (如 Adam, SGD)
        criterion: 损失函数 (如 CrossEntropyLoss)
        epochs: 训练轮数
    &quot;&quot;&quot;
    model.train()  # 设置为训练模式（启用 dropout、BN 等）

    for epoch in range(epochs):  # 外层循环：共训练 epochs 轮
        running_loss = 0.0  # 记录一个 epoch 内的累计 loss

        # tqdm 用于显示进度条，每个 batch 迭代时会实时刷新
        progress_bar = tqdm(train_loader, desc=f&quot;Epoch {epoch+1}/{epochs}&quot;, leave=False)

        for images, labels in progress_bar:
            # 梯度清零（防止梯度累积）
            optimizer.zero_grad()

            # 前向传播
            outputs = model(images)

            # 计算损失
            loss = criterion(outputs, labels)

            # 反向传播
            loss.backward()

            # 参数更新
            optimizer.step()

            # 累加损失，用于 epoch 统计
            running_loss += loss.item()

            # tqdm 实时显示当前 batch 的 loss
            progress_bar.set_postfix({&quot;Batch Loss&quot;: f&quot;{loss.item():.4f}&quot;})

        # 一个 epoch 结束后，计算平均损失
        avg_loss = running_loss / len(train_loader)
        print(f&quot;Epoch [{epoch+1}/{epochs}] - Average Loss: {avg_loss:.4f}&quot;)</code></pre><ol start="1" class="notion-list notion-list-numbered notion-block-58a28b393826429ebeb3e53bcf623394" style="list-style-type:decimal"><li>模型测试</li></ol><div class="notion-text notion-block-6d1373ff58154de09394b4eaec42561c">定义测试过程并计算准确率：</div><pre class="notion-code language-python notion-code-id-ac1431fb6c7c4fb7a71a691d73c696b8" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">def test_model(model, test_loader):
    &quot;&quot;&quot;
    测试模型函数
    参数:
        model: 已训练好的神经网络模型
        test_loader: 测试数据 DataLoader
    &quot;&quot;&quot;
    model.eval()  # 设置为评估模式（关闭 dropout、BN 等）
    correct = 0   # 预测正确的样本数
    total = 0     # 总样本数

    # 测试时不需要计算梯度，节省显存和加速
    with torch.no_grad():
        # tqdm 进度条显示测试进度
        for images, labels in tqdm(test_loader, desc=&quot;Testing&quot;, leave=False):
            # 前向传播
            outputs = model(images)

            # 取概率最大的类别作为预测结果
            _, predicted = torch.max(outputs.data, 1)

            # 累加总数和正确数
            total += labels.size(0)
            correct += (predicted == labels).sum().item()

    # 计算总体准确率
    accuracy = 100 * correct / total
    print(f&quot;Test Accuracy: {accuracy:.2f}%&quot;)</code></pre><ol start="1" class="notion-list notion-list-numbered notion-block-b942eb314f984f9d903ec4908ae68e36" style="list-style-type:decimal"><li>开始训练与测试</li></ol><div class="notion-text notion-block-b4d7fe46387d4c4287ac3a5cd20597d0">运行训练和测试：</div><pre class="notion-code language-python notion-code-id-c3f714eebef24082bec056c2af07a155" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">if __name__ == &quot;__main__&quot;:
	train_model(model, train_loader,optimizer,criterion,epochs=10)
	test_model(model, test_loader)</code></pre><div class="notion-text notion-block-485001db84e84a818c43c2fdee25bd1b">输出</div><pre class="notion-code language-python notion-code-id-ea234e8a9e2e4c7492563b61c0d3d502" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">
Epoch [1/10] - Average Loss: 0.0391

Epoch [2/10] - Average Loss: 0.0239

Epoch [3/10] - Average Loss: 0.0176

Epoch [4/10] - Average Loss: 0.0134

Epoch [5/10] - Average Loss: 0.0105

Epoch [6/10] - Average Loss: 0.0102

Epoch [7/10] - Average Loss: 0.0085

Epoch [8/10] - Average Loss: 0.0069

Epoch [9/10] - Average Loss: 0.0058

Epoch [10/10] - Average Loss: 0.0084

Test Accuracy: 99.19%</code></pre><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-13133187b4f645169c487c6257818556" data-id="13133187b4f645169c487c6257818556"><span><div id="13133187b4f645169c487c6257818556" class="notion-header-anchor"></div><a class="notion-hash-link" href="#13133187b4f645169c487c6257818556" title="进行预测"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">进行预测</span></span></h4><pre class="notion-code language-python notion-code-id-c14a92a76858421b9a0a1d8aac4c2a77" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">import torch
from torchvision import transforms
from PIL import Image

def predict_image(model, image_path, class_names, transform=None, device=&quot;cpu&quot;):
    model.eval()  # 评估模式
    model.to(device) # 移动到指定设备

    # 打开图片
    image = Image.open(image_path).convert(&quot;L&quot;)  # 转灰度 (1 通道)，如果是彩色就改成 &quot;RGB&quot;

    # 预处理
    if transform is not None:
        image = transform(image)
    else:
        # 默认 transform: 转 tensor + 标准化
        image = transforms.ToTensor()(image)

    # 增加 batch 维度: [1, C, H, W]
    image = image.unsqueeze(0).to(device)

    with torch.no_grad():
        # 输出预测结果 tensor
        outputs = model(image)
        # softmax 归一化
        probs = torch.softmax(outputs, dim=1).cpu().numpy()  # 转成 NumPy
        print(f&quot;Probabilities: {probs.round(3)}&quot;)  # 打印并保留3位小数
        _, predicted = torch.max(outputs, 1)  # 获取预测类别索引

    predicted_class = class_names[predicted.item()]
    print(f&quot;Predicted Class: {predicted_class}&quot;)
    return predicted_class</code></pre><pre class="notion-code language-python notion-code-id-3f7e36d5a5f64a0dbe70fe5247617366" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python"># 定义类别
class_names = [str(i) for i in range(10)]  # 如果是MNIST: 0~9

# 单张图片预测
predict_image(model, &quot;../3.jpg&quot;, class_names, transform, device=&quot;cuda&quot;)</code></pre><div class="notion-text notion-block-56b7375aee54472e9458e5fe58e41fa7">输出结果</div><pre class="notion-code language-python notion-code-id-dd907453a6ac4a049d3ede247ba8890e" tabindex="0"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-python">Probabilities: [[0.001 0.047 0.027 0.831 0.002 0.049 0.002 0.026 0.009 0.006]]
Predicted Class: 3</code></pre></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>