Skip to content

fix: assume ratelimit is not in effect if reset after is small amount #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions interactions/api/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def ingest_ratelimit_header(self, header: CIMultiDictProxy) -> None:
self.remaining = int(header.get("x-ratelimit-remaining", self.DEFAULT_REMAINING))
self.delta = float(header.get("x-ratelimit-reset-after", self.DEFAULT_DELTA))

if self.delta < 0.005 and self.remaining == 0: # the delta value is so small that we can assume it's 0
self.delta = self.DEFAULT_DELTA
self.remaining = self.DEFAULT_REMAINING # we can assume that we can make another request right away

if self._semaphore is None or self._semaphore._value != self.limit:
self._semaphore = asyncio.Semaphore(self.limit)

Expand Down