Command Palette

Search for a command to run...

Hectal
Phase 0: Start Here: What an LLM Is and Why Engineering Matters
LLM Engineering · Exercise 5 of 5 Previous
Beginner

Estimate the cost of a day's calls

Write cost_dollars(usages, price_in, price_out). usages is a list of {"input": n, "output": n} token counts; the prices are dollars per million tokens. Return the total cost rounded to 6 decimals.

Write within_budget(usages, price_in, price_out, budget) that returns True when the cost is at most the budget.

What Check tests

  1. Two calls cost 0.000296 dollars
  2. No calls cost nothing
  3. Output tokens use the output price
  4. within_budget compares with the budget

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.