Update app.py
Browse files
app.py
CHANGED
|
@@ -479,30 +479,6 @@ def list_models():
|
|
| 479 |
"data": detailed_models
|
| 480 |
})
|
| 481 |
|
| 482 |
-
def get_billing_info():
|
| 483 |
-
keys = valid_keys_global + unverified_keys_global
|
| 484 |
-
total_balance = 0
|
| 485 |
-
|
| 486 |
-
with concurrent.futures.ThreadPoolExecutor(
|
| 487 |
-
max_workers=10000
|
| 488 |
-
) as executor:
|
| 489 |
-
futures = [
|
| 490 |
-
executor.submit(get_credit_summary, key) for key in keys
|
| 491 |
-
]
|
| 492 |
-
|
| 493 |
-
for future in concurrent.futures.as_completed(futures):
|
| 494 |
-
try:
|
| 495 |
-
credit_summary = future.result()
|
| 496 |
-
if credit_summary:
|
| 497 |
-
total_balance += credit_summary.get(
|
| 498 |
-
"total_balance",
|
| 499 |
-
0
|
| 500 |
-
)
|
| 501 |
-
except Exception as exc:
|
| 502 |
-
logging.error(f"获取额度信息生成异常: {exc}")
|
| 503 |
-
|
| 504 |
-
return total_balance
|
| 505 |
-
|
| 506 |
@app.route('/handsome/v1/dashboard/billing/usage', methods=['GET'])
|
| 507 |
def billing_usage():
|
| 508 |
if not check_authorization(request):
|
|
@@ -521,7 +497,23 @@ def billing_subscription():
|
|
| 521 |
if not check_authorization(request):
|
| 522 |
return jsonify({"error": "Unauthorized"}), 401
|
| 523 |
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
return jsonify({
|
| 527 |
"object": "billing_subscription",
|
|
@@ -552,15 +544,7 @@ def handsome_embeddings():
|
|
| 552 |
api_key = select_key(request_type, model_name)
|
| 553 |
|
| 554 |
if not api_key:
|
| 555 |
-
return jsonify(
|
| 556 |
-
{
|
| 557 |
-
"error": (
|
| 558 |
-
"No available API key for this "
|
| 559 |
-
"request type or all keys have "
|
| 560 |
-
"reached their limits"
|
| 561 |
-
)
|
| 562 |
-
}
|
| 563 |
-
), 429
|
| 564 |
|
| 565 |
headers = {
|
| 566 |
"Authorization": f"Bearer {api_key}",
|
|
|
|
| 479 |
"data": detailed_models
|
| 480 |
})
|
| 481 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
@app.route('/handsome/v1/dashboard/billing/usage', methods=['GET'])
|
| 483 |
def billing_usage():
|
| 484 |
if not check_authorization(request):
|
|
|
|
| 497 |
if not check_authorization(request):
|
| 498 |
return jsonify({"error": "Unauthorized"}), 401
|
| 499 |
|
| 500 |
+
keys = valid_keys_global + unverified_keys_global
|
| 501 |
+
total_balance = 0
|
| 502 |
+
|
| 503 |
+
with concurrent.futures.ThreadPoolExecutor(
|
| 504 |
+
max_workers=10000
|
| 505 |
+
) as executor:
|
| 506 |
+
futures = [
|
| 507 |
+
executor.submit(get_credit_summary, key) for key in keys
|
| 508 |
+
]
|
| 509 |
+
|
| 510 |
+
for future in concurrent.futures.as_completed(futures):
|
| 511 |
+
try:
|
| 512 |
+
credit_summary = future.result()
|
| 513 |
+
if credit_summary:
|
| 514 |
+
total_balance += credit_summary.get("total_balance", 0)
|
| 515 |
+
except Exception as exc:
|
| 516 |
+
logging.error(f"获取额度信息生成异常: {exc}")
|
| 517 |
|
| 518 |
return jsonify({
|
| 519 |
"object": "billing_subscription",
|
|
|
|
| 544 |
api_key = select_key(request_type, model_name)
|
| 545 |
|
| 546 |
if not api_key:
|
| 547 |
+
return jsonify({"error": ("No available API key for this request type or all keys have reached their limits")}), 429
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
|
| 549 |
headers = {
|
| 550 |
"Authorization": f"Bearer {api_key}",
|