Update app.py
Browse files
app.py
CHANGED
|
@@ -51,16 +51,23 @@ def get_credit_summary(api_key):
|
|
| 51 |
"Authorization": f"Bearer {api_key}",
|
| 52 |
"Content-Type": "application/json"
|
| 53 |
}
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
FREE_MODEL_TEST_KEY = (
|
| 66 |
"sk-bmjbjzleaqfgtqfzmcnsbagxrlohriadnxqrzfocbizaxukw"
|
|
|
|
| 51 |
"Authorization": f"Bearer {api_key}",
|
| 52 |
"Content-Type": "application/json"
|
| 53 |
}
|
| 54 |
+
max_retries = 5
|
| 55 |
+
retry_delay = 5
|
| 56 |
+
for attempt in range(max_retries):
|
| 57 |
+
try:
|
| 58 |
+
response = requests.get(API_ENDPOINT, headers=headers, timeout=5)
|
| 59 |
+
response.raise_for_status()
|
| 60 |
+
data = response.json().get("data", {})
|
| 61 |
+
total_balance = data.get("totalBalance", 0)
|
| 62 |
+
logging.info(f"API Key:{api_key},当前额度: {total_balance}")
|
| 63 |
+
return {"total_balance": float(total_balance)}
|
| 64 |
+
except requests.exceptions.RequestException as e:
|
| 65 |
+
logging.error(f"获取额度信息失败,API Key:{api_key},尝试次数:{attempt+1}/{max_retries},错误信息:{e}")
|
| 66 |
+
if attempt < max_retries - 1:
|
| 67 |
+
time.sleep(retry_delay)
|
| 68 |
+
else:
|
| 69 |
+
logging.error(f"获取额度信息失败,API Key:{api_key},所有重试次数均已失败")
|
| 70 |
+
return None
|
| 71 |
|
| 72 |
FREE_MODEL_TEST_KEY = (
|
| 73 |
"sk-bmjbjzleaqfgtqfzmcnsbagxrlohriadnxqrzfocbizaxukw"
|