Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -668,12 +668,14 @@ def make_request(payload, auth_manager, model_id):
|
|
| 668 |
global multi_auth_manager
|
| 669 |
max_retries = 3
|
| 670 |
retry_delay = 1
|
|
|
|
| 671 |
|
| 672 |
for _ in range(len(multi_auth_manager.auth_managers)): # 尝试所有可用的账号
|
| 673 |
auth_manager = multi_auth_manager.get_next_auth_manager(model_id)
|
| 674 |
if not auth_manager:
|
| 675 |
logger.error(f"No available accounts for model {model_id}")
|
| 676 |
-
|
|
|
|
| 677 |
|
| 678 |
for attempt in range(max_retries):
|
| 679 |
try:
|
|
@@ -713,6 +715,26 @@ def make_request(payload, auth_manager, model_id):
|
|
| 713 |
# If we've exhausted all retries for this account, continue to the next account
|
| 714 |
continue
|
| 715 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
raise Exception("Failed to make request after trying all accounts")
|
| 717 |
|
| 718 |
def health_check():
|
|
@@ -745,3 +767,4 @@ if __name__ == "__main__":
|
|
| 745 |
|
| 746 |
port = int(os.environ.get("PORT", 3000))
|
| 747 |
app.run(debug=False, host='0.0.0.0', port=port, threaded=True)
|
|
|
|
|
|
| 668 |
global multi_auth_manager
|
| 669 |
max_retries = 3
|
| 670 |
retry_delay = 1
|
| 671 |
+
accounts_exhausted = False
|
| 672 |
|
| 673 |
for _ in range(len(multi_auth_manager.auth_managers)): # 尝试所有可用的账号
|
| 674 |
auth_manager = multi_auth_manager.get_next_auth_manager(model_id)
|
| 675 |
if not auth_manager:
|
| 676 |
logger.error(f"No available accounts for model {model_id}")
|
| 677 |
+
accounts_exhausted = True
|
| 678 |
+
break
|
| 679 |
|
| 680 |
for attempt in range(max_retries):
|
| 681 |
try:
|
|
|
|
| 715 |
# If we've exhausted all retries for this account, continue to the next account
|
| 716 |
continue
|
| 717 |
|
| 718 |
+
# 如果所有账号都被耗尽,尝试自动注册
|
| 719 |
+
if accounts_exhausted:
|
| 720 |
+
logger.info("尝试自动注册新账号")
|
| 721 |
+
try:
|
| 722 |
+
successful_accounts = register_bot.register_and_verify(5) # 注册5个账号
|
| 723 |
+
|
| 724 |
+
if successful_accounts:
|
| 725 |
+
# 重新初始化 multi_auth_manager
|
| 726 |
+
credentials = [(account['email'], account['password']) for account in successful_accounts]
|
| 727 |
+
multi_auth_manager = MultiAuthManager(credentials)
|
| 728 |
+
|
| 729 |
+
# 重新尝试请求
|
| 730 |
+
return make_request(payload, None, model_id)
|
| 731 |
+
else:
|
| 732 |
+
logger.error("无法自动注册新账号")
|
| 733 |
+
raise Exception("Failed to register new accounts")
|
| 734 |
+
except Exception as e:
|
| 735 |
+
logger.error(f"自动注册过程发生错误: {e}")
|
| 736 |
+
raise Exception("Failed to make request after trying all accounts")
|
| 737 |
+
|
| 738 |
raise Exception("Failed to make request after trying all accounts")
|
| 739 |
|
| 740 |
def health_check():
|
|
|
|
| 767 |
|
| 768 |
port = int(os.environ.get("PORT", 3000))
|
| 769 |
app.run(debug=False, host='0.0.0.0', port=port, threaded=True)
|
| 770 |
+
|