{"record":{"id":"152a6d2cad8e5de6","repo":"binary-husky/gpt_academic","slug":"error-152a6d","errorCode":null,"errorMessage":"程序终止。","messagePattern":"程序终止。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_zhipu.py","lineNumber":43,"sourceCode":"    \"\"\"\n    watch_dog_patience = 5\n    response = \"\"\n\n    if llm_kwargs[\"llm_model\"] == \"zhipuai\":\n        llm_kwargs[\"llm_model\"] = zhipuai_default_model\n\n    if validate_key() is False:\n        raise RuntimeError('请配置ZHIPUAI_API_KEY')\n\n    # 开始接收回复\n    from .com_zhipuglm import ZhipuChatInit\n    zhipu_bro_init = ZhipuChatInit()\n    for chunk, response in zhipu_bro_init.generate_chat(inputs, llm_kwargs, history, sys_prompt):\n        if len(observe_window) >= 1:\n            observe_window[0] = response\n        if len(observe_window) >= 2:\n            if (time.time() - observe_window[1]) > watch_dog_patience:\n                raise RuntimeError(\"程序终止。\")\n    return response\n\n\ndef predict(inputs:str, llm_kwargs:dict, plugin_kwargs:dict, chatbot:ChatBotWithCookies,\n            history:list=[], system_prompt:str='', stream:bool=True, additional_fn:str=None):\n    \"\"\"\n        ⭐单线程方法\n        函数的说明请见 request_llms/bridge_all.py\n    \"\"\"\n    chatbot.append([inputs, \"\"])\n    yield from update_ui(chatbot=chatbot, history=history)\n\n    # 尝试导入依赖，如果缺少依赖，则给出安装建议\n    try:\n        check_packages([\"zhipuai\"])\n    except:\n        yield from update_ui_latest_msg(f\"导入软件依赖失败。使用该模型需要额外依赖，安装方法```pip install --upgrade zhipuai```。\",\n            chatbot=chatbot, history=history, delay=0)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_zhipu.py#L25-L61","documentation":"Watchdog of the Zhipu GLM streaming loop: during ZhipuChatInit.generate_chat iteration, if observe_window[1] is more than watch_dog_patience (5 s) in the past, the loop raises RuntimeError('程序终止。') and the worker thread stops.","triggerScenarios":"ZhipuChatInit.generate_chat stops yielding for >5 s inside request_llms/bridge_zhipu.py:43 predict_no_ui_long_connection() — e.g. open.bigmodel.cn stream stall, 429 throttle, TLS/proxy interruption mid-stream.","commonSituations":"Free-tier Zhipu quota exhausted mid-stream causing a hang instead of clean error; network flakiness; GLM-4 long generations whose inter-chunk gap occasionally exceeds 5 s.","solutions":["Retry the request; check Zhipu console for quota/usage errors","Test streaming endpoint directly with curl to see whether chunks pause >5 s","Raise watch_dog_patience if inter-chunk gaps are legitimately long","Stabilize network / disable interfering proxies for open.bigmodel.cn"],"exampleFix":"# before\nwatch_dog_patience = 5\n\n# after\nwatch_dog_patience = 30","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ...\nexcept RuntimeError as e:\n    if str(e) == '程序终止。':\n        logger.warning('zhipu stream stalled; retrying')\n        return retry(inputs)\n    raise","preventionTips":["Watch Zhipu console quotas; exhausted quota can hang streams","Raise watchdog patience for GLM-4 long generations","Retry once; consecutive watchdog trips indicate a real outage"],"tags":["timeout","watchdog","zhipu","network"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}