fix: content=None 导致 TypeError + /v1/models 本地返回

This commit is contained in:
chaos committed 2026-07-08 16:27:35 +08:00
1 parent 29d6fac6cc
commit 2b073f2e3f
1 file changed
+10 -1
+10 -1
View File
@@ -306,7 +306,7 @@ def auto_compact(raw_body, real_token, orig_request):
MAX_MSG_CHARS = 500 MAX_MSG_CHARS = 500
truncated_msgs = [] truncated_msgs = []
for m in convo_msgs: for m in convo_msgs:
content = m.get('content', '') content = m.get('content', '') or ''
if len(content) > MAX_MSG_CHARS: if len(content) > MAX_MSG_CHARS:
truncated_msgs.append({**m, 'content': content[:MAX_MSG_CHARS] + '...[截断]'}) truncated_msgs.append({**m, 'content': content[:MAX_MSG_CHARS] + '...[截断]'})
else: else:
@@ -816,6 +816,15 @@ def proxy(subpath):
target_url = f'https://{TARGET_HOST}/v2/{subpath}' target_url = f'https://{TARGET_HOST}/v2/{subpath}'
# ============ /models 请求直接返回,不转发上游 ============
if subpath in ('models', 'models/'):
return {
"object": "list",
"data": [
{"id": "glm-5.1", "object": "model", "owned": "zhipu"},
]
}
# ============ 请求体处理:大小校验 + 动态超时 ============ # ============ 请求体处理:大小校验 + 动态超时 ============
raw_body = request.get_data() raw_body = request.get_data()
body_size = len(raw_body) body_size = len(raw_body)