From a2776fe7cadfe18090199a7e239d9bd1284557a5 Mon Sep 17 00:00:00 2001 From: Chesars Date: Mon, 4 May 2026 21:58:43 -0300 Subject: [PATCH] fix(get_model_cost_map): give an actionable message when bundled JSON is missing Wrap the package-resource load so that a wheel built without the prerequisite cp step (e.g. a manual `uv build`) surfaces a message that names the missing file, points at the canonical build steps, and shows the one-liner fix. The original FileNotFoundError is preserved via `raise ... from e`. Addresses Greptile review P1. --- .../litellm_core_utils/get_model_cost_map.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/litellm/litellm_core_utils/get_model_cost_map.py b/litellm/litellm_core_utils/get_model_cost_map.py index 35c393c47d3..da60f73ad6e 100644 --- a/litellm/litellm_core_utils/get_model_cost_map.py +++ b/litellm/litellm_core_utils/get_model_cost_map.py @@ -51,11 +51,20 @@ class GetModelCostMap: verbose_logger.debug( "LiteLLM: loading local model cost map from bundled package resource" ) - return json.loads( - files("litellm") - .joinpath("model_prices_and_context_window_backup.json") - .read_text(encoding="utf-8") - ) + try: + return json.loads( + files("litellm") + .joinpath("model_prices_and_context_window_backup.json") + .read_text(encoding="utf-8") + ) + except FileNotFoundError as e: + raise FileNotFoundError( + "litellm/model_prices_and_context_window_backup.json is missing from the installed package. " + "This file is a build-time artefact — the `cp` step in .github/workflows/publish_to_pypi.yml " + "and the source-build Dockerfiles materialize it before the wheel is built. If you ran " + "`uv build` manually, first run: " + "cp model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json" + ) from e @classmethod def _get_backup_model_count(cls) -> int: