Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ text_models = []
|
|
24 |
invalid_keys_global = []
|
25 |
valid_keys_global = []
|
26 |
|
27 |
-
executor = concurrent.futures.ThreadPoolExecutor(max_workers=
|
28 |
model_key_indices = {}
|
29 |
|
30 |
request_timestamps = []
|
@@ -60,21 +60,21 @@ def get_credit_summary(api_key):
|
|
60 |
exchange_rate = get_usd_to_cny_rate()
|
61 |
if exchange_rate is not None:
|
62 |
total_balance_cny += usd_balance * exchange_rate
|
63 |
-
logging.info(f"
|
64 |
else:
|
65 |
-
|
66 |
-
|
67 |
except Exception as e:
|
68 |
-
|
69 |
-
|
70 |
|
71 |
return {"total_balance": float(total_balance_cny)}
|
72 |
except requests.exceptions.RequestException as e:
|
73 |
logging.error(f"获取额度信息失败,API Key:{api_key},错误信息:{e}")
|
74 |
return None
|
75 |
except Exception as e:
|
76 |
-
|
77 |
-
|
78 |
|
79 |
def get_usd_to_cny_rate():
|
80 |
try:
|
@@ -100,7 +100,7 @@ def load_keys():
|
|
100 |
logging.info(f"加载的 keys:{unique_keys}")
|
101 |
|
102 |
with concurrent.futures.ThreadPoolExecutor(
|
103 |
-
max_workers=
|
104 |
) as executor:
|
105 |
future_to_key = {
|
106 |
executor.submit(
|
@@ -191,54 +191,6 @@ def index():
|
|
191 |
tpm = sum(token_counts)
|
192 |
|
193 |
return jsonify({"rpm": rpm, "tpm": tpm})
|
194 |
-
|
195 |
-
@app.route('/check_tokens', methods=['POST'])
|
196 |
-
def check_tokens():
|
197 |
-
tokens = request.json.get('tokens', [])
|
198 |
-
|
199 |
-
with concurrent.futures.ThreadPoolExecutor(
|
200 |
-
max_workers=1000
|
201 |
-
) as executor:
|
202 |
-
future_to_token = {
|
203 |
-
executor.submit(
|
204 |
-
process_key, token
|
205 |
-
): token for token in tokens
|
206 |
-
}
|
207 |
-
|
208 |
-
results = []
|
209 |
-
for future in concurrent.futures.as_completed(future_to_token):
|
210 |
-
token = future_to_token[future]
|
211 |
-
try:
|
212 |
-
key_type = future.result()
|
213 |
-
credit_summary = get_credit_summary(token)
|
214 |
-
balance = (
|
215 |
-
credit_summary.get("total_balance", 0)
|
216 |
-
if credit_summary else 0
|
217 |
-
)
|
218 |
-
if key_type == "invalid":
|
219 |
-
results.append(
|
220 |
-
{
|
221 |
-
"token": token,
|
222 |
-
"type": "无效 KEY",
|
223 |
-
"balance": balance,
|
224 |
-
"message": "无法获取额度信息"
|
225 |
-
}
|
226 |
-
)
|
227 |
-
elif key_type == "valid":
|
228 |
-
results.append(
|
229 |
-
{
|
230 |
-
"token": token,
|
231 |
-
"type": "有效 KEY",
|
232 |
-
"balance": balance,
|
233 |
-
"message": "可以使用指定模型"
|
234 |
-
}
|
235 |
-
)
|
236 |
-
except Exception as exc:
|
237 |
-
logging.error(
|
238 |
-
f"处理 Token {token} 生成异常: {exc}"
|
239 |
-
)
|
240 |
-
|
241 |
-
return jsonify(results)
|
242 |
|
243 |
@app.route('/handsome/v1/models', methods=['GET'])
|
244 |
def list_models():
|
@@ -251,22 +203,6 @@ def list_models():
|
|
251 |
"object": "model",
|
252 |
"created": 1678888888,
|
253 |
"owned_by": "openai",
|
254 |
-
"permission": [
|
255 |
-
{
|
256 |
-
"id": f"modelperm-{uuid.uuid4().hex}",
|
257 |
-
"object": "model_permission",
|
258 |
-
"created": 1678888888,
|
259 |
-
"allow_create_engine": False,
|
260 |
-
"allow_sampling": True,
|
261 |
-
"allow_logprobs": True,
|
262 |
-
"allow_search_indices": False,
|
263 |
-
"allow_view": True,
|
264 |
-
"allow_fine_tuning": False,
|
265 |
-
"organization": "*",
|
266 |
-
"group": None,
|
267 |
-
"is_blocking": False
|
268 |
-
}
|
269 |
-
],
|
270 |
"root": "deepseek-chat",
|
271 |
"parent": None
|
272 |
},
|
@@ -275,22 +211,6 @@ def list_models():
|
|
275 |
"object": "model",
|
276 |
"created": 1678888889,
|
277 |
"owned_by": "openai",
|
278 |
-
"permission": [
|
279 |
-
{
|
280 |
-
"id": f"modelperm-{uuid.uuid4().hex}",
|
281 |
-
"object": "model_permission",
|
282 |
-
"created": 1678888889,
|
283 |
-
"allow_create_engine": False,
|
284 |
-
"allow_sampling": True,
|
285 |
-
"allow_logprobs": True,
|
286 |
-
"allow_search_indices": False,
|
287 |
-
"allow_view": True,
|
288 |
-
"allow_fine_tuning": False,
|
289 |
-
"organization": "*",
|
290 |
-
"group": None,
|
291 |
-
"is_blocking": False
|
292 |
-
}
|
293 |
-
],
|
294 |
"root": "deepseek-reasoner",
|
295 |
"parent": None
|
296 |
}
|
|
|
24 |
invalid_keys_global = []
|
25 |
valid_keys_global = []
|
26 |
|
27 |
+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=10000)
|
28 |
model_key_indices = {}
|
29 |
|
30 |
request_timestamps = []
|
|
|
60 |
exchange_rate = get_usd_to_cny_rate()
|
61 |
if exchange_rate is not None:
|
62 |
total_balance_cny += usd_balance * exchange_rate
|
63 |
+
logging.info(f"获取美元兑人民币汇率成功,API Key:{api_key},当前总额度(CNY): {total_balance_cny}")
|
64 |
else:
|
65 |
+
logging.warning(f"获取美元兑人民币汇率失败,无法转换美元余额,API Key:{api_key}")
|
66 |
+
total_balance_cny += usd_balance * 7.2
|
67 |
except Exception as e:
|
68 |
+
logging.error(f"获取美元兑人民币汇率失败,API Key:{api_key},错误信息:{e}")
|
69 |
+
total_balance_cny += usd_balance * 7.2
|
70 |
|
71 |
return {"total_balance": float(total_balance_cny)}
|
72 |
except requests.exceptions.RequestException as e:
|
73 |
logging.error(f"获取额度信息失败,API Key:{api_key},错误信息:{e}")
|
74 |
return None
|
75 |
except Exception as e:
|
76 |
+
logging.error(f"处理额度信息失败,API Key:{api_key},错误信息:{e}")
|
77 |
+
return None
|
78 |
|
79 |
def get_usd_to_cny_rate():
|
80 |
try:
|
|
|
100 |
logging.info(f"加载的 keys:{unique_keys}")
|
101 |
|
102 |
with concurrent.futures.ThreadPoolExecutor(
|
103 |
+
max_workers=10000
|
104 |
) as executor:
|
105 |
future_to_key = {
|
106 |
executor.submit(
|
|
|
191 |
tpm = sum(token_counts)
|
192 |
|
193 |
return jsonify({"rpm": rpm, "tpm": tpm})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
@app.route('/handsome/v1/models', methods=['GET'])
|
196 |
def list_models():
|
|
|
203 |
"object": "model",
|
204 |
"created": 1678888888,
|
205 |
"owned_by": "openai",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
"root": "deepseek-chat",
|
207 |
"parent": None
|
208 |
},
|
|
|
211 |
"object": "model",
|
212 |
"created": 1678888889,
|
213 |
"owned_by": "openai",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
"root": "deepseek-reasoner",
|
215 |
"parent": None
|
216 |
}
|