Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,15 +23,16 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 23 |
|
| 24 |
# Rate limiting configuration
|
| 25 |
MAX_MODEL_CALLS_PER_MINUTE = 12 # Conservative buffer below 15 RPM
|
| 26 |
-
TOKEN_BUCKET_CAPACITY = RATE_LIMIT
|
| 27 |
RATE_LIMIT = MAX_MODEL_CALLS_PER_MINUTE
|
|
|
|
| 28 |
TOKEN_BUCKET_REFILL_RATE = RATE_LIMIT / 60.0 # Tokens per second
|
| 29 |
|
| 30 |
# Initialize global token bucket with MemoryStorage
|
| 31 |
storage = MemoryStorage()
|
| 32 |
token_bucket = Limiter(rate=TOKEN_BUCKET_REFILL_RATE, capacity=TOKEN_BUCKET_CAPACITY, storage=storage)
|
| 33 |
|
| 34 |
-
async def fetch_questions(session: aiohttp
|
|
|
|
| 35 |
"""Fetch questions asynchronously."""
|
| 36 |
try:
|
| 37 |
async with session.get(questions_url, timeout=15) as response:
|
|
|
|
| 23 |
|
| 24 |
# Rate limiting configuration
|
| 25 |
MAX_MODEL_CALLS_PER_MINUTE = 12 # Conservative buffer below 15 RPM
|
|
|
|
| 26 |
RATE_LIMIT = MAX_MODEL_CALLS_PER_MINUTE
|
| 27 |
+
TOKEN_BUCKET_CAPACITY = RATE_LIMIT
|
| 28 |
TOKEN_BUCKET_REFILL_RATE = RATE_LIMIT / 60.0 # Tokens per second
|
| 29 |
|
| 30 |
# Initialize global token bucket with MemoryStorage
|
| 31 |
storage = MemoryStorage()
|
| 32 |
token_bucket = Limiter(rate=TOKEN_BUCKET_REFILL_RATE, capacity=TOKEN_BUCKET_CAPACITY, storage=storage)
|
| 33 |
|
| 34 |
+
async def fetch_questions(session: aiohttp
|
| 35 |
+
.ClientSession, questions_url: str) -> list:
|
| 36 |
"""Fetch questions asynchronously."""
|
| 37 |
try:
|
| 38 |
async with session.get(questions_url, timeout=15) as response:
|