mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-05 07:26:39 +08:00
fix: 在智能路由中间件中添加对请求体的JSON解析异常处理,确保在提取模型时的稳定性
This commit is contained in:
@@ -3,6 +3,7 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
|||||||
from app.config.config import settings
|
from app.config.config import settings
|
||||||
from app.log.logger import get_main_logger
|
from app.log.logger import get_main_logger
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
|
|
||||||
logger = get_main_logger()
|
logger = get_main_logger()
|
||||||
|
|
||||||
@@ -240,11 +241,10 @@ class SmartRoutingMiddleware(BaseHTTPMiddleware):
|
|||||||
# 1. 从请求体中提取
|
# 1. 从请求体中提取
|
||||||
try:
|
try:
|
||||||
if hasattr(request, '_body') and request._body:
|
if hasattr(request, '_body') and request._body:
|
||||||
import json
|
|
||||||
body = json.loads(request._body.decode())
|
body = json.loads(request._body.decode())
|
||||||
if 'model' in body and body['model']:
|
if 'model' in body and body['model']:
|
||||||
return body['model']
|
return body['model']
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 2. 从查询参数中提取
|
# 2. 从查询参数中提取
|
||||||
|
|||||||
Reference in New Issue
Block a user