diff --git a/qw_shim.py b/qw_shim.py index 6d1efdc..ee6cc54 100644 --- a/qw_shim.py +++ b/qw_shim.py @@ -42,19 +42,19 @@ UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " # iishko model name -> qwenwork chat mode MODES = { - "qw-flash": "flash", - "qw-standard": "flash", - "qw-pro": "advanced", - "qw-advanced": "advanced", - "qw-flagship": "pro", - "qw-qwen4-max": "qwen4-max", - "qw-qwen3.8-max": "qwen3.8-max", - "qw-qwen3.8-flash": "qwen3.8-flash", - "qw-deepseek-v4.1-flash": "deepseek-flash", - "qw-glm-5.3": "glm-5.3", - "qw-glm-5.3-flash": "glm-5.3-flash", - "qw-kimi-k3.1-pro": "kimi-k3.1-pro", - "qw-minimax-m3.1-flash": "minimax-m3.1-flash", + "flash": "flash", + "standard": "flash", + "pro": "advanced", + "advanced": "advanced", + "flagship": "pro", + "qwen4-max": "qwen4-max", + "qwen3.8-max": "qwen3.8-max", + "qwen3.8-flash": "qwen3.8-flash", + "deepseek-v4.1-flash": "deepseek-flash", + "glm-5.3": "glm-5.3", + "glm-5.3-flash": "glm-5.3-flash", + "kimi-k3.1-pro": "kimi-k3.1-pro", + "minimax-m3.1-flash": "minimax-m3.1-flash", } _lock = threading.Lock() @@ -315,6 +315,12 @@ class H(BaseHTTPRequestHandler): return self._json(code, {"error": {"message": (last_err.msg if last_err else "upstream failed"), "type": "upstream_error"}}) ans = ans or "" + if not ans.strip(): + # [EMPTY502 1121] upstream created the session but never emitted agent_message_chunk; + # returning an empty 200 poisons the gateway (user sees nothing, credits burned). + return self._json(502, {"error": {"message": "empty answer from qwenwork (no agent_message_chunk)", + "type": "upstream_error"}, + "x_qwenwork_session": sid}) tid = "chatcmpl-" + uuid.uuid4().hex[:24] created = int(time.time())