This commit is contained in:
hailin 2025-08-01 14:34:13 +08:00
parent db9e41c3e0
commit 45c24387d9
1 changed files with 3 additions and 14 deletions

View File

@ -148,20 +148,9 @@ def chat(
except Empty:
continue
# 你之前在 worker() 中把完整字符串放进 result_q所以这里只是字符串
if isinstance(result, str):
# 假设是 JSON 字符串(但你原来实际放的是 content 文本)
try:
parsed = json.loads(result)
txt = parsed["choices"][0]["message"]["content"].strip()
except Exception:
txt = result.strip()
elif isinstance(result, dict):
txt = result.get("text", "").strip()
else:
txt = str(result).strip()
# ✅ 推荐返回结构,自动渲染 + 自动 history 追加
# 你用 backend 返回的其实已经是 content 字符串了,不要再转 json
txt = result.strip() if isinstance(result, str) else str(result).strip()
# 注意,这里必须 yield {"text": txt}, log_state
yield {"text": txt}, log_state
return
else: