generated from coulomb/repo-seed
Implement-LLM-WP-0005-cost-model-estimators
This commit is contained in:
54
tests/test_cli.py
Normal file
54
tests/test_cli.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from llm_connect.cli import main
|
||||
from llm_connect.quality import QualityLedger, QualityObservation
|
||||
|
||||
|
||||
def test_rates_show_json_outputs_default_registry(capsys):
|
||||
assert main(["rates", "show", "--json"]) == 0
|
||||
|
||||
payload = json.loads(capsys.readouterr().out)
|
||||
|
||||
assert payload["openai/gpt-4o-mini"]["prompt_per_1k"] == 0.00015
|
||||
|
||||
|
||||
def test_classes_show_lists_builtins(capsys):
|
||||
assert main(["classes", "show"]) == 0
|
||||
|
||||
output = capsys.readouterr().out
|
||||
|
||||
assert "chunk-summarization" in output
|
||||
assert "entity-extraction" in output
|
||||
|
||||
|
||||
def test_classes_fit_reads_quality_ledger(tmp_path, capsys):
|
||||
ledger = QualityLedger(tmp_path / "quality.jsonl")
|
||||
for _ in range(3):
|
||||
ledger.append(
|
||||
QualityObservation(
|
||||
task_type="extract",
|
||||
adapter_id="openrouter",
|
||||
model_id="openai/gpt-4o-mini",
|
||||
cost_usd=0.001,
|
||||
quality_score=0.9,
|
||||
latency_ms=100,
|
||||
tokens_in=500,
|
||||
tokens_out=350,
|
||||
recorded_at=datetime(2026, 5, 19, tzinfo=timezone.utc),
|
||||
tags={
|
||||
"problem_class": "entity-extraction",
|
||||
"dimensions": {
|
||||
"chunk_words": 300,
|
||||
"template_words": 100,
|
||||
"expected_entities": 5,
|
||||
},
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
assert main(["classes", "fit", str(ledger.path), "--class", "entity-extraction", "--json"]) == 0
|
||||
|
||||
payload = json.loads(capsys.readouterr().out)
|
||||
|
||||
assert payload["entity-extraction"]["params"]["tokens_per_entity"] == 70
|
||||
Reference in New Issue
Block a user