发布

  • [issue-5018] [BE] Add fallback logic to strip date suffixes from model names for cost calculation (#5047)

    frostbyte_neo 发布于 2026-02-24 10:24:00 +00:00

    • [issue-5018] [BE] Add fallback logic to strip date suffixes from model names for cost calculation

    Fixes issue where OpenAI returns dated model names (e.g., gpt-5.2-2025-12-17)
    but the pricing database only has the base model name (e.g., gpt-5.2).

    Changes:

    • Enhanced findModelPrice() to try stripping date suffixes (YYYY-MM-DD format)
      after trying exact match and normalized name lookups
    • Added stripDateSuffix() method to handle date pattern removal
    • Added comprehensive unit tests for the new fallback logic
    • Tests verify that models like gpt-5.2-2025-12-17 correctly fall back to gpt-5.2

    This ensures cost tracking works for gpt-5.2 and future dated model variants.

    Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

    • [PR-5047] Address feedback on apps/opik-backend/src/main/java/com/comet/opik/domain/cost/CostService.java
    • Encapsulate toLowerCase inside stripDateSuffix
    • Use equalsIgnoreCase for comparisons

    Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

    • [PR-5047] Address feedback on apps/opik-backend/src/main/java/com/comet/opik/domain/cost/CostService.java
    • Add Locale import and replace inline java.util.Locale.ROOT with Locale.ROOT

    Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

    • [PR-5047] Address feedback on apps/opik-backend/src/main/java/com/comet/opik/domain/cost/CostService.java
    • Check original date-stripped name before normalized date-stripped name
    • Simplify block-scoped inner vars to normalizedKey/normalizedMatch

    Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

    • [PR-5047] Address feedback on apps/opik-backend/src/main/java/com/comet/opik/domain/cost/CostService.java
    • Extract date suffix regex to static final constant DATE_SUFFIX_PATTERN

    Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

    • [PR-5047] Address feedback on apps/opik-backend/src/test/java/com/comet/opik/domain/cost/CostServiceTest.java
    • Split issue5018 test: separate parameterized test for positive cases,
      dedicated @Test for zero-cost case; removes if-in-assertion anti-pattern

    Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

    • [PR-5047] Address feedback on apps/opik-backend/src/test/java/com/comet/opik/domain/cost/CostServiceTest.java
    • Remove duplicate test cases from provideModelNamesWithDateSuffixes
    • Add missing case for stripped date on normalized name (dots+date suffix)

    Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com


    Co-authored-by: Douglas Blank doug@comet.com
    Co-authored-by: Claude Sonnet 4.5 noreply@anthropic.com

    下载附件