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)