-
[BE] refactor: consolidate above_NNNk tier fields into PromptTier record (#7438)
发布于
2026-07-13 09:59:21 +00:00 - [BE] refactor: consolidate above_NNNk tier fields into PromptTier record
Follow-up cleanup to #7347. The above_128k, above_200k, and above_272k
tier rates lived as eight parallel fields on ModelPrice (input+output
for each of three thresholds, plus cache_creation/cache_read at 200k).
Each new field required updating ModelPrice + defaultBuilder +
CostService.buildModelPrice + the effective-price helpers. baz-reviewer
called out the resulting duplication on #7347 (Code Dedup and
Conventions), and Andres explicitly left it as a follow-up.Replace the eight fields with a single List on ModelPrice,
where PromptTier is a nested record carrying (threshold, inputPrice,
outputPrice, cacheCreationInputTokenPrice, cacheReadInputTokenPrice).
CostService.buildModelPrice appends a tier when at least one of its
per-rate JSON values is non-zero, in descending-threshold order, so
the effective helpers walk the list once and pick the first applicable
non-zero rate. Behavior is preserved 1:1: any tier the JSON does not
publish for a model (e.g. cache rates at 128k/272k, or every tier for a
non-flagship model) simply isn't added to the list, and the effective
helpers fall through to the base rate — matching the previous "field
defaulted to ZERO, useTier returned false" semantics.Concrete wins:
- ModelPrice record shrinks from 17 to 10 fields.
- Four effective-* helpers collapse to a single applicableTier(...)
private walker parameterized by the rate accessor. - Adding a future threshold is a two-line change (new constant + one
call to addTierIfPresent in buildModelPrice) with zero effective-rate
method churn.
All 100 tests in CostServiceTest + SpanCostCalculatorTest green locally;
no test fixture needed updating because they use CostService.calculateCost
end-to-end, not the ModelPrice tier fields directly.- [BE] refactor: use builder pattern for PromptTier record per SKILL
Addressing baz-reviewer's AI-Coding-Guidelines finding on #7438.
.agents/skills/opik-backend/SKILL.mdrequires@Builder(toBuilder = true)
on records and construction via the builder rather than the constructor.Annotate PromptTier with @Builder(toBuilder = true) and switch the single
call site in CostService.addTierIfPresent(...) from
new ModelPrice.PromptTier(...)to
ModelPrice.PromptTier.builder()...build().Behavior preserved 1:1; all 100 tests in CostServiceTest +
SpanCostCalculatorTest still green.
Co-authored-by: Andres Cruz andresc@comet.com
下载附件