Update app.py
Browse files
app.py
CHANGED
@@ -506,56 +506,6 @@ def handsome_chat_completions():
|
|
506 |
except requests.exceptions.RequestException as e:
|
507 |
logging.error(f"请求转发异常: {e}")
|
508 |
return jsonify({"error": str(e)}), 500
|
509 |
-
|
510 |
-
def get_credit_summary(api_key):
|
511 |
-
headers = {
|
512 |
-
"Authorization": f"Bearer {api_key}",
|
513 |
-
"Content-Type": "application/json"
|
514 |
-
}
|
515 |
-
try:
|
516 |
-
response = session.get(
|
517 |
-
API_ENDPOINT,
|
518 |
-
headers=headers
|
519 |
-
)
|
520 |
-
response.raise_for_status()
|
521 |
-
return response.json().get("credit_summary")
|
522 |
-
except requests.exceptions.RequestException as e:
|
523 |
-
logging.error(
|
524 |
-
f"获取账户余额失败,"
|
525 |
-
f"API Key:{api_key},错误信息:{e}"
|
526 |
-
)
|
527 |
-
return None
|
528 |
-
except (KeyError, TypeError) as e:
|
529 |
-
logging.error(
|
530 |
-
f"解析账户余额失败,"
|
531 |
-
f"API Key:{api_key},错误信息:{e}"
|
532 |
-
)
|
533 |
-
return None
|
534 |
-
|
535 |
-
def test_model_availability(api_key, test_model):
|
536 |
-
headers = {
|
537 |
-
"Authorization": f"Bearer {api_key}",
|
538 |
-
"Content-Type": "application/json"
|
539 |
-
}
|
540 |
-
data = {
|
541 |
-
"model": test_model,
|
542 |
-
"messages": [{"role": "user", "content": "hello"}]
|
543 |
-
}
|
544 |
-
try:
|
545 |
-
response = session.post(
|
546 |
-
TEST_MODEL_ENDPOINT,
|
547 |
-
headers=headers,
|
548 |
-
json=data
|
549 |
-
)
|
550 |
-
response.raise_for_status()
|
551 |
-
return True
|
552 |
-
except requests.exceptions.RequestException as e:
|
553 |
-
logging.error(
|
554 |
-
f"模型测试失败,"
|
555 |
-
f"API Key:{api_key},错误信息:{e}"
|
556 |
-
)
|
557 |
-
return False
|
558 |
-
|
559 |
|
560 |
if __name__ == '__main__':
|
561 |
logging.info(f"环境变量:{os.environ}")
|
|
|
506 |
except requests.exceptions.RequestException as e:
|
507 |
logging.error(f"请求转发异常: {e}")
|
508 |
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
|
510 |
if __name__ == '__main__':
|
511 |
logging.info(f"环境变量:{os.environ}")
|