"""Original hypothetical accounting. No network, API, model, or live billing.""" from decimal import Decimal as D import json P = {'input': D('1'), 'write': D('1.25'), 'read': D('0.10'), 'output': D('5')} def cost(u=0, w=0, r=0, o=0): return sum(D(t) * P[k] for t, k in zip((u,w,r,o), P)) / D(1000000) def main(): a, b = cost(w=100000,r=900000), cost(w=60000,r=2940000) uncached = 10 * cost(u=22000,o=1000) reused = cost(w=20000) + 9 * cost(r=20000) + 10 * cost(u=2000,o=1000) expired = 10 * cost(w=20000,u=2000,o=1000) one_cached, one_plain = cost(w=20000,u=2000,o=1000), cost(u=22000,o=1000) threshold = (P['write']-P['read'])/(P['input']-P['read']) total_context = sum(20000+2000*i for i in range(10)) assert (a,b)==(D('.215'),D('.369')) and b>a assert (uncached,reused,expired)==(D('.270'),D('.113'),D('.320')) assert (one_cached,one_plain)==(D('.032'),D('.027')) assert 1 < threshold < 2 and total_context==290000 assert 2*cost(u=22000,o=1000)>cost(w=20000)+cost(r=20000)+2*cost(u=2000,o=1000) print(json.dumps({'kind':'hypothetical arithmetic, not product measurement','prices_per_million':{k:str(v) for k,v in P.items()},'input_cost_A':str(a),'input_cost_B':str(b),'ten_uncached':str(uncached),'ten_reused':str(reused),'ten_expired':str(expired),'one_cached':str(one_cached),'one_plain':str(one_plain),'reuse_threshold':str(threshold),'total_context':total_context,'checks':'passed'},indent=2)) if __name__ == '__main__': main()