feat(llm): cost tracker with per-tier pricing and breakdown
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
from multi_swarm.genome.hypothesis import ModelTier
|
||||
from multi_swarm.llm.cost_tracker import CostTracker, estimate_cost
|
||||
|
||||
|
||||
def test_estimate_cost_tier_c():
|
||||
cost = estimate_cost(input_tokens=1_000_000, output_tokens=1_000_000, tier=ModelTier.C)
|
||||
assert cost == 0.40 + 0.40
|
||||
|
||||
|
||||
def test_estimate_cost_tier_b():
|
||||
cost = estimate_cost(input_tokens=1_000_000, output_tokens=1_000_000, tier=ModelTier.B)
|
||||
assert cost == 3.00 + 15.00
|
||||
|
||||
|
||||
def test_tracker_accumulates():
|
||||
t = CostTracker()
|
||||
t.record(input_tokens=10_000, output_tokens=20_000, tier=ModelTier.C, run_id="r", agent_id="a")
|
||||
t.record(input_tokens=5_000, output_tokens=15_000, tier=ModelTier.C, run_id="r", agent_id="b")
|
||||
summary = t.summary()
|
||||
assert summary["calls"] == 2
|
||||
assert summary["input_tokens"] == 15_000
|
||||
assert summary["output_tokens"] == 35_000
|
||||
assert summary["cost_usd"] > 0
|
||||
|
||||
|
||||
def test_tracker_per_tier_breakdown():
|
||||
t = CostTracker()
|
||||
t.record(input_tokens=10_000, output_tokens=10_000, tier=ModelTier.C, run_id="r", agent_id="a")
|
||||
t.record(input_tokens=10_000, output_tokens=10_000, tier=ModelTier.B, run_id="r", agent_id="b")
|
||||
summary = t.summary()
|
||||
assert "C" in summary["by_tier"]
|
||||
assert "B" in summary["by_tier"]
|
||||
Reference in New Issue
Block a user