Skip to content

🧠 两小时从 0 训出你的 64M 大模型。Train your own 64M LLM from scratch in 2 hours.

fix: guard against empty/filtered LLM responses in chat_api.py

Jonathan Hill182bff1bd86d
diff --git a/scripts/chat_api.py b/scripts/chat_api.py
index 3828453..58b0d0b 100644
--- a/scripts/chat_api.py
+++ b/scripts/chat_api.py
@@ -21,6 +21,8 @@ while True:
extra_body={"chat_template_kwargs": {"open_thinking": True}, "reasoning_effort": "medium"} # 思考开关
)
if not stream:
+ if not response.choices or response.choices[0].message is None:
+ raise ValueError("LLM returned empty or filtered response")
assistant_res = response.choices[0].message.content
print('[A]: ', assistant_res)
else: