{"record":{"id":"ba1bd9f9b9494435","repo":"binary-husky/gpt_academic","slug":"error-ba1bd9","errorCode":null,"errorMessage":"程序终止。","messagePattern":"程序终止。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_taichu.py","lineNumber":38,"sourceCode":"    \"\"\"\n    watch_dog_patience = 5\n    response = \"\"\n\n    # if llm_kwargs[\"llm_model\"] == \"taichu\":\n    #     llm_kwargs[\"llm_model\"] = \"taichu\"\n\n    if validate_key() is False:\n        raise RuntimeError('请配置 TAICHU_API_KEY')\n\n    # 开始接收回复\n    from .com_taichu import TaichuChatInit\n    zhipu_bro_init = TaichuChatInit()\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    if validate_key() is False:\n        yield from update_ui_latest_msg(lastmsg=\"[Local Message] 请配置ZHIPUAI_API_KEY\", chatbot=chatbot, history=history, delay=0)\n        return\n\n    if additional_fn is not None:\n        from core_functional import handle_core_functionality","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_taichu.py#L20-L56","documentation":"Watchdog inside the Taichu bridge's long-connection generator: if the time stored in observe_window[1] lags more than watch_dog_patience (5 s) behind wall-clock while TaichuChatInit.generate_chat streams chunks, the loop aborts with RuntimeError('程序终止。').","triggerScenarios":"TaichuChatInit.generate_chat stalls between yields for >5 s (HTTP stream hang, server-side throttling, network drop) while running predict_no_ui_long_connection from request_llms/bridge_taichu.py:38.","commonSituations":"Slow Taichu endpoint under load; proxy stripping streaming responses; large history making first-token latency exceed 5 s; caller thread not refreshing observe_window[1].","solutions":["Retry — transient Taichu service latency is the usual cause","Test the Taichu API directly (curl) with the same key to measure time-to-first-token","Increase watch_dog_patience if first-token latency is legitimately >5 s","Shorten history payload so the service responds faster"],"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        return retry_once(predict_no_ui_long_connection, inputs, llm_kwargs, history, sys_prompt, observe_window)\n    raise","preventionTips":["Measure Taichu time-to-first-token; adjust watchdog patience above it","Keep request history short to reduce server latency","Retry once on watchdog trips in batch plugins; abort on repeat failure"],"tags":["timeout","watchdog","taichu","network"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}