瀏覽代碼

feat(chat): 打字机速度加快到主流上沿(61 → 121 字符/秒)

每次打出的字数 2 → 4,积压加速档位同步加倍。

基准取主流 AI 的实测输出速度(Claude 3.5 约 60 字符/秒、DeepSeek-R1 约 75,
主流区间 50~120),取区间上沿。原值 61 字符/秒数值上已等于 Claude 3.5,
但本项目后端一次返回整段、打字机是纯额外延迟,同样速度会明显比主流慢,
故取上沿使展开速度不再是瓶颈。

Co-Authored-By: Claude Code <noreply@anthropic.com>
gongtianxiao 4 天之前
父節點
當前提交
e83ce60778
共有 2 個文件被更改,包括 19 次插入6 次删除
  1. 4 0
      README.md
  2. 15 6
      src/components/Chat/TextContent.vue

+ 4 - 0
README.md

@@ -30,6 +30,10 @@
 
 ## 20260916
 
+- 打字机速度加快:每次打出字数 2 → 4(61 → **121 字符/秒**),积压加速档位同步上调。
+  基准取主流 AI 的实测输出速度(Claude 3.5 约 60 字符/秒、DeepSeek-R1 约 75,
+  主流区间 50~120),取区间上沿——因为本项目后端一次返回整段,打字机是纯额外延迟,
+  同样速度会比主流慢一整段
 - 「政策事项列表」统一为**一个列表、一个入口**:
   - 卡片区「更多 >>」与详情的「返回政策事项列表」**走同一条路径、内容相同**
   - 列表数据统一来自 `public/merchant-agent/policies_public.v1.json`

+ 15 - 6
src/components/Chat/TextContent.vue

@@ -87,14 +87,23 @@ const isTypingActive = ref(false)
 const lastContent = ref('') // 记录上一次的 content
 const batchRevealTerminalTags = new Set(["PRE", "CODE", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "TH", "TD"])
 const batchRevealListTags = new Set(["UL", "OL"])
+// 打字机速度。
+//
+// 基准参考主流 AI 的实测输出速度(字符口径):Claude 3.5 约 60 字符/秒、
+// DeepSeek-R1 约 75 字符/秒,主流区间 50~120,快速模型取的 120。
+//
+// 这里取区间**上沿**(4 字/33ms ≈ 121 字符/秒),原因:主流产品是模型边生成边流出,
+// 用户感知的等待约等于生成时间;而本项目的后端**一次返回整段**,打字机是纯额外延迟——
+// 同样 60 字符/秒会比主流慢一整段。取上沿让展开速度不再是瓶颈。
 const typingInterval = 33
-const typingCharsPerTick = 2
+const typingCharsPerTick = 4
+// 积压越多打得越快,避免长回答的展开明显落后于阅读
 const typingBurstThresholds = [
-  { pendingLength: 32, batchSize: 4 },
-  { pendingLength: 96, batchSize: 6 },
-  { pendingLength: 256, batchSize: 8 },
-  { pendingLength: 512, batchSize: 10 },
-  { pendingLength: 1024, batchSize: 12 },
+  { pendingLength: 32, batchSize: 8 },
+  { pendingLength: 96, batchSize: 12 },
+  { pendingLength: 256, batchSize: 16 },
+  { pendingLength: 512, batchSize: 20 },
+  { pendingLength: 1024, batchSize: 24 },
 ]
 const pendingCompactThreshold = 1000
 let lastTypewriterTickTime = 0