Spaces:
Paused
Paused
Upload 4 files
Browse files
app.py
CHANGED
|
@@ -54,7 +54,7 @@ class APIKeyManager:
|
|
| 54 |
if current_key not in api_key_blacklist:
|
| 55 |
return current_key
|
| 56 |
|
| 57 |
-
logger.error("所有API key
|
| 58 |
return None
|
| 59 |
|
| 60 |
def show_all_keys(self):
|
|
@@ -63,7 +63,7 @@ class APIKeyManager:
|
|
| 63 |
logger.info(f"API Key{i}: {api_key[:11]}...")
|
| 64 |
|
| 65 |
def blacklist_key(self, key):
|
| 66 |
-
logger.warning(f"{key[:11]} →
|
| 67 |
api_key_blacklist.add(key)
|
| 68 |
|
| 69 |
scheduler.add_job(lambda: api_key_blacklist.discard(key), 'date', run_date=datetime.now() + timedelta(seconds=api_key_blacklist_duration))
|
|
@@ -79,7 +79,7 @@ def switch_api_key():
|
|
| 79 |
current_api_key = key
|
| 80 |
logger.info(f"API key 替换为 → {current_api_key[:11]}...")
|
| 81 |
else:
|
| 82 |
-
logger.error("API key 替换失败,所有API key
|
| 83 |
|
| 84 |
logger.info(f"当前 API key: {current_api_key[:11]}...")
|
| 85 |
|
|
@@ -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]} → 暂时超过限额,该API key将在 {time}
|
| 222 |
switch_api_key()
|
| 223 |
return False, None
|
| 224 |
|
|
|
|
| 54 |
if current_key not in api_key_blacklist:
|
| 55 |
return current_key
|
| 56 |
|
| 57 |
+
logger.error("所有API key都已耗尽或被暂时禁用,请重新配置或稍后重试")
|
| 58 |
return None
|
| 59 |
|
| 60 |
def show_all_keys(self):
|
|
|
|
| 63 |
logger.info(f"API Key{i}: {api_key[:11]}...")
|
| 64 |
|
| 65 |
def blacklist_key(self, key):
|
| 66 |
+
logger.warning(f"{key[:11]} → 暂时禁用 {api_key_blacklist_duration} 秒")
|
| 67 |
api_key_blacklist.add(key)
|
| 68 |
|
| 69 |
scheduler.add_job(lambda: api_key_blacklist.discard(key), 'date', run_date=datetime.now() + timedelta(seconds=api_key_blacklist_duration))
|
|
|
|
| 79 |
current_api_key = key
|
| 80 |
logger.info(f"API key 替换为 → {current_api_key[:11]}...")
|
| 81 |
else:
|
| 82 |
+
logger.error("API key 替换失败,所有API key都已耗尽或被暂时禁用,请重新配置或稍后重试")
|
| 83 |
|
| 84 |
logger.info(f"当前 API key: {current_api_key[:11]}...")
|
| 85 |
|
|
|
|
| 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 |
|