Spaces:
Sleeping
Sleeping
translate Japanese comments into English
Browse files- rate_limiter.py +5 -3
rate_limiter.py
CHANGED
|
@@ -3,7 +3,8 @@ from smolagents import CodeAgent, ActionStep
|
|
| 3 |
|
| 4 |
class RateLimiter:
|
| 5 |
"""
|
| 6 |
-
API
|
|
|
|
| 7 |
"""
|
| 8 |
def __init__(self, calls_per_wait: int = 10, seconds_to_wait: int = 60):
|
| 9 |
self.calls_per_wait = calls_per_wait
|
|
@@ -12,11 +13,12 @@ class RateLimiter:
|
|
| 12 |
|
| 13 |
def increment_and_sleep_if_needed(self, memory_step: ActionStep, agent: CodeAgent):
|
| 14 |
"""
|
| 15 |
-
|
|
|
|
| 16 |
"""
|
| 17 |
self._call_count += 1
|
| 18 |
|
| 19 |
if self._call_count >= self.calls_per_wait:
|
| 20 |
-
print(f"
|
| 21 |
time.sleep(self.seconds_to_wait)
|
| 22 |
self._call_count = 0
|
|
|
|
| 3 |
|
| 4 |
class RateLimiter:
|
| 5 |
"""
|
| 6 |
+
responsible for counting the number of API calls
|
| 7 |
+
and waiting for a certain number of seconds when a certain number of calls have been made.
|
| 8 |
"""
|
| 9 |
def __init__(self, calls_per_wait: int = 10, seconds_to_wait: int = 60):
|
| 10 |
self.calls_per_wait = calls_per_wait
|
|
|
|
| 13 |
|
| 14 |
def increment_and_sleep_if_needed(self, memory_step: ActionStep, agent: CodeAgent):
|
| 15 |
"""
|
| 16 |
+
Increment the number of calls, and wait for a certain number of seconds
|
| 17 |
+
after a certain number of calls have been made.
|
| 18 |
"""
|
| 19 |
self._call_count += 1
|
| 20 |
|
| 21 |
if self._call_count >= self.calls_per_wait:
|
| 22 |
+
print(f"Since the number of calls exceeded {self.calls_per_wait} times, wait for {self.seconds_to_wait} seconds")
|
| 23 |
time.sleep(self.seconds_to_wait)
|
| 24 |
self._call_count = 0
|