0
0
Prompt Engineering / GenAIml~10 mins

Rate limiting and abuse prevention in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a maximum number of requests per minute.

Prompt Engineering / GenAI
rate_limit = [1]  # max requests per minute
Drag options to blanks, or click blank then click option'
A100
B1000
C10
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing too high a number that defeats rate limiting purpose.
2fill in blank
medium

Complete the code to check if the user has exceeded the allowed requests.

Prompt Engineering / GenAI
if user_requests > [1]:
    block_user()
Drag options to blanks, or click blank then click option'
Arate_limit + 10
Brate_limit
Crate_limit / 2
Drate_limit * 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value higher than the limit, which delays blocking.
3fill in blank
hard

Fix the error in the code that resets the request count after one minute.

Prompt Engineering / GenAI
if time.time() - start_time >= [1]:
    user_requests = 0
    start_time = time.time()
Drag options to blanks, or click blank then click option'
A10
B30
C100
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 30 or 10 seconds which resets too frequently.
4fill in blank
hard

Fill both blanks to implement a simple token bucket rate limiter.

Prompt Engineering / GenAI
bucket_capacity = [1]
tokens = [2]
Drag options to blanks, or click blank then click option'
A100
B0
C50
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Setting tokens to zero initially which blocks all requests at start.
5fill in blank
hard

Fill all three blanks to update tokens and check if a request can proceed.

Prompt Engineering / GenAI
tokens = min([1] + refill_rate, [2])
if tokens >= [3]:
    tokens -= 1
    allow_request()
Drag options to blanks, or click blank then click option'
Atokens
Bbucket_capacity
C1
Drefill_rate
Attempts:
3 left
💡 Hint
Common Mistakes
Not capping tokens at bucket capacity or subtracting wrong token amount.