Spaces:
Paused
Paused
Upload 4 files
Browse files
app.py
CHANGED
|
@@ -176,9 +176,9 @@ def handle_api_error(error, attempt, stream=False):
|
|
| 176 |
elif isinstance(error, (ResourceExhausted, Aborted, InternalServerError, ServiceUnavailable)):
|
| 177 |
delay = min(RETRY_DELAY * (2 ** attempt), MAX_RETRY_DELAY)
|
| 178 |
if isinstance(error, ResourceExhausted):
|
| 179 |
-
|
| 180 |
else:
|
| 181 |
-
|
| 182 |
time.sleep(delay)
|
| 183 |
if isinstance(error, (ResourceExhausted)):
|
| 184 |
key_manager.blacklist_key(current_api_key)
|
|
@@ -218,7 +218,7 @@ def chat_completions():
|
|
| 218 |
def do_request(current_api_key, attempt):
|
| 219 |
isok, time = is_within_rate_limit(current_api_key)
|
| 220 |
if not isok:
|
| 221 |
-
logger.warning(f"{current_api_key[:11]} →
|
| 222 |
switch_api_key()
|
| 223 |
return False, None
|
| 224 |
|
|
|
|
| 176 |
elif isinstance(error, (ResourceExhausted, Aborted, InternalServerError, ServiceUnavailable)):
|
| 177 |
delay = min(RETRY_DELAY * (2 ** attempt), MAX_RETRY_DELAY)
|
| 178 |
if isinstance(error, ResourceExhausted):
|
| 179 |
+
logger.warning(f"{current_api_key[:11]} → 429 官方资源耗尽;{delay} 秒后重试...")
|
| 180 |
else:
|
| 181 |
+
logger.warning(f"{current_api_key[:11]} → 未知错误↙ \n{type(error).__name__}\n{delay} 秒后重试...")
|
| 182 |
time.sleep(delay)
|
| 183 |
if isinstance(error, (ResourceExhausted)):
|
| 184 |
key_manager.blacklist_key(current_api_key)
|
|
|
|
| 218 |
def do_request(current_api_key, attempt):
|
| 219 |
isok, time = is_within_rate_limit(current_api_key)
|
| 220 |
if not isok:
|
| 221 |
+
logger.warning(f"{current_api_key[:11]} → 暂时超过限额,该API key将在 {time} 秒后被移出黑名单...")
|
| 222 |
switch_api_key()
|
| 223 |
return False, None
|
| 224 |
|