fix(model_cost_map): fix json parse error on model cost map + add unit test (#8629)

Fixes https://github.com/BerriAI/litellm/pull/8619#issuecomment-2666693045
This commit is contained in:
Krish Dholakia 2025-02-18 11:18:16 -08:00 committed by GitHub
parent 49610485a2
commit ea985dda0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View file

@ -2961,3 +2961,18 @@ async def test_cost_calculator_with_custom_pricing_router(model_item, custom_pri
)
# assert resp.model == "random-model"
assert resp._hidden_params["response_cost"] > 0
def test_json_valid_model_cost_map():
import json
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
model_cost = litellm.get_model_cost_map(url="")
try:
# Attempt to serialize and deserialize the JSON
json_str = json.dumps(model_cost)
json.loads(json_str)
except json.JSONDecodeError as e:
assert False, f"Invalid JSON format: {str(e)}"