-
[issue-4114] [BE] Add model name normalization for dot-based Claude model variants (#4254)
发布于
2025-12-01 10:06:15 +00:00 - [issue-4114] [BE] Add model name normalization for dot-based Claude model variants
Fixes cost estimation for Claude model names with dots (e.g., claude-3.5-sonnet)
by normalizing them to hyphenated format (claude-3-5-sonnet) used in pricing database.Changes:
- Add findModelPrice() method with backwards-compatible fallback logic
- Add normalizeModelName() to replace dots with hyphens
- Try exact match first (maintains backwards compatibility)
- Fall back to normalized name if exact match fails
- Add comprehensive tests verifying both normalization and backwards compatibility
Resolves: #4114
- Revision 2: Add test for versioned Claude models with dots (issue #4114)
Adds specific test case for the exact models mentioned in the user complaint:
- claude-sonnet-4.5-20250929
- claude-haiku-4.5-20251001
These versioned models now correctly normalize from dot notation
to hyphenated format and return proper cost estimates.- Revision 3: Apply dot-to-hyphen normalization to ModelCapabilities and frontend
Extends issue #4114 fix to ensure consistent model name normalization across:
- Backend ModelCapabilities (vision capability detection)
- Frontend modelCapabilities.ts (UI vision checks)
This ensures vision capability detection works correctly for dot-notated models
like "claude-3.5-sonnet", "gemini-1.5-pro", matching the same fix applied
to cost calculation in CostService.Changes:
- Update ModelCapabilities.normalize() to replace dots with hyphens
- Update frontend normalizeModelName() with same logic
- Add comprehensive tests for dot notation in ModelCapabilitiesTest
- All 20 tests passing (11 ModelCapabilities + 9 CostService)
- Revision 4: Address Copilot PR review comments
Changes based on GitHub Copilot review feedback:
-
Simplify normalizeModelName() method:
- Remove redundant null/blank check since caller guarantees non-null
- Document precondition in JavaDoc
- Reduces unnecessary defensive code
-
Rename test for clarity:
- calculateCost_shouldHandleMultipleDotsInModelName_issue4114
→ calculateCost_shouldHandleUnknownModelWithDotsGracefully_issue4114 - Test name now matches actual behavior (graceful handling of unknown models)
- Updated assertion to check for exact zero (not >=)
- Improved comments to explain what's being tested
- calculateCost_shouldHandleMultipleDotsInModelName_issue4114
All 9 tests still passing.
- Revision 5: Fix Prettier formatting in modelCapabilities.ts
Remove trailing space in JSDoc comment that was causing linter error.
All linting now passes.- Revision 2: Address code review comments
- Remove @Nullable annotations from private method parameters per project convention
- Use StringUtils.isBlank for more robust null/blank validation
- Add lowercase normalization and case-insensitive comparison for better model matching
- Consolidate CostServiceTest into parameterized test (15 test cases, was 9)
- Consolidate ModelCapabilitiesTest into parameterized test (29 test cases, was 11)
- Improves test maintainability while increasing coverage
Changes per review feedback from @andrescrz and GitHub Copilot
下载附件