{"record":{"id":"8a22eb2ae1194155","repo":"binary-husky/gpt_academic","slug":"error-8a22eb","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"request_llms/bridge_moss.py","lineNumber":187,"sourceCode":"        self.threadLock.release()\n\nglobal moss_handle\nmoss_handle = None\n#################################################################################\ndef predict_no_ui_long_connection(inputs:str, llm_kwargs:dict, history:list=[], sys_prompt:str=\"\",\n                                  observe_window:list=[], console_silence:bool=False):\n    \"\"\"\n        多线程方法\n        函数的说明请见 request_llms/bridge_all.py\n    \"\"\"\n    global moss_handle\n    if moss_handle is None:\n        moss_handle = GetGLMHandle()\n        if len(observe_window) >= 1: observe_window[0] = load_message + \"\\n\\n\" + moss_handle.info\n        if not moss_handle.success:\n            error = moss_handle.info\n            moss_handle = None\n            raise RuntimeError(error)\n\n    # chatglm 没有 sys_prompt 接口，因此把prompt加入 history\n    history_feedin = []\n    for i in range(len(history)//2):\n        history_feedin.append([history[2*i], history[2*i+1]] )\n\n    watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可\n    response = \"\"\n    for response in moss_handle.stream_chat(query=inputs, history=history_feedin, sys_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):\n        if len(observe_window) >= 1:  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\n\ndef predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_moss.py#L169-L205","documentation":"In moss_predict_no_ui_long_connection: on first use the loader thread runs; if it failed, moss_handle.success is False and moss_handle.info holds the loader's status message (typically '[Local Message] Call MOSS fail 不能正常加载MOSS的参数。'). The code nulls the global handle and re-raises that info as RuntimeError(error).","triggerScenarios":"First call to the MOSS streaming predict while the MOSS model failed to load in the background thread (weights/deps/VRAM), so handle.success is False at the check.","commonSituations":"Same as the MOSS loader failure: missing weights, incompatible transformers, CUDA OOM; the surfaced message is whatever info the thread had written when polled.","solutions":["Read observe_window[0] (load_message + handle.info) — it carries the actual loader message shown before the raise.","Run moss_init directly to capture the true traceback and fix env/weights/VRAM.","Free GPU memory or use quantization; verify LOCAL_MODEL_DEVICE.","Restart the app after fixing — the failed handle was reset to None and will retry on next call."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = moss_predict_no_ui_long_connection(...)\nexcept RuntimeError as e:\n    chatbot.append(('system', f'MOSS unavailable: {e}'))  # e is handle.info","preventionTips":["Read observe_window[0] for the loader message","Validate MOSS at startup, not first request","Reset handle to None on failure so next call retries"],"tags":["moss","local-model","model-loading","error-propagation"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}