Update 大模型应用.md

补充模型训练与量化、工具调用的实现、AI 编程助手和 Harness 等内容。
This commit is contained in:
CyC2018
2026-10-26 22:04:04 +08:00
parent 07db1f5e9e
commit 74dc880742
7 changed files with 408 additions and 8 deletions
+82
View File
@@ -0,0 +1,82 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="470" viewBox="0 0 760 470">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">AI 编程助手修复一个失败的测试(示意)</text>
<circle cx="46" cy="61" r="9" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<path d="M29,92 q0,-19 17,-19 q17,0 17,19 z" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="46" y="108" class="c sub b">开发者</text>
<path d="M86,54 h238 q6,0 6,6 v28 q0,6 -6,6 H98 l-8,8 l0,-8 H86 q-6,0 -6,-6 v-28 q0,-6 6,-6 z" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="92" y="78" class="sub" style="fill:#444">“OrderServiceTest 挂了,修一下”</text>
<text x="30" y="152" class="sub b" style="fill:#444">收集上下文</text>
<rect x="110" y="130" width="64" height="34" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="142" y="151" class="c sub b mono" style="fill:#444">Bash</text>
<rect x="178" y="130" width="330" height="34" rx="4" fill="#FFFFFF" stroke="#CCC"/>
<text x="188" y="152" class="sub" style="fill:#444">mvn test → 1 个测试失败:期望 59.9,实际 0.0</text>
<rect x="110" y="182" width="64" height="34" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="142" y="203" class="c sub b mono" style="fill:#444">Grep</text>
<rect x="178" y="182" width="330" height="34" rx="4" fill="#FFFFFF" stroke="#CCC"/>
<text x="188" y="204" class="sub" style="fill:#444">grep -rn "calcAmount" src/ → OrderService.java:42</text>
<line x1="142" y1="166" x2="142" y2="180" class="arrow "/>
<rect x="110" y="234" width="64" height="34" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="142" y="255" class="c sub b mono" style="fill:#444">Read</text>
<rect x="178" y="234" width="330" height="34" rx="4" fill="#FFFFFF" stroke="#CCC"/>
<text x="188" y="256" class="sub" style="fill:#444">读取 OrderService.java 第 30~60 行</text>
<line x1="142" y1="218" x2="142" y2="232" class="arrow "/>
<text x="30" y="308" class="sub b" style="fill:#444">修改</text>
<rect x="110" y="286" width="64" height="34" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
<text x="142" y="307" class="c sub b mono" style="fill:#444">Edit</text>
<rect x="178" y="286" width="330" height="34" rx="4" fill="#FFFFFF" stroke="#CCC"/>
<text x="188" y="308" class="sub" style="fill:#444">把 discount 为 null 时的分支改为按原价计算</text>
<line x1="142" y1="270" x2="142" y2="284" class="arrow "/>
<text x="30" y="360" class="sub b" style="fill:#444">验证</text>
<rect x="110" y="338" width="64" height="34" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="142" y="359" class="c sub b mono" style="fill:#444">Bash</text>
<rect x="178" y="338" width="330" height="34" rx="4" fill="#FFFFFF" stroke="#CCC"/>
<text x="188" y="360" class="sub" style="fill:#444">mvn test → 全部通过</text>
<line x1="142" y1="322" x2="142" y2="336" class="arrow "/>
<path d="M110,355 C70,355 70,147 106,147" class="arrow dash"/>
<text x="64" y="256" class="sub e">失败就</text>
<text x="64" y="272" class="sub e">继续循环</text>
<text x="110" y="404" class="sub">每一步都是一次模型调用:模型选择工具,应用执行后把输出放回上下文。</text>
<text x="540" y="140" class="b">上下文中有什么</text>
<rect x="540" y="152" width="190" height="34" rx="4" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="635" y="173" class="c sub" style="fill:#444">系统提示词、工具定义</text>
<rect x="540" y="190" width="190" height="34" rx="4" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="635" y="211" class="c sub" style="fill:#444">CLAUDE.md 等项目约定</text>
<rect x="540" y="228" width="190" height="110" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="635" y="287" class="c sub" style="fill:#444">对话和每次工具的输出</text>
<line x1="540" y1="348" x2="730" y2="348" stroke="#C0605A" stroke-dasharray="4 3"/>
<text x="635" y="364" class="c sub note">接近上限时压缩为摘要</text>
<text x="540" y="396" class="sub">子 Agent 在自己的上下文中</text>
<text x="540" y="412" class="sub">搜索大量文件,只返回结论</text>
<text x="30" y="448" class="sub">修改文件前自动保存快照,可以撤销;执行命令、修改文件前按权限设置决定是否请求开发者确认。</text>
</svg>

After

Width:  |  Height:  |  Size: 5.9 KiB

+92
View File
@@ -0,0 +1,92 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="490" viewBox="0 0 760 490">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">Harness 中的引导与反馈:以分层规范为例</text>
<text x="30" y="70" class="b">引导:动手之前</text>
<rect x="30" y="84" width="190" height="44" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="125" y="104" class="b c">CLAUDE.md、AGENTS.md</text>
<text x="125" y="119" class="sub c">Controller 只能调用 Service</text>
<line x1="220" y1="106" x2="240" y2="106" class="line"/>
<rect x="30" y="140" width="190" height="44" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="125" y="160" class="b c">架构文档、代码示例</text>
<text x="125" y="175" class="sub c">需要时再读取</text>
<line x1="220" y1="162" x2="240" y2="162" class="line"/>
<rect x="30" y="196" width="190" height="44" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="125" y="216" class="b c">Skill</text>
<text x="125" y="231" class="sub c">按需加载的操作步骤</text>
<line x1="220" y1="218" x2="240" y2="218" class="line"/>
<line x1="240" y1="106" x2="240" y2="218" class="line"/>
<line x1="240" y1="106" x2="288" y2="106" class="arrow "/>
<rect x="290" y="84" width="180" height="44" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
<text x="380" y="104" class="b c">Agent</text>
<text x="380" y="119" class="sub c">模型 + Agent 循环</text>
<line x1="380" y1="128" x2="380" y2="154" class="arrow "/>
<rect x="290" y="156" width="180" height="76" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<line x1="290" y1="170" x2="470" y2="170" stroke="#BBBBBB" stroke-width="1"/>
<circle cx="299" cy="163" r="2.2" fill="#BBBBBB"/>
<circle cx="307" cy="163" r="2.2" fill="#BBBBBB"/>
<circle cx="315" cy="163" r="2.2" fill="#BBBBBB"/>
<text x="299" y="186" class="sub mono">OrderController.java</text>
<text x="299" y="202" class="sub mono">mapper.selectById(id);</text>
<text x="380" y="250" class="c sub">Agent 第一次写的代码</text>
<text x="380" y="264" class="c sub note">跳过了 Service 层</text>
<text x="540" y="70" class="b">反馈:动手之后</text>
<rect x="540" y="84" width="190" height="44" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="635" y="104" class="b c">编译、单元测试</text>
<text x="635" y="119" class="sub c">确定,速度快</text>
<rect x="540" y="140" width="190" height="44" rx="6" fill="#E6E3FA" stroke="#B8B0DE"/>
<text x="635" y="160" class="b c">架构检查(ArchUnit)</text>
<text x="635" y="175" class="sub c">确定,速度快</text>
<rect x="540" y="196" width="190" height="44" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="635" y="216" class="b c">模型审查</text>
<text x="635" y="231" class="sub c">能查语义,较慢且不确定</text>
<line x1="470" y1="194" x2="538" y2="162" class="arrow "/>
<path d="M730,162 C752,180 752,260 738,296" class="arrow red"/>
<text x="732" y="284" class="e sub note">未通过</text>
<rect x="30" y="298" width="700" height="102" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
<line x1="30" y1="312" x2="730" y2="312" stroke="#BBBBBB" stroke-width="1"/>
<circle cx="39" cy="305" r="2.2" fill="#BBBBBB"/>
<circle cx="47" cy="305" r="2.2" fill="#BBBBBB"/>
<circle cx="55" cy="305" r="2.2" fill="#BBBBBB"/>
<text x="39" y="328" class="sub mono">Architecture Violation [Priority: MEDIUM] - Rule 'no classes that reside in a package</text>
<text x="39" y="344" class="sub mono">'..controller..' should depend on classes that reside in a package '..mapper..',</text>
<text x="39" y="360" class="sub mono">because Controller 只能调用 Service' was violated (3 times):</text>
<text x="39" y="376" class="sub mono">Method &lt;OrderController.get(long)&gt; calls method &lt;OrderMapper.selectById(long)&gt;</text>
<text x="39" y="392" class="sub mono">in (OrderController.java:7)</text>
<path d="M262,296 C262,200 270,150 296,130" class="arrow"/>
<text x="272" y="290" class="sub" style="fill:#444">错误信息作为工具结果发回,Agent 改为调用 OrderService</text>
<circle cx="60" cy="423" r="9" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<path d="M43,454 q0,-19 17,-19 q17,0 17,19 z" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
<text x="92" y="430" class="sub" style="fill:#444">开发者:同一个问题反复出现时,补一条规范(引导)或一个检查(反馈),而不是每次在对话中纠正。</text>
<text x="92" y="448" class="sub">确定的检查放在前面,便宜又可靠;模型审查用来发现规则写不出来的问题。</text>
<text x="30" y="478" class="sub">错误信息是本机用 ArchUnit 1.3 检查示例代码的真实输出,省略了包名。</text>
</svg>

After

Width:  |  Height:  |  Size: 6.2 KiB

+69
View File
@@ -0,0 +1,69 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="420" viewBox="0 0 760 420">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">Qwen2.5-7B 实际收到和输出的文本</text>
<rect x="30" y="54" width="520" height="22" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="40" y="69" class="sub mono" style="fill:#444">&lt;|im_start|&gt;system</text>
<text x="566" y="69" class="sub">系统消息</text>
<rect x="30" y="79" width="520" height="22" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="40" y="94" class="sub mono" style="fill:#444">你是电商客服助手,回答要简短。</text>
<rect x="30" y="104" width="520" height="22" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="40" y="119" class="sub mono" style="fill:#444"># Tools ... &lt;tools&gt;</text>
<text x="566" y="119" class="sub">推理服务按模板</text>
<rect x="30" y="129" width="520" height="22" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="40" y="144" class="sub mono" style="fill:#444">{"name": "get_order", "description": "按订单号查询…"}</text>
<text x="566" y="144" class="sub">拼入的工具定义</text>
<rect x="30" y="154" width="520" height="22" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
<text x="40" y="169" class="sub mono" style="fill:#444">{"name": "get_logistics", ...}&lt;/tools&gt;</text>
<rect x="30" y="179" width="520" height="22" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="40" y="194" class="sub mono" style="fill:#444">&lt;|im_start|&gt;user 订单 1024 到哪了?</text>
<text x="566" y="194" class="sub">用户消息</text>
<rect x="30" y="204" width="520" height="22" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
<text x="40" y="219" class="sub mono" style="fill:#444">&lt;|im_start|&gt;assistant</text>
<rect x="30" y="229" width="520" height="22" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="40" y="244" class="sub mono" style="fill:#444">&lt;tool_call&gt;</text>
<text x="566" y="244" class="sub">模型生成的文本</text>
<rect x="30" y="254" width="520" height="22" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="40" y="269" class="sub mono" style="fill:#444">{"name": "get_order", "arguments": {"order_id": "1024"}}</text>
<rect x="30" y="279" width="520" height="22" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
<text x="40" y="294" class="sub mono" style="fill:#444">&lt;/tool_call&gt;</text>
<rect x="30" y="304" width="520" height="22" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="40" y="319" class="sub mono" style="fill:#444">&lt;|im_start|&gt;user</text>
<text x="566" y="319" class="sub">应用执行工具后,</text>
<rect x="30" y="329" width="520" height="22" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="40" y="344" class="sub mono" style="fill:#444">&lt;tool_response&gt;{"status": "已发货", "tracking_no": "SF1234567"}</text>
<text x="566" y="344" class="sub">把结果放回去</text>
<rect x="30" y="354" width="520" height="22" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
<text x="40" y="369" class="sub mono" style="fill:#444">&lt;/tool_response&gt;</text>
<text x="30" y="401" class="sub">第 2 次调用时,上面的全部文本加上工具结果一起重新发给模型,共 327 个 Token;第 1 次是 255 个。</text>
<text x="30" y="419" class="sub">tool_calls、tool 角色这些结构化字段,在模型看来都只是这样一段特定格式的文本。</text>
</svg>

After

Width:  |  Height:  |  Size: 5.0 KiB