feat(token): Add consumed mode for quota management (opt-in)#315
Open
fno2010 wants to merge 3 commits intochenyme:mainfrom
Open
feat(token): Add consumed mode for quota management (opt-in)#315fno2010 wants to merge 3 commits intochenyme:mainfrom
fno2010 wants to merge 3 commits intochenyme:mainfrom
Conversation
- Add 'consumed_mode_enabled' config option (opt-in, default false) - Track local consumption separately from API quota - consumed increases in both modes; quota deduction differs by mode - Prefer tokens with lower consumed amount in pool selection - UI dynamically switches between 'remaining quota' and 'consumed' display - Disable quota editing in edit modal when consumed mode is enabled - Maintain backward compatibility with existing configs
- Reset consumed to 0 when quota reaches 0 in default mode (consume()) - Reset consumed to 0 when 429 rate limit is triggered (mark_rate_limited()) - Remove consumed reset on API sync, only restore active status - This ensures consumed represents 'usage count per cooling cycle'
在 consumed 模式下,移除错误的『新旧 token 分离逻辑』,改为直接在所有 available token 中选择 consumed 最少的。 问题根因: - 原逻辑将 consumed > 0 的 token 标记为『新逻辑』并优先选择 - 导致一旦某个 token 被使用过,其他 consumed=0 的 token 就永久被排除 - 造成单个 token 过载,其他 token 闲置的问题 修复方案: - 删除 new_logic_tokens 和 old_logic_tokens 的分离逻辑 - 直接在所有 available token 中按 consumed 排序,选择最少的 - 确保所有 token 都能参与负载均衡,实现真正的消耗均衡 测试验证: - 5 个 token,10 次请求,每个 token 恰好被选择 2 次 - 负载均衡差异为 0,符合预期
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
本 PR 是针对 Issue #205 中 Token 额度管理机制优化建议的初步实现,提供了 Issue 中提出的"消耗记录模式"作为可选特性。
已实现功能
consumed_mode_enabled配置项(默认关闭,保持向后兼容)待改进项
风险提示
Changes
Related Issues
Closes #205
Verification
验证说明:
本地测试通过,功能正常运行
Breaking Changes