Your question is LLM API Rate Limiting. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Implement a rate limiter for the Axis Max Life Insurance policy-assistance LLM endpoint. Each user may make at most limit accepted requests during any rolling interval of window seconds.
Process requests in the order received. For each request, remove that user's accepted request timestamps that are outside the current window. Accept the request if fewer than limit accepted requests remain, otherwise reject it. Rejected requests do not consume quota.
Implement rate_limit(requests, limit, window).
requests is a list of two-element lists, [user_id, timestamp], ordered by nondecreasing timestamp.user_id is a string.timestamp, limit, and window are positive integers.True means accepted and False means rejected.t considers timestamps in the half-open interval [t - window, t) expired. A request at exactly t - window is therefore expired.def rate_limit(requests, limit, window):