Spaces:
Sleeping
Sleeping
update
Browse files
proxy.py
CHANGED
|
@@ -8,6 +8,7 @@ import os
|
|
| 8 |
from datetime import timezone, timedelta, datetime
|
| 9 |
from fastapi import FastAPI, Request, HTTPException, Depends, status
|
| 10 |
import logging # 导入logging模块
|
|
|
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
|
|
@@ -20,10 +21,21 @@ async def do_proxy(url: str, method: str, headers: dict, content: str, max_retri
|
|
| 20 |
try:
|
| 21 |
async with httpx.AsyncClient() as client:
|
| 22 |
for attempt in range(max_retries):
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# 获取API密钥信息
|
| 26 |
-
api_key_info = await get_api_key_info(
|
| 27 |
api_key = api_key_info.get('api_key')
|
| 28 |
api_key_id = api_key_info.get('api_key_id')
|
| 29 |
api_key_show = api_key[:5]+'*****'+api_key[-5:]
|
|
|
|
| 8 |
from datetime import timezone, timedelta, datetime
|
| 9 |
from fastapi import FastAPI, Request, HTTPException, Depends, status
|
| 10 |
import logging # 导入logging模块
|
| 11 |
+
import json # 导入json模块
|
| 12 |
|
| 13 |
load_dotenv()
|
| 14 |
|
|
|
|
| 21 |
try:
|
| 22 |
async with httpx.AsyncClient() as client:
|
| 23 |
for attempt in range(max_retries):
|
| 24 |
+
logger.info(f"接收到的内容: {content}")
|
| 25 |
+
try:
|
| 26 |
+
content_json = json.loads(content)
|
| 27 |
+
model_name = content_json.get('model')
|
| 28 |
+
if model_name:
|
| 29 |
+
logger.info(f"从内容中提取的模型名称: {model_name}")
|
| 30 |
+
else:
|
| 31 |
+
logger.warning("内容中未找到 'model' 键。")
|
| 32 |
+
except json.JSONDecodeError:
|
| 33 |
+
logger.warning("内容不是有效的 JSON 格式,无法提取 'model' 键。")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
logger.error(f"提取模型名称时发生错误: {str(e)}")
|
| 36 |
|
| 37 |
# 获取API密钥信息
|
| 38 |
+
api_key_info = await get_api_key_info(model_name)
|
| 39 |
api_key = api_key_info.get('api_key')
|
| 40 |
api_key_id = api_key_info.get('api_key_id')
|
| 41 |
api_key_show = api_key[:5]+'*****'+api_key[-5:]
|