All problems
Prompt Token Budget
Problem
Return the number of tokens left for retrieved context after reserving space for the system prompt, few-shot examples, the question, and the generated output.
Return max(0, context_limit - system_tokens - few_shot_tokens - question_tokens - output_reserve).
Hint
Clamp the subtraction at zero so oversized fixed parts report no remaining budget.
Test cases
case 1
in: [4096,200,300,50,500]
expected: 3046
case 2
in: [100,50,60,10,5]
expected: 0
case 3
in: [0,0,0,0,0]
expected: 0
case 4
in: [2048,100,0,20,1024]
expected: 904
Starter codePython
def prompt_token_budget(context_limit, system_tokens, few_shot_tokens, question_tokens, output_reserve):
# Your code here
pass4 test cases · run your code against them in the editor