fix: move tool_costs outside the tier_rate computing#204
Conversation
审查者指南(在小型 PR 上折叠显示)审查者指南调整消耗计算逻辑,使工具成本在应用分级费率倍数之后再进行添加,而不是与基础成本和 Token 成本一起乘以分级费率。 更新后的消耗计算逻辑流程图flowchart TD
A[Start calculate] --> B[Read input_tokens and output_tokens from ConsumptionContext]
B --> C[Compute token_cost = input_tokens * INPUT_TOKEN_RATE + output_tokens * OUTPUT_TOKEN_RATE]
C --> D[Compute base_amount = BASE_COST + token_cost]
D --> E["Compute tiered_amount = int(base_amount * tier_rate)"]
E --> F[Compute final_amount = tiered_amount + tool_costs]
F --> G[Return ConsumptionResult with amount = final_amount]
文件级别改动
技巧和命令与 Sourcery 交互
自定义你的使用体验打开你的 dashboard 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the consumption calculation so that tool costs are added after applying the tier rate multiplier, rather than being multiplied by the tier rate along with base and token costs. Flow diagram for updated consumption calculation logicflowchart TD
A[Start calculate] --> B[Read input_tokens and output_tokens from ConsumptionContext]
B --> C[Compute token_cost = input_tokens * INPUT_TOKEN_RATE + output_tokens * OUTPUT_TOKEN_RATE]
C --> D[Compute base_amount = BASE_COST + token_cost]
D --> E["Compute tiered_amount = int(base_amount * tier_rate)"]
E --> F[Compute final_amount = tiered_amount + tool_costs]
F --> G[Return ConsumptionResult with amount = final_amount]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些总体反馈:
- 行内注释
# Tier rate multiplies ALL costs (including tool costs)现在已经过时了,因为context.tool_costs是在应用tier_rate之后才被加上的,请更新该注释以反映新的行为。 - 请考虑舍入行为的变化是否是有意为之:之前
tool_costs被包含在传给int(...)的值中,而现在它们是在截断之后再相加的,这会在某些输入下略微改变总金额。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The inline comment `# Tier rate multiplies ALL costs (including tool costs)` is now outdated given that `context.tool_costs` are added after applying `tier_rate`, so please update the comment to reflect the new behavior.
- Consider whether the change in rounding behavior is intentional: previously `tool_costs` were included in the value passed to `int(...)`, whereas now they are added after truncation, which can slightly change total amounts for some inputs.
## Individual Comments
### Comment 1
<location> `service/app/core/consume_strategy.py:102-104` </location>
<code_context>
token_cost = context.input_tokens * self.INPUT_TOKEN_RATE + context.output_tokens * self.OUTPUT_TOKEN_RATE
# Tier rate multiplies ALL costs (including tool costs)
- base_amount = self.BASE_COST + token_cost + context.tool_costs
- final_amount = int(base_amount * tier_rate)
+ base_amount = self.BASE_COST + token_cost
+ final_amount = int(base_amount * tier_rate) + context.tool_costs
return ConsumptionResult(
</code_context>
<issue_to_address>
**issue:** The inline comment no longer matches the updated calculation for tool costs.
The code now excludes `context.tool_costs` from the tier multiplier while the inline comment says all costs are multiplied. Please either update the comment to match the current behavior (tool costs are added after applying `tier_rate`) or, if tool costs are meant to scale with `tier_rate`, revert the calculation so they are included in `base_amount` before the multiplier.
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The inline comment
# Tier rate multiplies ALL costs (including tool costs)is now outdated given thatcontext.tool_costsare added after applyingtier_rate, so please update the comment to reflect the new behavior. - Consider whether the change in rounding behavior is intentional: previously
tool_costswere included in the value passed toint(...), whereas now they are added after truncation, which can slightly change total amounts for some inputs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The inline comment `# Tier rate multiplies ALL costs (including tool costs)` is now outdated given that `context.tool_costs` are added after applying `tier_rate`, so please update the comment to reflect the new behavior.
- Consider whether the change in rounding behavior is intentional: previously `tool_costs` were included in the value passed to `int(...)`, whereas now they are added after truncation, which can slightly change total amounts for some inputs.
## Individual Comments
### Comment 1
<location> `service/app/core/consume_strategy.py:102-104` </location>
<code_context>
token_cost = context.input_tokens * self.INPUT_TOKEN_RATE + context.output_tokens * self.OUTPUT_TOKEN_RATE
# Tier rate multiplies ALL costs (including tool costs)
- base_amount = self.BASE_COST + token_cost + context.tool_costs
- final_amount = int(base_amount * tier_rate)
+ base_amount = self.BASE_COST + token_cost
+ final_amount = int(base_amount * tier_rate) + context.tool_costs
return ConsumptionResult(
</code_context>
<issue_to_address>
**issue:** The inline comment no longer matches the updated calculation for tool costs.
The code now excludes `context.tool_costs` from the tier multiplier while the inline comment says all costs are multiplied. Please either update the comment to match the current behavior (tool costs are added after applying `tier_rate`) or, if tool costs are meant to scale with `tier_rate`, revert the calculation so they are included in `base_amount` before the multiplier.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| # Tier rate multiplies ALL costs (including tool costs) | ||
| base_amount = self.BASE_COST + token_cost + context.tool_costs | ||
| final_amount = int(base_amount * tier_rate) | ||
| base_amount = self.BASE_COST + token_cost | ||
| final_amount = int(base_amount * tier_rate) + context.tool_costs |
There was a problem hiding this comment.
issue: 行内注释不再与工具成本的最新计算方式一致。
现在代码将 context.tool_costs 排除在层级乘数之外,但行内注释却说明所有成本都会被乘以该系数。请更新注释以匹配当前行为(工具成本是在应用 tier_rate 之后再相加),或者如果工具成本本来就应该随 tier_rate 一起缩放,请恢复为之前的计算方式,使它们在乘数之前就被包含在 base_amount 中。
Original comment in English
issue: The inline comment no longer matches the updated calculation for tool costs.
The code now excludes context.tool_costs from the tier multiplier while the inline comment says all costs are multiplied. Please either update the comment to match the current behavior (tool costs are added after applying tier_rate) or, if tool costs are meant to scale with tier_rate, revert the calculation so they are included in base_amount before the multiplier.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
## [1.0.10](v1.0.9...v1.0.10) (2026-01-26) ### 🐛 Bug Fixes * move tool_costs outside the tier_rate computing ([#204](#204)) ([f391ca9](f391ca9))
|
🎉 This PR is included in version 1.0.10 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
变更内容
简要描述本次 PR 的主要变更内容。
相关 Issue
请关联相关 Issue(如有):#编号
检查清单
默认已勾选,如不满足,请检查。
其他说明
如有特殊说明或注意事项,请补充。
Summary by Sourcery
Bug Fixes:
Original summary in English
Summary by Sourcery
Bug Fixes: