From 2b073f2e3f27a48ef69e69908c35514655f899a1 Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 8 Jul 2026 16:27:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20content=3DNone=20=E5=AF=BC=E8=87=B4=20Ty?= =?UTF-8?q?peError=20+=20/v1/models=20=E6=9C=AC=E5=9C=B0=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/huawei_gateway.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ai/huawei_gateway.py b/ai/huawei_gateway.py index f226313..b343e8f 100755 --- a/ai/huawei_gateway.py +++ b/ai/huawei_gateway.py @@ -306,7 +306,7 @@ def auto_compact(raw_body, real_token, orig_request): MAX_MSG_CHARS = 500 truncated_msgs = [] for m in convo_msgs: - content = m.get('content', '') + content = m.get('content', '') or '' if len(content) > MAX_MSG_CHARS: truncated_msgs.append({**m, 'content': content[:MAX_MSG_CHARS] + '...[截断]'}) else: @@ -816,6 +816,15 @@ def proxy(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() body_size = len(raw_body)