Spaces:
Paused
Paused
Upload app.py
Browse files
app.py
CHANGED
@@ -107,7 +107,7 @@ def create_custom_session():
|
|
107 |
return session
|
108 |
|
109 |
# 添加速率限制相关的常量
|
110 |
-
AUTH_RETRY_DELAY = 60 #
|
111 |
AUTH_BACKOFF_FACTOR = 2 # 退避因子
|
112 |
AUTH_MAX_RETRIES = 3 # 最大重试次数
|
113 |
AUTH_CHECK_INTERVAL = 300 # 健康检查间隔(秒)
|
@@ -322,27 +322,39 @@ class MultiAuthManager:
|
|
322 |
if auth_manager.is_model_available(model) and auth_manager.ensure_valid_token():
|
323 |
logger.info(f"Using last successful account for model {model}: {auth_manager._email}")
|
324 |
return auth_manager
|
|
|
|
|
|
|
|
|
325 |
|
326 |
# 如果该模型没有成功记录或上次的账号不可用,从头开始尝试所有账号
|
327 |
tried_accounts = set()
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
while len(tried_accounts) < len(self.auth_managers):
|
332 |
auth_manager = self.auth_managers[current]
|
333 |
|
334 |
if auth_manager._email not in tried_accounts:
|
335 |
tried_accounts.add(auth_manager._email)
|
|
|
336 |
|
337 |
-
if auth_manager.is_model_available(model)
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
|
|
|
|
|
|
|
|
|
|
343 |
|
344 |
current = (current + 1) % len(self.auth_managers)
|
345 |
-
|
|
|
|
|
346 |
# 如果是新的一天,重置所有状态
|
347 |
if datetime.now().date() > self.last_success_date:
|
348 |
logger.info("New day started, resetting all model status")
|
@@ -353,7 +365,7 @@ class MultiAuthManager:
|
|
353 |
# 重新尝试第一个账号
|
354 |
auth_manager = self.auth_managers[0]
|
355 |
if auth_manager.ensure_valid_token():
|
356 |
-
self.current_index =
|
357 |
self.model_usage[model] = 0
|
358 |
logger.info(f"Using first account after reset: {auth_manager._email}")
|
359 |
return auth_manager
|
@@ -824,7 +836,7 @@ def make_request(payload, auth_manager, model_id):
|
|
824 |
else:
|
825 |
raise Exception("无法注册新账号")
|
826 |
|
827 |
-
#
|
828 |
tried_accounts = set()
|
829 |
|
830 |
while len(tried_accounts) < len(multi_auth_manager.auth_managers):
|
|
|
107 |
return session
|
108 |
|
109 |
# 添加速率限制相关的常量
|
110 |
+
AUTH_RETRY_DELAY = 60 # 认证���试延迟(秒)
|
111 |
AUTH_BACKOFF_FACTOR = 2 # 退避因子
|
112 |
AUTH_MAX_RETRIES = 3 # 最大重试次数
|
113 |
AUTH_CHECK_INTERVAL = 300 # 健康检查间隔(秒)
|
|
|
322 |
if auth_manager.is_model_available(model) and auth_manager.ensure_valid_token():
|
323 |
logger.info(f"Using last successful account for model {model}: {auth_manager._email}")
|
324 |
return auth_manager
|
325 |
+
else:
|
326 |
+
logger.info(f"Last successful account {auth_manager._email} is no longer available for model {model}")
|
327 |
+
# 从模型使用记录中移除不可用的账号
|
328 |
+
del self.model_usage[model]
|
329 |
|
330 |
# 如果该模型没有成功记录或上次的账号不可用,从头开始尝试所有账号
|
331 |
tried_accounts = set()
|
332 |
+
start_index = self.current_index
|
333 |
+
current = start_index
|
334 |
+
|
335 |
while len(tried_accounts) < len(self.auth_managers):
|
336 |
auth_manager = self.auth_managers[current]
|
337 |
|
338 |
if auth_manager._email not in tried_accounts:
|
339 |
tried_accounts.add(auth_manager._email)
|
340 |
+
logger.info(f"Trying account {auth_manager._email} for model {model}")
|
341 |
|
342 |
+
if auth_manager.is_model_available(model):
|
343 |
+
if auth_manager.ensure_valid_token():
|
344 |
+
# 更新该模型的成功账号记录
|
345 |
+
self.model_usage[model] = current
|
346 |
+
self.current_index = (current + 1) % len(self.auth_managers) # 更新当前索引为下一个
|
347 |
+
logger.info(f"Found available account for model {model}: {auth_manager._email}")
|
348 |
+
return auth_manager
|
349 |
+
else:
|
350 |
+
logger.info(f"Token validation failed for account {auth_manager._email}")
|
351 |
+
else:
|
352 |
+
logger.info(f"Model {model} not available for account {auth_manager._email}")
|
353 |
|
354 |
current = (current + 1) % len(self.auth_managers)
|
355 |
+
if current == start_index:
|
356 |
+
break
|
357 |
+
|
358 |
# 如果是新的一天,重置所有状态
|
359 |
if datetime.now().date() > self.last_success_date:
|
360 |
logger.info("New day started, resetting all model status")
|
|
|
365 |
# 重新尝试第一个账号
|
366 |
auth_manager = self.auth_managers[0]
|
367 |
if auth_manager.ensure_valid_token():
|
368 |
+
self.current_index = 1 # 设置为下一个账号
|
369 |
self.model_usage[model] = 0
|
370 |
logger.info(f"Using first account after reset: {auth_manager._email}")
|
371 |
return auth_manager
|
|
|
836 |
else:
|
837 |
raise Exception("无法注册新账号")
|
838 |
|
839 |
+
# 记录尝试的账号
|
840 |
tried_accounts = set()
|
841 |
|
842 |
while len(tried_accounts) < len(multi_auth_manager.auth_managers):
|