mirror of
https://github.com/tiennm99/litellm.git
synced 2026-06-18 00:48:01 +00:00
6e8e3b30f9
* update databricks pricing and add DBU<>USD test * Refactor test_databricks_pricing.py Removed unnecessary sys.path modification and cleaned up comments.
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
|
|
|
|
def test_databricks_pricing_integrity():
|
|
"""
|
|
Verifies that for all Databricks models in model_prices_and_context_window.json:
|
|
USD Price == DBU Price * 0.07
|
|
"""
|
|
json_path = os.path.join(
|
|
os.path.dirname(__file__), "../../../../model_prices_and_context_window.json"
|
|
)
|
|
|
|
# Verify file exists
|
|
assert os.path.exists(
|
|
json_path
|
|
), f"Could not find model_prices_and_context_window.json at {json_path}"
|
|
|
|
with open(json_path, "r") as f:
|
|
data = json.load(f)
|
|
|
|
conversion_rate = 0.07 # 1 DBU = 0.07 USD
|
|
errors = []
|
|
|
|
for model, info in data.items():
|
|
if info.get("litellm_provider") == "databricks":
|
|
# Check Input Cost
|
|
input_usd = info.get("input_cost_per_token")
|
|
input_dbu = info.get("input_dbu_cost_per_token")
|
|
|
|
if input_usd is not None and input_dbu is not None:
|
|
expected = input_dbu * conversion_rate
|
|
# Allow small floating point difference
|
|
if abs(input_usd - expected) > 1e-9:
|
|
errors.append(
|
|
f"{model} input mismatch: USD={input_usd}, DBU={input_dbu}, Expected={expected}"
|
|
)
|
|
|
|
# Check Output Cost
|
|
output_usd = info.get("output_cost_per_token")
|
|
output_dbu = info.get("output_dbu_cost_per_token")
|
|
|
|
if output_usd is not None and output_dbu is not None:
|
|
expected = output_dbu * conversion_rate
|
|
if abs(output_usd - expected) > 1e-9:
|
|
errors.append(
|
|
f"{model} output mismatch: USD={output_usd}, DBU={output_dbu}, Expected={expected}"
|
|
)
|
|
|
|
assert not errors, "\n" + "\n".join(errors)
|