binary-husky/gpt_academic · error · RuntimeError
Json解析不合常规
Error message
Json解析不合常规
What it means
Catch-all inside the try block that processes each SSE chunk in predict_no_ui_long_connection: any exception while accumulating result/handling finish (key errors from unexpected chunk shapes, decode issues, the watchdog raise being caught too) triggers get_full_error, logger.error of the raw chunk, and RuntimeError('Json解析不合常规'). Like 188/189, the real detail is in the log; the message just says the JSON shape was unexpected.
Source
Thrown at request_llms/oai_std_model_template.py:263
print(f"[response] {result}")
break
result += response_text
if reasoning:
reasoning_buffer += reasoning_content
if observe_window is not None:
# 观测窗,把已经获取的数据显示出去
if len(observe_window) >= 1:
observe_window[0] += response_text
# 看门狗,如果超过期限没有喂狗,则终止
if len(observe_window) >= 2:
if (time.time() - observe_window[1]) > watch_dog_patience:
raise RuntimeError("用户取消了程序。")
except Exception as e:
chunk = get_full_error(chunk, stream_response)
chunk_decoded = chunk.decode()
error_msg = chunk_decoded
logger.error(error_msg)
raise RuntimeError("Json解析不合常规")
if reasoning:
paragraphs = ''.join([f'<p style="margin: 1.25em 0;">{line}</p>' for line in reasoning_buffer.split('\n')])
return f'''<div class="reasoning_process" >{paragraphs}</div>\n\n''' + result
return result
def predict(
inputs,
llm_kwargs,
plugin_kwargs,
chatbot,
history=[],
system_prompt="",
stream=True,
additional_fn=None,
):
"""
发送至chatGPT,流式获取输出。
用于基础的对话功能。View on GitHub (pinned to d6bde0fa54)
Solutions
- Inspect logger.error output — the offending raw chunk is logged verbatim.
- Point API_URL_ORIGINAL at a strictly OpenAI-compatible endpoint or fix the relay's response format.
- Update decode_chunk to tolerate the provider's actual schema (e.g. missing reasoning_content).
- Retry after provider-side errors resolve (502s are often transient).
Defensive patterns
Strategy: try-catch
Try / catch
try:
result = predict_no_ui_long_connection(...)
except RuntimeError as e:
if 'Json解析不合常规' in str(e):
chunk = get_last_logged_chunk() # logger.error has the raw payload
if is_provider_5xx(chunk):
backoff_and_retry()
else:
fix_or_report_schema(chunk) Prevention
- Always run with logging enabled; the raw chunk is the only diagnostic.
- Prefer strictly OpenAI-compatible endpoints/relays.
- Re-test custom providers after their API version bumps.
When it happens
Trigger: A chunk whose structure violates decode_chunk/accumulation assumptions: provider returns an error object where content deltas are expected, missing 'choices' field, non-JSON relay responses (HTML error pages), or schema changes in a custom OpenAI-compatible backend.
Common situations: Third-party relays with slightly non-standard SSE payloads; gateways returning HTML 502 pages mid-stream; provider API version changes; this catch also swallows the user-cancel watchdog raise from error 189 when cancellation coincides with chunk processing.
Related errors
- 意外Json结构:
- 无法读取以下数据,请检查配置。 {chunk_decoded}
- API异常,请检测终端输出。可能的原因是:{finish_reason}
- OpenAI拒绝了请求:
- OpenAI拒绝了请求:
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/3eeccaf5e6047bfd.
Report an issue: GitHub.