refactor: Remove redundant backup file - #16590
Conversation
- Removed litellm/model_prices_and_context_window_backup.json - Updated get_model_cost_map() to read from single source - Refactored _load_local_model_cost_map() to support: * Package resources (production/pip install) * Project root (development) - Updated CI/CD workflows: * .circleci/config.yml: Copy to litellm/ before publishing * .github/workflows/simple_pypi_publish.yml: Same approach * ci_cd/check_files_match.py: Updated file paths - Updated test_get_model_file.py to use project root - Renamed test_get_backup_model_cost_map → test_get_local_model_cost_map Benefits: - Eliminates file duplication - Single source of truth for model pricing - No need for PRs like BerriAI#16460 to sync backup files - Simpler maintenance The backup was unnecessary because CI copies the file to the package before publishing.
|
@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR eliminates the long-standing dual-file maintenance burden by removing
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/get_model_cost_map.py | Core loading logic refactored to try package resources first, then fall back to project root. Exception handling remains narrow (FileNotFoundError, ModuleNotFoundError only) — remaining open concerns from previous threads. |
| tests/local_testing/test_get_model_file.py | Test now correctly exercises the production loading path via GetModelCostMap.load_local_model_cost_map(). Three imports (traceback, importlib.resources, json) are now unused and should be removed. |
| tests/test_litellm/test_deepseek_model_metadata.py | _load_backup_json() renamed to _load_model_cost_json() and now delegates to GetModelCostMap.load_local_model_cost_map(). Tests are equivalent in coverage with a cleaner loading path. |
| .gitignore | Properly adds litellm/model_prices_and_context_window.json on a new line (the missing trailing newline from the original file was fixed). Both patterns are now valid. |
| .pre-commit-config.yaml | Correctly removes the now-unnecessary check-files-match pre-commit hook alongside the deletion of ci_cd/check_files_match.py. |
| ci_cd/check_files_match.py | File deleted as expected — the sync check is no longer needed with a single source of truth. |
| .circleci/config.yml | CI step updated to copy model_prices_and_context_window.json → litellm/model_prices_and_context_window.json before publish instead of the old backup filename. |
| .github/workflows/simple_pypi_publish.yml | GitHub Actions publish workflow updated in lockstep with CircleCI — copies to the new canonical package path. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[get_model_cost_map called] --> B{LITELLM_LOCAL_MODEL_COST_MAP=True?}
B -- Yes --> C[load_local_model_cost_map]
B -- No --> D[fetch_remote_model_cost_map URL]
D -- Network error --> C
D -- Success --> E{validate_model_cost_map}
E -- Fail --> C
E -- Pass --> F[Return remote map + expand aliases]
C --> G{Try: importlib.resources\nfiles litellm .joinpath\nmodel_prices_and_context_window.json}
G -- FileNotFoundError /\nModuleNotFoundError --> H[Fallback: Path __file__ .parent.parent.parent\nmodel_prices_and_context_window.json]
G -- Success --> I[Return package resource map]
H --> J[Return project-root map]
I --> K[expand_model_aliases + return]
J --> K
Comments Outside Diff (1)
-
tests/local_testing/test_get_model_file.py, line 1-3 (link)Stale imports left behind after refactor
After removing
test_get_backup_model_cost_map, three top-level imports are now unused:traceback,importlib.resources, andjson. The newtest_get_local_model_cost_maponly uses a locally-scopedfrom litellm...import. Linters (e.g.flake8 F401) will warn on these.
Last reviewed commit: "Merge remote-trackin..."
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The hook kept the backup JSON in sync with the root file — no longer needed now that the backup file has been removed.
- Update load_local_model_cost_map to use project root fallback for dev - Keep main's validation, aliases, and source info tracking - Remove backup JSON (purpose of this PR)
Prevent accidental commits of the CI-generated copy.
…or/remove-backup-file-dry-principle # Conflicts: # litellm/model_prices_and_context_window_backup.json
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…e-backup-file-dry-principle # Conflicts: # litellm/model_prices_and_context_window_backup.json
62df632
into
BerriAI:litellm_staging_03_21_2026
…file-dry-principle refactor: Remove redundant backup file
Title
Remove redundant backup file for model pricing
Relevant issues
Closes #16460
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hardrequirement - see details
make test-unitType
🧹 Refactoring
Changes
Summary
Removed the redundant
litellm/model_prices_and_context_window_backup.jsonfile and refactored the codebase to use a single source of truth for model pricing data.model_prices_and_context_window.json(root) andlitellm/model_prices_and_context_window_backup.jsonSolution
litellm/model_prices_and_context_window_backup.json(24,718 lines deleted)get_model_cost_map()to read from single source:model_prices_and_context_window.json.circleci/config.yml: Changed to copy main file to package before publish.github/workflows/simple_pypi_publish.yml: Same approachci_cd/check_files_match.py: Updated file pathstest_get_local_model_cost_map()How it works
model_prices_and_context_window.jsonfrom project rootlitellm/directorypip install litellmBenefits
Testing
LITELLM_LOCAL_MODEL_COST_MAP=True✓ Loaded successfully
Models count: 1743
Tests passing:
tests/local_testing/test_get_model_file.py::test_get_local_model_cost_map PASSED
tests/local_testing/test_get_model_file.py::test_get_model_cost_map PASSED
tests/test_litellm/test_cost_calculator.py::test_cost_calculator_with_usage PASSED