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
- Two calls cost 0.000296 dollars
- No calls cost nothing
- Output tokens use the output price
within_budgetcompares 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.