"""Reproduce the article's illustrative aggregate worksheet; no API calls.""" import csv import json from decimal import Decimal as D from pathlib import Path rows = list(csv.DictReader(Path(__file__).with_name('cost-worksheet.csv').open())) results = [] for raw in rows: x = {k: D(v) for k, v in raw.items() if k != 'scenario'} assert all(v >= 0 for v in x.values()) assert x['requests'] > 0 and x['accepted_results'] > 0 assert x['reviewed_requests'] <= x['requests'] assert x['accepted_results'] <= x['requests'] per_call = (x['input_tokens_per_call'] * x['input_usd_per_million'] + x['output_tokens_per_call'] * x['output_usd_per_million']) / D(1000000) model = per_call * (x['requests'] + x['extra_calls']) review = x['reviewed_requests'] * x['review_seconds_each'] / D(3600) * x['review_usd_per_hour'] total = model + review + x['allocated_infra_usd'] results.append({'scenario': raw['scenario'], 'currency': 'USD', 'per_call': str(per_call), 'model_total': str(model), 'review_total': str(review), 'operating_total': str(total), 'per_request': str(total / x['requests']), 'per_accepted': str(total / x['accepted_results'])}) print(json.dumps({'scope': 'Illustrative arithmetic; equal tokens per call; not actual billing reconciliation.', 'results': results}, indent=2))