Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/opentelemetry-collector/builder/costs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def load_model_costs() -> list[ModelCost]:
cost = ModelCost.from_tokencost_json(model_name, model_data)
except pydantic.ValidationError:
print(f"Model {model_name} has invalid data. Skipping.")
continue
costs.append(cost)

print(f"Loaded {len(costs)} model costs from {json_path}")
Expand Down
31 changes: 30 additions & 1 deletion app/opentelemetry-collector/builder/tests/test_model_cost.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest
from decimal import Decimal
from pathlib import Path
Expand Down Expand Up @@ -174,6 +175,34 @@ def test_validator_methods(self):
dumped = model.model_dump()
assert dumped["input"] == "0.001"

def test_load_model_costs_skips_invalid_rows(self, tmp_path, monkeypatch):
"""Invalid rows are skipped without aborting or duplicating a prior row."""
model_prices = {
"invalid-first": {
"litellm_provider": "test",
"input_cost_per_token": 0,
"output_cost_per_token": 0.00003,
},
"valid-model": {
"litellm_provider": "test",
"input_cost_per_token": 0.00001,
"output_cost_per_token": 0.00003,
},
"invalid-after-valid": {
"litellm_provider": "test",
"input_cost_per_token": 0,
"output_cost_per_token": 0.00003,
},
}
(tmp_path / "model_prices.json").write_text(
json.dumps(model_prices), encoding="utf-8"
)
monkeypatch.setattr("builder.costs.get_tokencost_path", lambda: tmp_path)

costs = load_model_costs()

assert [cost.model for cost in costs] == ["valid-model"]

def test_get_tokencost_path_integration(self):
"""Integration test for get_tokencost_path with the real package."""
path = get_tokencost_path()
Expand Down Expand Up @@ -218,4 +247,4 @@ def test_load_model_costs_integration(self):

# At least one of these common models should be present
assert any(model in model_names for model in common_models), \
f"None of the common models {common_models} found in {model_names[:5]}..."
f"None of the common models {common_models} found in {model_names[:5]}..."