Skip to content

Conversation

@versun
Copy link
Owner

@versun versun commented Dec 11, 2025

问题描述

在 PR #139 合并后,发现 merge_system_prompt 功能中存在 token 计算逻辑错误。

修复的问题

  1. Token 计算错误:修复了 max_usable_tokens 在合并模式下的计算逻辑
    • merge_system_prompt=True 时,需要正确计算 system_prompt 的 token 占用
  2. 重复计算:移除了重复的 input_tokens 计算(第 335 行)
  3. 逻辑一致性:确保所有 token 计算路径的一致性

潜在影响

这些问题可能导致:

  • Token 计算错误,导致 API 调用失败或产生意外费用
  • 分块逻辑错误,导致内容处理不正确
  • 输出 token 限制计算错误,导致响应被截断

测试

  • Token 计算逻辑正确
  • 合并模式和非合并模式都能正常工作
  • 分块处理逻辑正确
  • 代码通过 lint 检查

相关 PR

修复 PR #139 中发现的问题。

修复了 merge_system_prompt 功能中的以下问题:
1. 修复了 max_usable_tokens 在合并模式下的计算逻辑
2. 移除了重复的 input_tokens 计算
3. 确保所有 token 计算路径的一致性

这些问题可能导致:
- Token 计算错误,导致 API 调用失败
- 分块逻辑错误,导致内容处理不正确
- 输出 token 限制计算错误,导致响应被截断
@cloudflare-workers-and-pages
Copy link

Deploying rss-translator-home with  Cloudflare Pages  Cloudflare Pages

Latest commit: efcf875
Status: ✅  Deploy successful!
Preview URL: https://b3029366.rss-translator-home.pages.dev
Branch Preview URL: https://fix-token-calculation-merge.rss-translator-home.pages.dev

View logs

@versun versun merged commit 8b05f4e into main Dec 11, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants