mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-12 02:19:59 +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.log.logger import get_main_logger
|
||||
import re
|
||||
import json
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
@@ -240,11 +241,10 @@ class SmartRoutingMiddleware(BaseHTTPMiddleware):
|
||||
# 1. 从请求体中提取
|
||||
try:
|
||||
if hasattr(request, '_body') and request._body:
|
||||
import json
|
||||
body = json.loads(request._body.decode())
|
||||
if 'model' in body and body['model']:
|
||||
return body['model']
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. 从查询参数中提取
|
||||
|
||||
Reference in New Issue
Block a user