Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,6 @@ from urllib3.util.connection import create_connection
|
|
| 18 |
import urllib3
|
| 19 |
from cachetools import TTLCache
|
| 20 |
import threading
|
| 21 |
-
from datetime import datetime
|
| 22 |
|
| 23 |
# 新增导入
|
| 24 |
import register_bot
|
|
@@ -56,7 +55,7 @@ if not NOTDIAMOND_IP:
|
|
| 56 |
logger.error("NOTDIAMOND_IP environment variable is not set!")
|
| 57 |
raise ValueError("NOTDIAMOND_IP must be set")
|
| 58 |
|
| 59 |
-
# API
|
| 60 |
def require_api_key(f):
|
| 61 |
@wraps(f)
|
| 62 |
def decorated_function(*args, **kwargs):
|
|
@@ -522,51 +521,10 @@ def before_request():
|
|
| 522 |
else:
|
| 523 |
multi_auth_manager = None
|
| 524 |
|
| 525 |
-
def get_accounts_status():
|
| 526 |
-
"""获取所有账号的状态信息"""
|
| 527 |
-
if not multi_auth_manager:
|
| 528 |
-
return []
|
| 529 |
-
|
| 530 |
-
accounts_status = []
|
| 531 |
-
for auth_manager in multi_auth_manager.auth_managers:
|
| 532 |
-
account_info = {
|
| 533 |
-
"email": auth_manager._email,
|
| 534 |
-
"is_valid": auth_manager.is_token_valid(),
|
| 535 |
-
"token_expiry": datetime.fromtimestamp(auth_manager._token_expiry).strftime('%Y-%m-%d %H:%M:%S'),
|
| 536 |
-
"models_status": {
|
| 537 |
-
model: status
|
| 538 |
-
for model, status in auth_manager.model_status.items()
|
| 539 |
-
}
|
| 540 |
-
}
|
| 541 |
-
accounts_status.append(account_info)
|
| 542 |
-
return accounts_status
|
| 543 |
-
|
| 544 |
@app.route('/', methods=['GET'])
|
| 545 |
def root():
|
| 546 |
-
accounts_status = get_accounts_status()
|
| 547 |
-
|
| 548 |
-
# 计算可用和不可用账号数量
|
| 549 |
-
total_accounts = len(accounts_status)
|
| 550 |
-
valid_accounts = sum(1 for acc in accounts_status if acc["is_valid"])
|
| 551 |
-
|
| 552 |
-
# 计算每个模型的可用账号数量
|
| 553 |
-
models_availability = {}
|
| 554 |
-
for model in MODEL_INFO.keys():
|
| 555 |
-
available_accounts = sum(
|
| 556 |
-
1 for acc in accounts_status
|
| 557 |
-
if acc["is_valid"] and acc["models_status"].get(model, False)
|
| 558 |
-
)
|
| 559 |
-
models_availability[model] = available_accounts
|
| 560 |
-
|
| 561 |
return jsonify({
|
| 562 |
"service": "AI Chat Completion Proxy",
|
| 563 |
-
"status": {
|
| 564 |
-
"total_accounts": total_accounts,
|
| 565 |
-
"valid_accounts": valid_accounts,
|
| 566 |
-
"invalid_accounts": total_accounts - valid_accounts,
|
| 567 |
-
"accounts_details": accounts_status,
|
| 568 |
-
"models_availability": models_availability
|
| 569 |
-
},
|
| 570 |
"usage": {
|
| 571 |
"endpoint": "/ai/v1/chat/completions",
|
| 572 |
"method": "POST",
|
|
@@ -824,5 +782,4 @@ if __name__ == "__main__":
|
|
| 824 |
health_check_thread.start()
|
| 825 |
|
| 826 |
port = int(os.environ.get("PORT", 3000))
|
| 827 |
-
app.run(debug=False, host='0.0.0.0', port=port, threaded=True)
|
| 828 |
-
|
|
|
|
| 18 |
import urllib3
|
| 19 |
from cachetools import TTLCache
|
| 20 |
import threading
|
|
|
|
| 21 |
|
| 22 |
# 新增导入
|
| 23 |
import register_bot
|
|
|
|
| 55 |
logger.error("NOTDIAMOND_IP environment variable is not set!")
|
| 56 |
raise ValueError("NOTDIAMOND_IP must be set")
|
| 57 |
|
| 58 |
+
# API密钥验证装饰器
|
| 59 |
def require_api_key(f):
|
| 60 |
@wraps(f)
|
| 61 |
def decorated_function(*args, **kwargs):
|
|
|
|
| 521 |
else:
|
| 522 |
multi_auth_manager = None
|
| 523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
@app.route('/', methods=['GET'])
|
| 525 |
def root():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
return jsonify({
|
| 527 |
"service": "AI Chat Completion Proxy",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
"usage": {
|
| 529 |
"endpoint": "/ai/v1/chat/completions",
|
| 530 |
"method": "POST",
|
|
|
|
| 782 |
health_check_thread.start()
|
| 783 |
|
| 784 |
port = int(os.environ.get("PORT", 3000))
|
| 785 |
+
app.run(debug=False, host='0.0.0.0', port=port, threaded=True)
|
|
|