Skip to content
DeepForgeby svx
All problems

In-Context RL Prompt Length

Problem

Compute how many tokens of an in-context RL prompt fit before hitting the context window.

The available budget is context_window - reserve, and the prompt wants n_transitions * tokens_per_transition tokens. Return the smaller of the two, floored at 0 when the budget is non-positive.

Hint

Longer demonstration prompts help until they crowd out room for the answer.

Test cases

case 1
in: [20,50,2048,128]
expected: 1000
case 2
in: [50,50,2048,128]
expected: 1920
case 3
in: [10,0,1024,24]
expected: 0
case 4
in: [100,10,32,32]
expected: 0
case 5
in: [2,3,10,4]
expected: 6
Starter codePython
def in_context_prompt_length(n_transitions, tokens_per_transition, context_window, reserve):
    # Your code here
    pass

5 test cases · run your code against them in the editor