{"record":{"id":"674da743c1e3869f","repo":"binary-husky/gpt_academic","slug":"error-674da7","errorCode":null,"errorMessage":"用户取消了程序。","messagePattern":"用户取消了程序。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_cohere.py","lineNumber":122,"sourceCode":"    while True:\n        try: chunk = next(stream_response)\n        except StopIteration:\n            break\n        except requests.exceptions.ConnectionError:\n            chunk = next(stream_response) # 失败了，重试一次？再失败就没办法了。\n        chunk_decoded, chunkjson, has_choices, choice_valid, has_content, has_role = decode_chunk(chunk)\n        if chunkjson['event_type'] == 'stream-start': continue\n        if chunkjson['event_type'] == 'text-generation':\n            result += chunkjson[\"text\"]\n            if not console_silence: print(chunkjson[\"text\"], end='')\n            if observe_window is not None:\n                # 观测窗，把已经获取的数据显示出去\n                if len(observe_window) >= 1:\n                    observe_window[0] += chunkjson[\"text\"]\n                # 看门狗，如果超过期限没有喂狗，则终止\n                if len(observe_window) >= 2:\n                    if (time.time()-observe_window[1]) > watch_dog_patience:\n                        raise RuntimeError(\"用户取消了程序。\")\n        if chunkjson['event_type'] == 'stream-end': break\n    return result\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    发送至chatGPT，流式获取输出。\n    用于基础的对话功能。\n    inputs 是本次问询的输入\n    top_p, temperature是chatGPT的内部调优参数\n    history 是之前的对话列表（注意无论是inputs还是history，内容太长了都会触发token数量溢出的错误）\n    chatbot 为WebUI中显示的对话列表，修改它，然后yield出去，可以直接修改对话界面内容\n    additional_fn代表点击的哪个按钮，按钮见functional.py\n    \"\"\"\n    # if is_any_api_key(inputs):\n    #     chatbot._cookies['api_key'] = inputs\n    #     chatbot.append((\"输入已识别为Cohere的api_key\", what_keys(inputs)))","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_cohere.py#L104-L140","documentation":"RuntimeError ('用户取消了程序。') from the Cohere bridge's watchdog in predict_no_ui_long_connection. While consuming Cohere's SSE events (text-generation frames appended to result), the code checks observe_window[1] — a timestamp the UI thread refreshes — against watch_dog_patience (5 s). If new text arrives but the timestamp is stale, the loop aborts on the assumption the user cancelled or the UI died. Standard cooperative-cancellation mechanism replicated across all bridges.","triggerScenarios":"User stops generation in the Gradio UI during a Cohere response; UI polling thread stops updating observe_window[1] (suspended tab, stalled Gradio queue); custom integration passes observe_window without a feeding thread while text-generation events stream in.","commonSituations":"Intentional stops mid-answer; slow Cohere API or relay causing UI thread starvation; backgrounded browser tabs freezing the watchdog feed.","solutions":["If deliberate, re-send the query after stopping.","Keep the UI tab in the foreground during generation.","Custom callers: update observe_window[1] = time.time() at ~1 Hz for the duration of the stream.","Raise watch_dog_patience in request_llms/bridge_cohere.py for slow setups."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = predict_no_ui_long_connection(inputs, llm_kwargs, history, sys_prompt, observe_window=win)\nexcept RuntimeError as e:\n    if '用户取消了程序' in str(e):\n        handle_cancel_or_stale_watchdog()\n    else:\n        raise","preventionTips":["Feed observe_window[1] at ~1 Hz from a live thread during the whole Cohere stream.","Tear down the feeder when the request finishes.","Keep the UI tab responsive; suspended tabs stop feeding the watchdog.","Raise the patience constant for slow Cohere relays."],"tags":["watchdog","cancellation","cohere","streaming","ui"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}